I have a set of regressions that are exported using the community-contributed Stata command estout
in the following format:
foreach yvar of varlist yvar1 yvar2 {
eststo: quietly regress `yvar' xvar1 xvar2, robust
estadd ysumm
}
esttab using mydoc.csv, se stats(N ymean r2_a) replace
However, I found that the community-contributed command outreg2
can create better regression tables, so I would like to use that instead.
I would like to include the mean of dependent variable (ymean
) when using outreg2
but I cannot call e(ymean)
as the relevant scalars are not created.
Below is my code:
local first_loop yes
foreach yvar of varlist yvar1 yvar2 {
quietly regress `yvar' xvar1 xvar2, robust
if "`first_loop'"=="yes"{
outreg2 using outreg2_test.xls, replace ctitle(`yvar') ///
addstat(Mean, e(ymean)) label
local first_loop no
}
else {
outreg2 using outreg2_test.xls, append ctitle(`yvar') ///
addstat(Mean, e(ymean)) label
}
}
My code above does not work because outreg2
does not recognize e(ymean)
.
My questions:
Is this scalar specific to
estadd
?Is there a way I can include mean of dependent variable in the regression output table when using
outreg2
?