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.

232 [ U ] 18 Programming Stata3. Estimation commands save the command they executed in e(cmdline). For instance, if youtyped reg mpg displ, saved in e(cmdline) would be “reg mpg displ”.4. Estimation commands save the number of observations used in e(N), and they identify theestimation subsample by setting e(sample). You could type, for instance, summarize ife(sample) to obtain summary statistics on the observations used by the estimator.5. Estimation commands save the entire coefficient vector and variance–covariance matrix of theestimators in e(b) and e(V). These are matrices, and they may be manipulated like any othermatrix:. matrix list e(b)e(b)[1,3]weight displ _consy1 -.00656711 .00528078 40.084522. matrix y = e(b)*e(V)*e(b)’. matrix list ysymmetric y[1,1]y1y1 6556.9826. Estimation commands set b[name] and se[name] as convenient ways to use coefficientsand their standard errors in expressions; see [U] 13.5 Accessing coefficients and standarderrors.7. Estimation commands may set other e() scalars, macros, or matrices containing more information.This is documented in the Saved results section of the particular command in the commandreference.Example 2If you are writing a command for use after regress, early in your code you should include thefollowing:if "‘e(cmd)’" != "regress" {error 301}This is how you verify that the estimation results that are stored have been set by regress and notby some other estimation command. Error 301 is Stata’s “last estimates not found” error.18.10 Saving resultsIf your program calculates something, it should save the results of the calculation so that otherprograms can access them. In this way your program not only can be used interactively but also canbe used as a subroutine for other commands.Saving results is easy:1. On the program line, specify the rclass, eclass, or sclass option according to whetheryou intend to return results in r(), e(), or s().2. Codereturn scalar name = expreturn local name . . .return matrix name matnameto save results in r().(same syntax as scalar without the return)(same syntax as local without the return)(moves matname to r(name))

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

Saved successfully!

Ooh no, something went wrong!