Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export multiple set of regressions into one Excel workbook using either outreg2 or esttab?

Tags:

excel

stata

I have multiple sets of regressions that need to be presented in different tables. I wonder if there is a way to export multiple set of regressions into one Excel workbook using either outreg2 or esttab or some other package?

For example, I run 100 regressions using esttab; then I want to present them in 25 different tables with four regressions in each table. The following format of code allows me to export to 25 different csv files:

esttab using "$output\output1.csv", se stats(N ymean r2_a) replace

However, I want to have all the 25 tables in one workbook with 25 tabs. It is possible to copy-paste the tables if the number of output files is not big, but that's not the case for me.

like image 732
SXS Avatar asked Sep 16 '15 19:09

SXS


People also ask

How do I export from Stata to Excel?

The putexcel command exports Stata results to an Excel file. You can easily export a matrix or a table of estimation results. putexcel is also great for exporting multiple sets of results because you can format entire rows and columns, and loop over them. The putdocx and putpdf suites export Stata results to .

What is Outreg?

outreg can arrange the results of Stata estimation commands in tables as they are typically presented in journal articles, rather than as they are presented in the Stata Results window. By default, t statistics appear in parentheses below the coefficient estimates with asterisks for significance levels.

How do I paste a table from Stata to Word?

Copy as image from the results window and paste into Word Highlight the output you want to save, then use the pulldown menu to choose Edit and then Copy as Picture. This is illustrated below. You can then go to Microsoft Word and from its pulldown menu choose Edit then Paste.


1 Answers

With outreg2, you'll need to use the dta option to save the results as individual datasets, and then use the export excel command to export each dataset to an individual sheet in the same tab. E.g.:

clear all
sysuse auto

regress price mpg
outreg2 using "price" , replace dta

regress price mpg headroom
outreg2 using "price" , dta

regress mpg weight length
outreg2 using "mpg" , replace dta

regress mpg weight length foreign
outreg2 using "mpg" , dta

use price_dta
export excel using "results" , sheet("price")

use mpg_dta
export excel using "results" , sheet("mpg")

Obviously running this as a loop will make more sense, and you may want to add the replace option to the first use of outreg2. Further use of outreg2's options will help clean up the output further.

like image 173
Brendan Avatar answered Sep 28 '22 01:09

Brendan