Search code examples
rplmrobust

How to implement HAC Standard Errors in r


I need to solve the issue of serial correlation in a within-model. I calculated the regression with country- and year-fixed effects and then calculated robust standard errors HC1. How can I calculate HAC Standard Errors instead? I've read about function vcovHAC() but I couldn't figure out how to implement it properly.

IVpan <- plm(log(Y) ~ log(X),
             model = "within",
             data = df,
             index = c("countryIdentifier","year"),
             effect = "twoways")
covIVpan         <- vcovHC(IVpan, type = "HC1")
robust_seIVpan    <- sqrt(diag(covIVpan))

Thanks for your support!


Solution

  • coeftest(IVpan, vcov = vcovHAC(IVpan))