# Access to Stata Results

Results from the most Stata procedures can be retraced from the computer's memory. Typically, this holds true for the *most recently executed* procedure.

## Classes of elements

Most Stata procedures store some, many or perhaps all elements that were used during computation in memory from which they can be retrieved; they remain available until the next procedure produces new elements to be stored. There is considerable variation as to what is stored: command `tab1`

stores only the number of cases and the number of rows, other procedures store a wealth of information. Stata distinguishes several classes of elements, of which `r()`

, `e()`

and `c()`

are most important.

### Results: r() and e()

Class `r()`

results can be expected from descriptive procedures, whereas estimation procedures (statistical models, but also command such as `mean`

) yield `e()`

results. You can access all current `r()`

elements via `return list`

and the `e()`

elements via `ereturn list`

. A single element of the list can be addressed just by its name. Thus, `display e(N)`

will yield the number of cases in the last estimation, or you may use `e(N)`

as an expression in a computation (where it will be replaced by the number stored in `e(N)`

).

The `r()`

and `e()`

elements may be single numbers (called "scalars" in matrix language), matrices, or strings. You will note that those elements that are found under the rubric "matrices" are not displayed when you type `return list`

or `ereturn list`

; what is displayed is the format of the matrices, e.g., 7 x 7 for the variance-covariance matrix of estimates in a regression model with six predictors (the seventh item is the constant of the model). Matrices are displayed with the help of the `matrix list`

command. For instance, from `ereturn list`

(or from the help function) you may have learned that the variance-covariance matrix is stored in matrix e(V). So, just type

matrix list e(V)

to obtain the entire matrix.

### Class c()

Class `c()`

elements do not change with each procedure; they refer to things like `c(current_date)`

, which is self-explaining, or `c(os)`

, the operating system. Typing `creturn list`

gives an overview of all `c()`

elements and their current settings. Class `c()`

elements are helpful particularly for programmers; average users may never have to use them.

## Coefficients

Coefficients from regression models and their standard errors can be accessed by `_b[varname]`

and `_se[varname]`

, respectively, with `varname`

referring to the variables that were used in the most recent regression model. Thus, if you have just estimated a regression model with education (variable `educ`

) as an independent variable, `_b[_cons]`

and `_b[educ]`

are stored in memory, as you can see easily by typing, e.g., `display _b[_cons]`

. You may also use these expressions in the generation of variables, as in the following example that computes the predicted values as follows (normally you will do this via the post-estimation command `predict`

, of course):

gen predy = _b[_cons] + _b[_educ]*educ

Note that this works only for single equation models and for simple variables. If you have used factor variables, interactions and the like, or if there are several dependent variables, the names of the coefficients will be more complex. In this case you may re-run your last estimation with option `coeflegend`

, as in this example of a linear regression model:

regress, coeflegend

This will yield a list of coefficients plus the names you can use to address them.

## Command statsby

Imagine that you run a regression model for several countries and wish to collect the regression coefficients from the different countries for further use (in a graph, for instance). To achieve this, use the `statsby`

command, which works like this:

statsby cons = _b[_cons] coeffeduc =_b[educ], by(country) clear: regress income educ

If you do it this way, Stata will replace the dataset you have used by the elements collected by `statsby`

. If you wish to keep your data in memory, you can store the elements in a file as follows:

statsby cons = _b[_cons] coeffeduc =_b[educ], by(country) saving(icoeffs, replace): regress income educ

This way, the coefficients will be stored in file `icoeffs`

.

© W. Ludwig-Mayerhofer, Stata Guide | Last update: 26 May 2017