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.

240 [ U ] 18 Programming Stata18.11.3 Debugging ado-filesDebugging ado-files is a little tricky because it is Stata and not you that controls when the ado-fileis loaded.Assume that you wanted to change hello to say “Hi, Mary”. Assume that your editor is calledvi and that you are in the habit of calling your editor from Stata, so you do this,. !vi hello.adoand make the obvious change to the program. Equivalently, you can pretend that you are using awindowed operating system and jump out of Stata—leaving it running—to modify the hello.adofile. Anyway, you change hello.ado to readprogram helloversion 11display "hi, Mary"endbegin hello.adoend hello.adoBack in Stata, you try it:. hellohi thereStata ran the old copy of hello—the copy it still has in its memory. Stata wants to be fast aboutexecuting ado-files, so when it loads one, it keeps it around a while—waiting for memory to getshort—before clearing it from its memory. Naturally, Stata can drop hello anytime because it canalways reload it from disk.You changed the copy on disk, but Stata still has the old copy loaded into memory. You typediscard to tell Stata to forget these automatically loaded things and to force itself to get new copiesof the ado-files from disk:. discard. hellohi, MaryYou had to type discard only because you changed the ado-file while Stata was running. Had youexited Stata and returned later to use hello, the discard would not have been necessary becauseStata forgets things between sessions anyway.18.11.4 Local subroutinesAn ado-file can contain more than one program, and if it does, the other programs defined in theado-file are assumed to be subroutines of the main program. For example,program decoy. . .duck . . .. . .endprogramendduck. . .begin decoy.adoend decoy.ado

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

Saved successfully!

Ooh no, something went wrong!