linearmodels.panel.covariance.ClusteredCovariance¶
-
class linearmodels.panel.covariance.ClusteredCovariance(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, clusters: ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None =None, group_debias: bool =False)[source]¶ One-way (Rogers) or two-way clustered 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.
- clusters: ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None =
None¶ Array of cluster group ids with nobs rows and 1 or 2 columns. If not provided, every observation is its own cluster.
- group_debias: bool =
False¶ Flag indicating whether to apply small-number of groups adjustment. The default is False.
- 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. It is also raised if clusters has more than 2 columns or does not have nobs rows.
Notes
The estimator of the covariance is
\[\hat{\Sigma}_{xx}^{-1}\hat{S}_{\mathcal{G}}\hat{\Sigma}_{xx}^{-1}\]where
\[\hat{\Sigma}_{xx} = X'X\]and \(\hat{S}_{\mathcal{G}}\) is a one- or two-way cluster covariance of the scores. Two-way clustering is implemented by summing up the two one-way cluster covariances and then subtracting the one-way clustering covariance computed using the group formed from the intersection of the two groups.
Two small sample adjustments are available.
debiased=Truewill account for regressors in the main model.group_debias=Truewill provide a small sample adjustment for the number of clusters of the form\[(g / (g- 1)) ((n - 1) / n)\]where g is the number of distinct groups and n is the number of observations.
Methods
Covariance calculation deferred until executed.
Properties
Estimated covariance.
Model residuals.
Covariance estimator name.
Error variance.