estpost together with esttab can be very useful in exporting outputs to tables.
estpost posts results from various commands in e(). esttab displays formatted tables.
sysuse auto
estpost tabstat price mpg weight if rep78 <= 4, by(foreign) s(count mean sd p50 min max) columns(statistics)
This posted the results from tabstat to the screen.
Summary statistics: count mean sd p50 min max
for variables: price mpg weight
by categories of: foreign
foreign | e(count) e(mean) e(sd) e(p50) e(min) e(max)
-------------+------------------------------------------------------------------
Domestic |
price | 46 6265.109 3230.865 4912 3291 15906
mpg | 46 19 4.027682 19 12 29
weight | 46 3429.565 633.463 3385 1800 4840
-------------+------------------------------------------------------------------
Foreign |
price | 12 5903.25 1826.219 5654 3895 9735
mpg | 12 24.5 2.645751 24.5 21 30
weight | 12 2158.333 307.3001 2100 1760 2750
-------------+------------------------------------------------------------------
Total |
price | 58 6190.241 2984.357 5006.5 3291 15906
mpg | 58 20.13793 4.382774 19.5 12 30
weight | 58 3166.552 777.7195 3290 1760 4840
To export the output to a csv file, use esttab:
esttab using table1.csv, replace cell((count mean sd p50 min max)) nonumber nomtitle
The commands below quietly posted the results from ttest and appended all e(b) and e(t) results to a csv file.
local i = 1
while `i' < 3{
foreach var in price mpg {
qui estpost ttest `var' if rep78 == `i' | rep78 == `i'+1, by(rep78)
esttab using table2.csv, append nonumber nomtitle nonotes
}
local i = `i' + 1
}
Commands below first stored regression outs from each model and appended all of them to a table in a csv file.
local i = 1
while `i' < 4{
foreach depvar of varlist var1 var2 var3 {
areg `depvar' ib`i'.rank if rank <= `i'+1 & rank >= `i', absorb(a)
est sto m1
areg `depvar' ib`i'.rank if rank <= `i'+1 & rank >= `i', absorb(b)
est sto m2
areg `depvar' ib`i'.rank if rank <= `i'+1 & rank >= `i', absorb(b)
est sto m3
esttab m1 m2 m3 using table3.csv, append se nonumber title(`depvar') mtitle("a fe" "b fe" "c fe")
}
local i = `i' + 1
}