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.
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.