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.

214 [ U ] 18 Programming StataThus one might codeformat y ‘:format x’to assign to variable y the same format as the variable x.Technical noteThere is another macro expansion operator, . (called dot), which is used in conjunction withStata’s class system; see [P] class for more information.There is also a macro expansion function, macval(), which is for use when expanding a macro—‘macval(name)’—which confines the macro expansion to the first level of name, thereby suppressingthe expansion of any embedded references to macros within name. Only two or three Stata users haveor will ever need this, but, if you suspect you are one of them, see [P] macro and then see [P] filefor an example.18.3.9 Advanced local macro manipulationThis section is really an aside to help test your understanding of macro substitution. The trickyexamples illustrated below sometimes occur in real programs.1. Say that you have macros x1, x2, x3, and so on. Obviously, ‘x1’ refers to the contents of x1,‘x2’ to the contents of x2, etc. What does ‘x‘i’’ refer to? Suppose that ‘i’ contains 6.The rule is to expand the inside first:So, there you have a vector of macros.‘x‘i’’ expands to ‘x6’‘x6’ expands to the contents of local macro x62. We have already shown adjoining expansions: ‘alpha’‘beta’ expands to myvar if ‘alpha’contains my and ‘beta’ contains var. What does ‘alpha’‘gamma’‘beta’ expand to whengamma is undefined?Stata does not mind if you refer to a nonexistent macro. A nonexistent macro is treated as a macrowith no contents. If local macro gamma does not exist, then‘gamma’ expands to nothingIt is not an error. Thus ‘alpha’‘gamma’‘beta’ expands to myvar.3. You clear a local macro by setting its contents to nothing:local macnameor local macname ""or local macname = ""

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

Saved successfully!

Ooh no, something went wrong!