linearmodels.iv.gmm.KernelWeightMatrix

class linearmodels.iv.gmm.KernelWeightMatrix(kernel: str = 'bartlett', bandwidth: int | None = None, center: bool = False, debiased: bool = False, optimal_bw: bool | None = None)[source]

Heteroskedasticity, autocorrelation robust weight estimation.

Parameters:
kernel: str = 'bartlett'

Name of kernel weighting function to use. The default is “bartlett”. 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: int | None = None

Bandwidth to use when computing kernel weights. If not provided, the bandwidth is selected by optimal_bw.

center: bool = False

Flag indicating whether to center the moment conditions by subtracting the mean before computing the weight matrix. The default is False.

debiased: bool = False

Flag indicating whether to use small-sample adjustments. The default is False.

optimal_bw: bool | None = None

Flag indicating whether to estimate the bandwidth from the data when bandwidth is not provided. If False, nobs - 2 is used. If True, the bandwidth is estimated using kernel_optimal_bandwidth(), which needs at least 4 observations with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel. The default also estimates the bandwidth, but it issues a DefaultBandwidthWarning since it changed in 7.1.

See also

linearmodels.iv.covariance.kernel_weight_bartlett

Kernel weights from a Bartlett kernel.

linearmodels.iv.covariance.kernel_weight_parzen

Kernel weights from a Parzen kernel.

linearmodels.iv.covariance.kernel_weight_quadratic_spectral

Kernel weights from a quadratic-spectral kernel.

Notes

The weight matrix is

\[\begin{split}g_i & =z_i \epsilon_i \\ W & =n^{-1}(\Gamma_0+\sum_{j=1}^{n-1}k(j)(\Gamma_j+\Gamma_j')) \\ \Gamma_j & =\sum_{i=j+1}^n g'_i g_{i-j}\end{split}\]

where \(k(j)\) is the kernel weight for lag j and \(z_i\) contains both the exogenous regressors and instruments.

If neither bandwidth nor optimal_bw is given, the bandwidth is estimated from the data every time that the weight matrix is computed. In 7.0 and earlier the default was nobs - 2, which is not a consistent estimator of the covariance of the moment conditions. Using the default issues a DefaultBandwidthWarning (a UserWarning), once for each instance. The previous behavior is restored by optimal_bw=False or by bandwidth=nobs - 2. Passing bandwidth or optimal_bw silences the warning, and optimal_bw=True selects the new default without it. IVGMMCUE estimates the bandwidth once, from the residuals of the first step estimates, and uses it in every evaluation of its objective function.

Changed in version 7.1: weight_matrix raises a ValueError if the bandwidth is estimated from the data and there are fewer observations than the kernel needs (see optimal_bw), or if the estimated bandwidth is not finite. Pass bandwidth or optimal_bw=False to use the weight matrix with fewer observations. Earlier versions raised “cannot convert float infinity to integer” (an OverflowError) or “cannot convert float NaN to integer” for some data when optimal_bw was True, and used a bandwidth of nobs - 1, or another bandwidth, for other data.

Methods

weight_matrix(x, z, eps)

Compute the covariance of the moment conditions.

Properties

bandwidth

Actual bandwidth used in estimating the weight matrix.

config

Weight estimator configuration.