Computes the heteroskedasticity-robust VCOV of fixest
objects.
Arguments
- x
A
fixest
object.- type
A string scalar. Either "HC1"/"HC2"/"HC3"
- exact
Logical scalar, default is
TRUE
. Whether the diagonals of the projection matrix should be calculated exactly. IfFALSE
, then it will be approximated using a JLA algorithm. See details. Unless you have a very large number of observations, it is recommended to keep the default value.- boot.size
Integer scalar or
NULL
, default is 1000. This is only used whenexact == FALSE
. This determines the number of bootstrap samples used to estimate the projection matrix. If equal toNULL
, it falls back to the default value of 1000.- ssc
An object returned by the function
ssc
. It specifies how to perform the small sample correction.- vcov_fix
Logical scalar, default is
FALSE
. If the VCOV ends up not being positive definite, whether to "fix" it using an eigenvalue decomposition (a la Cameron, Gelbach & Miller 2011). Since the VCOV should be PSD asymptotically, this might be a sign of a problem with using the asymptotic approximation (e.g. too few units in clusters). If a problem is detected, the function will print a message to inform you.
Value
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_hetero("HC3")
is equivalent to vcov_hetero(type = "HC3")
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).
References
MacKinnon, J. G. (2012). "Thirty years of heteroscedasticity-robust inference." Recent Advances and Future Directions in Causality, Prediction, and Specification Analysis, pp. 437–461. https://doi.org/10.1007/978-1-4614-1653-1_17
Examples
base = iris
names(base) = c("y", "x1", "x2", "x3", "species")
est = feols(y ~ x1 | species, base)
vcov_hetero(est, "hc1")
#> x1
#> x1 0.01127604
vcov_hetero(est, "hc2", ssc = ssc(K.adj = FALSE))
#> x1
#> x1 0.01143592
vcov_hetero(est, "hc3", ssc = ssc(K.adj = FALSE))
#> x1
#> x1 0.01192059
# Using approximate hatvalues
vcov_hetero(est, "hc3", exact = FALSE, boot.size = 500)
#> x1
#> x1 0.0119263