I am trying to replicate Statas reghdfe in R.

in Stata:

webuse nlswork, clear
reghdfe ln_w  age ttl_exp tenure not_smsa south, abs(idcode year)  cluster(idcode)

in R: Load the data & libraries:

df = read.dta13("http://www.stata-press.com/data/r14/nlswork.dta")

Using lfe package does not return the same standard errors:

## using lfe
model5 = felm(ln_wage ~    age + ttl_exp + tenure+  not_smsa  + south
          | idcode + year | 0 | idcode , 
          data = df, exactDOF=TRUE)

Using plm does get it right, but does not allow for two way clustering:

## using plm
model5 = plm( ln_wage ~   grade + age + ttl_exp + tenure+  not_smsa  + south  
            , data=df, index=c('idcode', 'year'), model="within", effect ="twoways")  # time and id fixed effects

coeftest(model5, vcov=vcovHC(model5,type="HC0",cluster="group")) # <- this gives clustered errors

How can I modify felm to get Stata reghdfe clustered standard errors? What are the difference in implementations that yield those differences?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.