2

I am running a multivariate OLS regression using lmtest with two-way clustered standard errors. The coefficients and standard errors work perfectly, but the usual stats (e.g. number of observations, R2, adj. R2, Residual SE, F Statistic) are not being displayed at the bottom of the regression table.

Here is how the code looks:

model1 <- lm(Y ~ X + Z data=df)
model2 <- lm(Y ~ W + Y + Z, data=df)

stargazer(
(coeftest(model1,vcovCL, cluster = ~ A + B)),
(coeftest(model2,vcovCL, cluster = ~ A + B)),
type='text')

Here is the output:

============================================
                    Dependent variable:     
                ----------------------------

                     (1)            (2)     
--------------------------------------------
X                   0.053***                 
                   (0.010)                  

W                                  0.048***   
                                  (0.014)   

Y                                  0.058***   
                                  (0.013)   

Z                   0.089***      0.089***   
                   (0.003)        (0.003)   

============================================
============================================
Note:            *p<0.1; **p<0.05; ***p<0.01

I learned that when I don't use the coeftest function, the table displays the results along with the common stats at the bottom. Please find below the example without the coeftest fuction, which produces the output containing the desired stats at the bottom:

stargazer(model1, model2, type='text')

===================================================================================
                                          Dependent variable:                      
                    ---------------------------------------------------------------                            
                                  (1)                             (2)              
-----------------------------------------------------------------------------------
X                                0.053***                                            
                                (0.002)                                            

W                                                                0.048***            
                                                                (0.002)            

Y                                                                0.058***            
                                                                (0.002)            

Z                               0.089***                        0.089***            
                               (0.0002)                        (0.0002)            

-----------------------------------------------------------------------------------
Observations                   1,119,677                       1,119,677           
R2                               0.151                           0.151             
Adjusted R2                      0.151                           0.151             
Residual Std. Error      0.079 (df = 1119673)            0.079 (df = 1119672)      
F Statistic         66,250.650*** (df = 3; 1119673) 49,690.200*** (df = 4; 1119672)
===================================================================================
Note:                                                   *p<0.1; **p<0.05; ***p<0.01

This other thread (Appending statistics to coeftest output to include in stargazer tables) addresses the same issue, but none of the answers solved the problem.

How do I produce these common statistics while passing the coeftest function through stargazer?

barduco
  • 23
  • 3

2 Answers2

0

try to cluster standard errors this way:

rob_se <- list(sqrt(diag(vcovHC(model1, type = "HC1"))),
sqrt(diag(vcovHC(model2, type = "HC1"))))


stargazer(model1, model2
          digits = 3,
          header = FALSE,
          type = "latex", 
          se = rob_se)
rama27
  • 115
  • 1
  • 1
  • 6
  • Thanks for the feedback! Under this solution, where do I specify the two columns which I would like to cluster standard errors with? I must cluster standard errors two-ways in every model. – barduco Dec 09 '19 at 07:59
0

You could cluster the standard errors by adding the cluster option extending the answer by rama27 and use either or both "group" or "time" as follows:-

rob_se <- 
    list(sqrt(diag(vcovHC(model1, type = "HC1",  cluster = c("group", "time")))),sqrt(diag(vcovHC(model2, type = "HC1",  cluster = c("group", "time")))))
user438383
  • 5,716
  • 8
  • 28
  • 43