linearmodels.panel.covariance.DriscollKraay¶
-
class linearmodels.panel.covariance.DriscollKraay(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]¶ Driscoll-Kraay heteroskedasticity-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. It must be below the number of time periods. The Bartlett and Parzen kernels use its integer part. If not provided a rule-of-thumb value is used.
- Raises:¶
ValueError – If the bandwidth, or the default bandwidth if none is given, is not below the number of time periods. It is also raised 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
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_t & = \sum_{i=1}^{n_t} \epsilon_i x_{i} \\ \hat{S}_0 & = \sum_{i=1}^{t} \xi'_t \xi_t \\ \hat{S}_j & = \sum_{i=1}^{t-j} \xi'_t \xi_{t+j} + \xi'_{t+j} \xi_t \\ \hat{S} & = (n-df)^{-1} \sum_{j=0}^{bw} K(j, bw) \hat{S}_j\end{split}\]where df is
extra_dfand n-df is replaced by n-df-k ifdebiasedisTrue. \(K(i, bw)\) is the kernel weighting function.The sums \(\xi_t\) of the scores of the \(T\) time periods have autocovariances up to lag \(T-1\), so the bandwidth must be below \(T\). The bandwidth is checked when the estimator is created, so that the
fitmethod of a model raises the error.Changed in version 7.1: A bandwidth that is not below the number of time periods raises a
ValueError. Earlier versions raised “Length of w is larger than the number of elements in z” with the Bartlett and Parzen kernels, when the covariance was first used. The quadratic spectral kernel, which has no truncation, returned a covariance without an error. With a large bandwidth the weights of all of the lags are close to one, and the sum of the scores over all of the periods is zero in a regression, so that the covariance was close to zero.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.