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.

230 [ U ] 18 Programming StataAlthough it is true that e() results remain in place until the next e-class command is executed, donot depend on r() remaining unchanged. If an e-class or n-class command were to use an r-classcommand as a subroutine, that would cause r() to change. Anyway, most commands are r-class, sothe contents of r() change often.Technical noteIt is, therefore, of great importance that you access results stored in r() immediately after thecommand that sets them. If you need the mean and variance of the variable ‘1’ for subsequentcalculation, do not codeInstead, codeorsummarize ‘1’. . .. . . r(mean) . . . r(Var) . . .summarize ‘1’local mean = r(mean)local var = r(Var). . .. . . ‘mean’ . . . ‘var’ . . .tempname mean varsummarize ‘1’scalar ‘mean’ = r(mean)scalar ‘var’ = r(Var). . .. . . ‘mean’ . . . ‘var’ . . .Saved results, whether in r() or e(), come in three types: scalars, macros, and matrices. If youlook back at the ereturn list and return list output, you will see that regress saves examplesof all three, whereas summarize saves just scalars. (regress also saves the “function” e(sample),as do all the other e-class commands; see [U] 20.6 Specifying the estimation subsample.)Regardless of the type of e(name) or r(name), you can just refer to e(name) or r(name).That was the rule we gave in [U] 13.6 Accessing results from Stata commands, and that ruleis sufficient for most uses. There is, however, another way to refer to saved results. Rather thanreferring to r(name) and e(name), you can embed the reference in macro-substitution characters‘’ to produce ‘r(name)’ and ‘e(name)’. The result is the same as macro substitution; the savedresult is evaluated, and then the evaluation is substituted:. display "You can refer to " e(cmd) " or to ‘e(cmd)’"You can refer to regress or to regressThis means, for instance, that typing ‘e(cmd)’ is the same as typing regress because e(cmd)contains “regress”:. ‘e(cmd)’Source SS df MS Number of obs = 74F( 2, 71) = 66.79Model 1595.40969 2 797.704846 Prob > F = 0.0000(remaining output omitted )In the ereturn list, e(cmd) was listed as a macro, and when you place a macro’s name in singlequotes, the macro’s contents are substituted, so this is hardly a surprise.

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

Saved successfully!

Ooh no, something went wrong!