heteroskedasticity correction and stargazer

Hi,

I am new on R and I have been trying to simply correct for heteroskedasticity. I use the following function

cse=function(reg) {
  rob=sqrt(diag(vcovHC(reg, type="HC1")))
  return(rob)
}

and then regress two models with and without correction :

library(wooldridge)
data(wage1)
head(wage1)
ols1<-lm(wage~educ, wage1)
ols2<-lm(wage~educ, wage1)

and display them using stargazer

library(wooldridge)
data(wage1)
head(wage1)
ols1<-lm(wage~educ, wage1)
ols2<-lm(wage~educ, wage1)
stargazer( ols1, ols2, type="text", se=list( cse(ols2)), column.labels=c("non-robust", "Robust"))

Yet, stargazer does not correct the second model (ols2) but the first one. How come? I did specify that the cse function ought to be apply to the ols2 object. I don't get why it is correcting only the SE for the first object (ols1) and not the second.

Thanks for your help

Hi there,

In case someone would be facing the same issue the soluation is the following:

library(wooldridge)
data(wage1)
head(wage1)
ols1<-lm(wage~educ, wage1)
ols2<-lm(wage~educ, wage1)
stargazer( ols1, ols2, type="text", se=list(NULL, cse(ols2)), column.labels=c("non-robust", "Robust"))

You just need to specify "NULL" in the SE list to calculate the homoskedastic SE in the first regression.

This solutions applies also to the estimatr package where the code would be:

stargazer(ols1, ols2, type="text", se= starprep(NULL, ols1, se_type ="stata"), column.labels=c( "non-Robust", "robust"))

Best

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.