Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stata: adding coefficients to estout

Tags:

stata

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)
like image 321
RoyalTS Avatar asked Oct 03 '22 15:10

RoyalTS


2 Answers

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.

like image 159
dimitriy Avatar answered Oct 07 '22 20:10

dimitriy


There's a problem with the answer above. I think the original poster wanted statistical significance stars based on a test of the lincom (weight+mpg) vs zero. That is not what star(skal) does.

As the documentation states: star[(scalarlist)] to specify that the overall significance of the model be denoted by stars. The stars are attached to the scalar statistics specified in scalarlist." Emphasis mine.

star(skal) in the previous example will place significance stars next to the estimates of skal, but they will be from an F-test of the overall significance of the regression model (I think). Not from lincom.

When I use this strategy on other specifications, the stars attached are clearly not based on the ones from lincom. I'm not sure if it's possible to use lincom/esttab to get the stars from lincom. To say nothing of nlcom!

like image 39
ABC Avatar answered Oct 07 '22 19:10

ABC