Search code examples
stata

Stata: adding coefficients to estout


I want to output the results of several regressions as a nicely formatted LaTeX table and am happy to see that for most cases the estout package on SSC seems to do exactly that.

However, what I want is a bit special: Between the table section that shows the coefficient estimates and their standard errors, and the section that shows R^2 and the like, I would like to add a section that shows point estimates and standard errors (bonus points for stars) for particular linear combinations of the coefficients. Both point estimates and standard errors are easily computed via lincom but the best solution I've found so far for getting these numbers into the table involves the massily hacky addition of these numbers, one estadd scalar ... at a time. Is there a more elegant way to do this?

Example code:

sysuse auto
eststo, title("Model 1"): regress price weight mpg
lincom weight+mpg
estadd scalar skal r(estimate)
estadd scalar skalsd r(se)
eststo, title("Model 2"): regress price weight mpg foreign
lincom weight+mpg
estadd scalar skal r(estimate)
estadd scalar skalsd r(se)
label variable foreign "Car type (1=foreign)"
estout, cells(b(star fmt(3)) t(par fmt(2)))  ///
     stats(skal skalsd r2 N, labels("Linear Combination" "S.E." R-squared "N. of cases")) ///
     label legend varlabels(_cons Constant)

Solution

  • You can use the layout, star and fmt sub-options to format the added scalars like this:

    estout, cells(b(star fmt(3)) t(par fmt(2)))  ///
         stats(skal skalsd r2 N, layout(@ (@) @ @) star(skal) labels("Linear Combination" "S.E." R-squared "N. of cases") fmt(%9.2f %9.2f %9.2f %12.0f)) ///
         label legend varlabels(_cons Constant)
    

    These options are documented here. As far as I know, the method in your question is the only way to do this.