linearmodels.panel.covariance.ClusteredCovariance

class linearmodels.panel.covariance.ClusteredCovariance(y: ndarray, x: ndarray, params: ndarray, entity_ids: ndarray, time_ids: ndarray, *, debiased: bool = False, extra_df: int = 0, clusters: ndarray | DataArray | DataFrame | Series | None = None, group_debias: bool = False)[source]

One-way (Rogers) or two-way clustered covariance estimation

Parameters:
y: ndarray

nobs by 1 stacked array of dependent

x: ndarray

nobs by variables stacked array of exogenous

params: ndarray

variables by 1 array of estimated model parameters

entity_ids: ndarray

(entity x time) by 1 stacked array of entity ids

time_ids: ndarray

(entity x time) by 1 stacked array of time ids

debiased: bool = False

Flag indicating whether to debias the estimator

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

clusters: ndarray | DataArray | DataFrame | Series | None = None

nobs by 1 or nobs by 2 array of cluster group ids

group_debias: bool = False

Flag indicating whether to apply small-number of groups adjustment.

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 adjustment are available. debias=True will account for regressors in the main model. group_debias=True will 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

deferred_cov()

Covariance calculation deferred until executed

Properties

ALLOWED_KWARGS

DEFAULT_KERNEL

cov

Estimated covariance

eps

Model residuals

name

Covariance estimator name

s2

Error variance