SXS
SXS

Reputation: 303

How to display different decimal places for N and R-Squared using esttab?

I use esttab to generate regression tables. Please see sample code below.

eststo clear
eststo: reghdfe y x1      , absorb(year state) cluster(year state)
        estadd local FE       "Yes"
        estadd local Controls "No"
eststo: reghdfe y x1 x2 x3, absorb(year state) cluster(year state)
        estadd local FE       "Yes"
        estadd local Controls "Yes"
esttab ,star(* 0.10 ** 0.05 *** 0.01) b(3) t(2) r2 replace label drop(_cons)   stats(FE Conrols N r2,fmt(%9.0fc) labels("Fixed Effects" "Controls" "Obserations" "R-Squared"))          

Because my dataset is large, I use fmt(%9.0fc) to add commas to my number of observations. However, this option rounds my R-Squared to 0. How can I have integers (with commas) for observations and three decimal places for R-squared?

Also, is there a way to display adjusted R-squared? The user manual suggests that stats disables ar2 but I struggle to find a fix.

Upvotes: 1

Views: 2615

Answers (1)

Arthur Morris
Arthur Morris

Reputation: 1348

esttab is part of estout by Ben Jann, see the online documentation for installation and further information.

Here is a minimal working example using esttab's default formats.

eststo clear        
sysuse auto

eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign

esttab ,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ar2 

Note that ar2 calls adjusted R^2. However, if you are going to use the stats() option to format the number of obs the syntax changes:

esttab ,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ///
    stats(N r2_a)

To apply formats you add a term for each stat, and if you supply fewer terms than stats esttab applies the last one to the remaining stats. This is why your R^2 is rounding to zero. Try the following:

esttab ,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ///
    stats(N r2_a, fmt(%9.0fc %9.2fc)

So I would edit your esttab line as follows:

esttab ,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) /// no 'ar2' here
    label /// note you only need 'replace' if you are generating a file
    nocons /// 'reghdfe' has an option to 'drop(_cons)'   
    stats(FE Controls N r2_a, /// 'Controls' not 'Conrols'
    fmt(%9.0fc %9.0fc %9.0fc %9.2fc) /// it seems you need place holders for the string stats
    labels("Fixed Effects" "Controls" "Obserations" "R-Squared"))          

Upvotes: 3

Related Questions