'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 1:[1]
coeftest(IVpan, vcov = vcovHAC(IVpan))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
