linearmodels.panel.covariance.ACCovariance¶
-
class linearmodels.panel.covariance.ACCovariance(y: ndarray[tuple[int, ...], dtype[float64]], x: ndarray[tuple[int, ...], dtype[float64]], params: ndarray[tuple[int, ...], dtype[float64]], entity_ids: ndarray[tuple[int, ...], dtype[integer]], time_ids: ndarray[tuple[int, ...], dtype[integer]], *, debiased: bool =
False, extra_df: int =0, kernel: str | None =None, bandwidth: float | None =None)[source]¶ Autocorrelation robust covariance estimation.
- Parameters:¶
- y: ndarray[tuple[int, ...], dtype[float64]]¶
(entity x time) by 1 stacked array of the dependent variable.
- x: ndarray[tuple[int, ...], dtype[float64]]¶
(entity x time) by variables stacked array of the exogenous variables.
- params: ndarray[tuple[int, ...], dtype[float64]]¶
Variables by 1 array of estimated model parameters.
- entity_ids: ndarray[tuple[int, ...], dtype[integer]]¶
(entity x time) by 1 stacked array of entity ids.
- time_ids: ndarray[tuple[int, ...], dtype[integer]]¶
(entity x time) by 1 stacked array of time ids.
- debiased: bool =
False¶ Flag indicating whether to debias the estimator. The default is False.
- extra_df: int =
0¶ Additional degrees of freedom consumed by models beyond the number of columns in x, e.g., fixed effects. Covariance estimators are always adjusted for extra_df irrespective of the setting of debiased. The default is 0.
- kernel: str | None =
None¶ Name of the kernel. If not provided, “newey-west”, which is the Bartlett kernel, is used. The names are not case sensitive. Supported kernels are:
”bartlett”, “newey-west” - Bartlett’s kernel
”parzen”, “gallant” - Parzen’s kernel
”qs”, “quadratic-spectral”, “andrews” - Quadratic spectral kernel
- bandwidth: float | None =
None¶ Non-negative bandwidth to use. The Bartlett and Parzen kernels use its integer part. If not provided a rule-of-thumb value is used. It can be larger than the number of observations of an entity.
- Raises:¶
ValueError – If the model has no residual degrees of freedom: the number of observations less
extra_df, and less the number of regressors ifdebiasedis True, is not positive.UnknownOptionError – If
kernelis not one of the supported names. It is both aValueErrorand aKeyError.
Notes
Estimator is robust to autocorrelation but not cross-sectional correlation.
Bandwidth is set to the common value for the Bartlett kernel if not provided, \(\lfloor 4 (T / 100)^{2/9} \rfloor\) where \(T\) is the number of time periods.
The estimator of the covariance is
\[n^{-1}\hat{\Sigma}_{xx}^{-1}\hat{S}\hat{\Sigma}_{xx}^{-1}\]where
\[\hat{\Sigma}_{xx} = n^{-1}X'X\]and
\[\begin{split}\xi_{it} & = \epsilon_{it} x_{it} \\ \hat{S} & = (n-df)^{-1} \sum_{i=1}^N S_i \\ \hat{S}_i & = \sum_{j=0}^{T_i-1} K(j, bw) \hat{S}_{ij} \\ \hat{S}_{i0} & = \sum_{t=1}^{T_i} \xi'_{it} \xi_{it} \\ \hat{S}_{ij} & = \sum_{t=1}^{T_i-j} \xi'_{it} \xi_{it+j} + \xi'_{it+j} \xi_{it}\end{split}\]where \(T_i\) is the number of observations of entity \(i\), df is
extra_dfand n-df is replaced by n-df-k ifdebiasedisTrue. \(K(j, bw)\) is the kernel weighting function, which is 1 for the lag 0. The Bartlett and Parzen kernels are 0 for the lags abovebandwidth.Lags
The lag between two observations of an entity is the difference between their positions in the observations of the entity, which are in the order of time. It is not the difference between their time periods. If a period is missing between two observations of an entity, they are one lag apart. With the Bartlett kernel the covariance is that of the cluster-HAC option of statsmodels (
cov_type="hac-panel"), which also counts positions. plm (vcovNW) and sandwich (vcovPL) pair the observations that are \(j\) periods apart, so that their covariances are different if an entity has missing periods between its observations: in a panel where about a quarter of the periods are missing the standard errors differed by about 3%. They are the same if no entity has a gap. See Gaps in the Periods of an Entity.Entities with few observations
An entity has the lags \(0,\ldots,T_i-1\), and its sum is over these lags. The weights are those of the bandwidth that was chosen, \(K(j, bw)\), also for an entity with fewer observations than the bandwidth. The bandwidth is not reduced to \(T_i-1\) for such an entity, and the weights of the lags that the entity does not have are not used. This is how plm, sandwich and statsmodels compute the covariance.
Changed in version 7.1: The entities are not weighted by their numbers of observations: each entity contributes the sum of the products of its scores. Earlier versions divided the sum of each entity by its number of observations and averaged over the entities, which is the same for a balanced panel. For an unbalanced panel the covariance, e.g., with a bandwidth of 0, was not the heteroskedasticity robust covariance, and differed from the covariance of other packages.
Changed in version 7.1: An entity with \(T_i\) observations, where \(T_i \leq bw\), keeps the weights of the bandwidth. Earlier versions replaced the bandwidth of the entity by \(T_i-1\). This changed the Bartlett weights of the entity from \(1-j/(bw+1)\) to \(1-j/T_i\), the Parzen weights in the same way, and the bandwidth of the quadratic spectral kernel. The covariance changes if any entity has fewer observations than the bandwidth, which is more likely in a panel where the entities are short or the bandwidth is large.
Changed in version 7.1: A
kernelthat is not one of the supported names raises anUnknownOptionErrorwhen the estimator is created, so that thefitmethod of a model raises. Earlier versions raised it when the covariance was first used, for example whenstd_errorsof the results was read, so thatfitreturned results that raised when the covariance was used.Methods
Covariance calculation deferred until executed.
Properties
Estimated covariance.
Model residuals.
Covariance estimator name.
Error variance.