11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ U ] 18.3 Macros 205That problem is solved by typing program drop hello before redefining it. We could do thatinteractively, or we could modify our do-file:program drop helloprogram hellodisplay "hi there"endhellobegin hello.doend hello.doThere is a problem with this solution. We can now rerun our do-file, but the first time we tried torun it in a Stata session, it would fail:. do hello. program drop hellohello not foundr(111);end of do-filer(111);The way around this conundrum is to modify the do-file:capture program drop helloprogram hellodisplay "hi there"endhellobegin hello.doend hello.docapture in front of a command makes Stata indifferent to whether the command works; see[P] capture. In real do-files containing programs, you will often see capture program drop beforethe program’s definition.To learn about the program command itself, see [P] program. It manipulates programs. programcan define programs, drop programs, and show you a directory of programs that you have defined.A program can contain any Stata command, but certain Stata commands are of special interest toprogram writers; see the Programming heading in the subject table of contents in the Quick Referenceand Index.18.3 MacrosBefore we can begin programming, we must discuss macros, which are the variables of Stataprograms.A macro is a string of characters, called the macroname, that stands for another string of characters,called the macro contents.Macros can be local or global. We will start with local macros because they are the most commonlyused, but nothing really distinguishes one from the other at this stage.

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

Saved successfully!

Ooh no, something went wrong!