Stata - Exporting Results

go back to the homepage
go back to the economics page
go back to the Stata page
Article: Jann, B. (2005). Making regression tables from stored estimatesThe Stata Journal 5(3): 288-308.
DO File: Exporting the Results

To quickly export regression results, you can save the majority of the output using estimates store and then display it with estimates table.  Taken from the article above, here are a few modified commands to output a slick LaTeX table:

. ssc install estout
. sysuse auto, clear
. regress price weight mpg
. estimates store eqn1, title(Model 1)
. gnerate forXmpg=foreign*mpg
. regress price weight mpg forXmpg foreign
. estimates store eqn2, title(Model 2)
. estout eqn1 eqn2 using auto.tex, cells("b(label(Coef.) fmt(%9.3f)) p(label(\$p\$-value))")  stats(r2_a N, fmt(%9.3f %9.0f) labels("Adj. \$R^2\$" "No. of cases"))  label msign(--) nolz varwidth(16) modelwidth(13) style(tex)  title(The auto data\label{auto}) varlabels(_cons Constant) mlabels(, span prefix(\multicolumn{@span}{c}{) suffix(})) prehead("\begin{table}\caption{@title}" "\begin{center}" "\begin{tabular}{l*{@M}{rr}}" "\hline") posthead(\hline) prefoot(\hline) postfoot("\hline" "\small\textit{Source:} auto.dta" "\end{tabular}" "\end{center}" "\end{table}")
. !texify -p -c -b --run-viewer auto.tex  

Compile the file auto.tex and you'll have the table.  Unfortunately, Stata gets a little more problematic when customizing tables.  Sometimes you don't have the statistics you'd like.  Extra statistics can be saved with either return or ereturn and then added into table in a way such as estadd, stats(mean sd(nobinary)).  Try this:

. quietly generate x=uniform()
. quietly regress x price weight mpg foreign
. estadd, stats(mean sd(nobinary))
. estimates store eqn3
. estout eqn3, cells("mean sd") stats(N) mlabels(,none) drop(_cons) style(fixed)

You can line up different equations based on common variables (see help estout documentation).  As you begin to do more complicated tables, you will encounter problems of significant digits and aligning by decimals (try the right align, {r}, instead of center or left).  You might find it easier to export results into Excel, format the table how you'd like it, and then export it to LaTex (use Excel2LaTeX).  Other commands you'll want to explore are esttaboutreg2outsheetoutfilemat2txt, and outtable.

Play around and good luck!