help regsave
-------------------------------------------------------------------------------
Title

regsave -- Save regression results to a Stata-formatted dataset.

Syntax

Replace data in memory with current regression results

regsave [namelist] [, tstat pval ci level(#) nose cmdline autoid covar(namelist) detail(type) coefmat(matname) varmat(matname) double addlabel(newvarname1, label1, newvarname2, label2, ...) addvar(name1, coef1, stderr1, name2, coef2, stderr2, ...) table(table_suboptions)]

Save current regression results to a Stata-formatted dataset

regsave [namelist] using filename [, tstat pval ci level(#) nose cmdline autoid covar(namelist) detail(type) coefmat(matname) varmat(matname) double addlabel(newvarname1, label1, newvarname2, label2, ...) addvar(name1, coef1, stderr1, name2, coef2, stderr2, ...) table(table_suboptions) append replace]

where

table_suboptions are

table(name [, order(string) format(%fmt) parentheses(statlist) brackets(statlist) asterisk(numlist)])

namelist corresponds to names of regressors for estimation results currently stored in e(),

type can be either all, scalars, or macros, and

statlist is one or more of the following: coef, stderr, tstat, pval, ci_lower, ci_upper

Description

regsave fetches output from Stata's e() macros, scalars, and matrices and stores them in a Stata-formatted dataset. It has two main uses:

1. regsave provides a user-friendly way to manipulate a large number of regression results by allowing you to apply Stata's data manipulation commands to those results. For example, you can save the results of 100 regressions to a dataset and then use Stata to analyze how coefficients change across different regression specifications. Or, you can outsheet these results and analyze them using external utilities like Microsoft Excel's pivot table.

2. regsave saves your regression results to a nicely formatted table when you specify its table() option. You can then outsheet or xmlsave your data and open it in another program. LaTeX users can use texsave (if installed) to automatically output their table to LaTeX format (see example 7 below).

Options

tstat calculates t-statistics by dividing coef by stderr.

pval calculates two-tailed p-values using the t-statistic and the residual degrees of freedom (as retrieved from e(df_r)). If the residual degrees of freedom are unavailable, the p-value is calculated by assuming normality.

ci calculates confidence intervals according to the confidence level set by level (default controlled by set level) and the residual degrees of freedom (as retrieved from e(df_r)). If the residual degrees of freedom are unavailable, the confidence interval is calculated by assuming normality.

level(#) specifies the confidence level, as a percentage, for confidence intervals. The default is level(95) or as set by set level.

nose drops standard errors from the reported results.

cmdline stores the Stata command code that produced the estimation results, if it's available from e(cmdline).

autoid provides an id number for your saved results. This is useful when saving a large number of results to the same dataset. autoid can be used as a complement to and/or substitute for addlabel().

covar(namelist) instructs Stata to store all possible combinations of covariances for the variables specified in namelist.

detail(type) stores additional statistics. If type is all, regsave retrieves all results available in e(). The user may alternatively specify a subset of those results: either scalars or macros.

coefmat(matname) instructs Stata to retrieve coefficient estimates from matname instead of e(b), the default. See the notes section below for more information.

varmat(matname) instructs Stata to retrieve variance estimates from matname instead of e(V), the default. See the notes section below for more information.

double specifies that all numeric statistics be stored as doubles instead of floats.

addlabel(newvarname1, label1, newvarname2, label2, ...) instructs Stata to create additional variables containing label data. The user-specified label1 is stored in newvarname1, label2 is stored in newvarname2, etc. This is a good way to label your results when storing lots of regression results together in one dataset. It is also a good way to store additional statistics that are not automatically retrieved by regsave (see example 4 below).

addvar(name1, coef1, stderr1, name2, coef2, stderr2, ...) allows the user to store estimates for variables that are not currently stored in e(b) and e(V) (see example 5 below).

table(name, suboptions) stores estimates in a traditional table form, i.e., with standard errors (and t-statistic and p-values, if specified) listed below coefficient estimates in a single column. name specifies the name of the column.

suboptions:

order(string) allows the user to specify the table's row order. The name regvars can be used to refer to all regression variables retrieved by regsave (see example 6 below).

format(%fmt) suboption allows you to specify the formats of the numbers in your table. For example, a format of %7.2f specifies that numbers are to be rounded to two decimal places. See [D] format for details.

parentheses(statlist) suboption puts parentheses around statlist.

brackets(statlist) suboption puts brackets around statlist.

asterisk(numlist) allows you to specify up to three (descending) significance levels for asterisks. For example, asterisk(5 1) place a */** next to coefficients that are significant at the 5/1% level, respectively. Specifying asterisk() sets a default, which places a */**/*** next to coefficients that are significant at the 10/5/1% level.

append appends the regression results to the Stata-formatted dataset filename.

replace overwrites filename.

Notes

By default, Stata retrieves coefficient and variance estimates from e(b) and e(V), respectively. One exception is if the user executes regsave after running a dprobit estimation. In that case, regsave retrieves the estimates from e(dfdx) and e(se_dfdx). Use options coefmat(matname) and varmat(matname) if you want to retrieve estimates from matrices that differ from these defaults. Note that regsave will take the square root of varmat(matname) unless the string "se" is detected in matname (in which case it assumes that standard errors, not variances, are reported).

List of retrieved items

regsave automatically retrieves the following items from e() when they are available:

Matrices e(b) Coefficient estimates (can be overridden with optio > n coefmat(matname)) e(V) Variance-covariance matrix (can be overridden with > option varmat(matname))

Scalars e(N) Number of observations e(r2) R-squared

If detail(all) is specified, regsave retrieves all available statistics from e().

Saved results

regsave saves the following scalars to r():

r(N) Number of rows in the newly created dataset r(k) Number of columns in the newly created dataset

Examples

1. Store regression results in the active dataset:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. regsave

. browse

2. Store regression results in a file:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. regsave using results, tstat covar(mpg trunk) replace

3. Store regression results in table form:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. regsave, tstat pval table(regression_1, parentheses(stderr) brackets(t > stat pval))

. browse

4. Store a user-created statistic and label a series of regressions:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length if gear_ratio > 3

. regsave using results, addlabel(scenario, gear ratio > 3, dataset, aut > o) replace

. regress price mpg trunk headroom length if gear_ratio <= 3

. regsave using results, addlabel(scenario, gear ratio <=3, dataset, aut > o) append

5. Store regression results and add coefficient and standard error estimates for an additional variable:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. local mycoef = _b[mpg]*5

. local mystderr = _se[mpg]*5

. regsave, addvar(mpg_5, `mycoef', `mystderr')

. browse

6. Run a series of regressions and outsheet them into a text file that can be opened by MS Excel:

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. regsave mpg trunk using results, table(OLS_stderr, order(regvars r2)) > replace

. regress price mpg trunk headroom length, robust

. regsave mpg trunk using results, table(Robust_stderr, order(regvars r2 > )) append

. use results, clear

. outsheet using table.txt, replace

7. Run a series of regressions and output the results in a nice LaTeX format that can be opened by Scientific Word. (This example requires the user-written command texsave to be installed.):

. sysuse auto.dta, clear

. regress price mpg trunk headroom length

. regsave mpg trunk using results, table(OLS, order(regvars r2) format(% > 5.3f) parentheses(stderr) asterisk()) replace

. regress price mpg trunk headroom length, robust

. regsave mpg trunk using results, table(Robust, order(regvars r2) forma > t(%5.3f) parentheses(stderr) asterisk()) append

. use results, clear

. replace var = subinstr(var,"_coef","",.)

. replace var = "" if strpos(var,"_stderr")!=0

. replace var = "R-squared" if var == "r2"

. rename var Variable

. texsave using "table.tex", title(Regression results) footnote("A */**/ > *** next to the coefficient indicates significance at the 10/5/1% level") rep > lace

Author

Julian Reif, University of Chicago

jreif@uchicago.edu

Also see

estimates store, outreg2 (if installed), sortobs (if installed), texsave (if installed), svret (if installed)