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.

[ U ] 18.3 Macros 207For the right single quote, we use the standard single quote, or apostrophe. On U.S. keyboards,the single quote is located on the same key as the double quote, on the right side of the keyboardnext to the Enter key.18.3.2 Global macrosLet’s put aside why Stata has two kinds of macros—local and global—and focus right now onhow global macros work.Global macros can have names that are up to 32 (not 31) characters long. You set the contents ofa global macro by using the global rather than the local command:. global shortcut "alpha beta"You obtain the contents of a global macro by prefixing its name with a dollar sign: $shortcut isequivalent to “alpha beta”.In the previous section, we defined a local macro named shortcut, which is a different macro.‘shortcut’ is still “myvar thisvar thatvar”.Local and global macros may have the same names, but even if they do, they are unrelated andare still distinguishable.Global macros are just like local macros except that you set their contents with global ratherthan local, and you substitute their contents by prefixing them with a $ rather than enclosing themin ‘’.18.3.3 The difference between local and global macrosThe difference between local and global macros is that local macros are private and global macrosare public.Say that you have written a programprogram myprogcode using local macro alphaendThe local macro alpha in myprog is private in that no other program can modify or even look atalpha’s contents. To make this point absolutely clear, assume that your program looks like this:program myprogcode using local macro alphamysubmore code using local macro alphaendprogram mysubcode using local macro alphaendmyprog calls mysub, and both programs use a local macro named alpha. Even so, the local macrosin each program are different. mysub’s alpha macro may contain one thing, but that has nothing todo with what myprog’s alpha macro contains. Even when mysub begins execution, its alpha macrois different from myprog’s. It is not that mysub’s inherits myprog’s alpha macro contents but is thenfree to change it. It is that myprog’s alpha and mysub’s alpha are entirely different things.When you write a program using local macros, you need not worry that some other programhas been written using local macros with the same names. Local macros are just that: local to yourprogram.

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

Saved successfully!

Ooh no, something went wrong!