HAC VCOVs
Set of functions to compute the VCOVs robust to different forms correlation in panel or time series settings.
vcov_DK(x, time = NULL, lag = NULL, ssc = NULL) vcov_NW(x, unit = NULL, time = NULL, lag = NULL, ssc = NULL) NW(lag = NULL) newey_west(lag = NULL) DK(lag = NULL) driscoll_kraay(lag = NULL)
x |
A |
time |
A character scalar or a one sided formula giving the name of the variable representing the time. |
lag |
An integer scalar, default is |
ssc |
An object returned by the function |
unit |
A character scalar or a one sided formula giving the name of the variable representing the units of the panel. |
There are currently three VCOV types: Newey-West applied to time series, Newey-West applied to a panel setting (when the argument 'unit' is not missing), and Driscoll-Kraay.
The functions on this page without the prefix "vcov_" do not compute VCOVs directly but are meant to be used in the argument vcov
of fixest
functions (e.g. in vcov.fixest
or even in the estimation calls).
Note that for Driscoll-Kraay VCOVs, to ensure its properties the number of periods should be long enough (a minimum of 20 periods or so).
If the first argument is a fixest
object, then a VCOV is returned (i.e. a symmetric matrix).
If the first argument is not a fixest
object, then a) implicitly the arguments are shifted to the left (i.e. vcov_DK(~year)
is equivalent to vcov_DK(time = ~year)
) and b) a VCOV-request is returned and NOT a VCOV. That VCOV-request can then be used in the argument vcov
of various fixest
functions (e.g. vcov.fixest
or even in the estimation calls).
Newey WK, West KD (1987). "A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix." Econometrica, 55(3), 703-708. doi:10.2307/1913610.
Driscoll JC, Kraay AC (1998). "Consistent Covariance Matrix Estimation with Spatially Dependent Panel Data." The Review of Economics and Statistics, 80(4), 549-560. doi:10.1162/003465398557825.
Milo G (2017). "Robust Standard Error Estimators for Panel Models: A Unifying Approach" Journal of Statistical Software, 82(3). doi:10.18637/jss.v082.i03.
data(base_did) # # During the estimation # # Panel Newey-West, lag = 2 feols(y ~ x1, base_did, NW(2) ~ id + period) # Driscoll-Kraay feols(y ~ x1, base_did, DK ~ period) # If the estimation is made with a panel.id, the dimensions are # automatically deduced: est = feols(y ~ x1, base_did, "NW", panel.id = ~id + period) est # # Post estimation # # If missing, the unit and time are automatically deduced from # the panel.id used in the estimation vcov_NW(est, lag = 2)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.