11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8 Error messages and return codesContents8.1 Making mistakes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718.1.1 Mistakes are forgiven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718.1.2 Mistakes stop user-written programs and do-files . . . . . . . . . . . . . . . . . . . . . . 718.1.3 Advanced programming to tolerate errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728.2 The return message for obtaining command timings . . . . . . . . . . . . . . . . . . . . . . . . . . . 728.1 Making mistakesWhen an error occurs, Stata produces an error message and a return code. For instance,. list myvarno variables definedr(111);We ask Stata to list the variable named myvar. Because we have no data in memory, Stata respondswith the message “no variables defined” and a line that reads “r(111)”.The “no variables defined” is called the error message.The 111 is called the return code. You can click on blue return codes to get a detailed explanationof the error.8.1.1 Mistakes are forgivenAfter “no variables defined” and r(111), all is forgiven; it is as if the error never occurred.Typically, the message will be enough to guide you to a solution, but if it is not, the numericreturn codes are documented in [P] error.8.1.2 Mistakes stop user-written programs and do-filesWhenever an error occurs in a user-written program or do-file, the program or do-file immediatelystops execution and the error message and return code are displayed.For instance, consider the following do-file:use http://www.stata-press.com/data/r11/autodecribelistbegin myfile.doend myfile.doNote the second line—you meant to type describe but typed decribe. Here is what happens whenyou execute this do-file by typing do myfile:. do myfile. use http://www.stata-press.com/data/r11/auto(1978 Automobile Data)71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!