linearmodels.panel.covariance.FamaMacBethCovariance

class linearmodels.panel.covariance.FamaMacBethCovariance(y: ndarray[tuple[int, ...], dtype[float64]], x: ndarray[tuple[int, ...], dtype[float64]], params: ndarray[tuple[int, ...], dtype[float64]], all_params: DataFrame, *, debiased: bool = False, bandwidth: float | None = None, kernel: str | None = None)[source]

HAC estimator for Fama-MacBeth estimator.

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.

all_params: DataFrame

(nobs by variables) array of all estimated model parameters.

debiased: bool = False

Flag indicating whether to debias the estimator. The default is False.

bandwidth: float | None = None

Non-negative bandwidth to use. It must be below T, the number of time periods that are used. The Bartlett and Parzen kernels use its integer part. Set to 0 to disable autocorrelation robustness. If not provided, it is computed from the T estimates and is at most T - 1. The computation needs at least 4 time periods with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel. See kernel_optimal_bandwidth().

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

Raises:
  • ValueError – If the bandwidth is not below the number of time periods that are used. It is also raised if the bandwidth is not provided and there are fewer time periods than the kernel needs to compute it, or if the bandwidth that is computed is not finite.

  • UnknownOptionError – If kernel is not one of the supported names, whether or not the covariance is a kernel covariance. It is both a ValueError and a KeyError.

Notes

Covariance is a Kernel covariance of all estimated parameters.

The \(T\) cross-sectional estimates, one for each time period that is used, have autocovariances up to lag \(T-1\), so the bandwidth must be below \(T\). The bandwidth is checked, or computed if it is not provided, when the estimator is created, so that the fit method of the 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 deviations of the estimates from their average sum to zero, so that the covariance was close to zero.

Changed in version 7.1: The bandwidth that is computed from the estimates needs at least 4 time periods with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel, and a ValueError is raised for fewer, when the estimator is created. The deviations of the estimates from their average sum to zero. With fewer periods the rule divides by the sum of all of their autocovariances, which is zero, so that earlier versions raised “cannot convert float infinity to integer” (an OverflowError) or “cannot convert float NaN to integer” when the covariance was first used, or used a bandwidth of \(T-1\) because of the rounding error of the sum.

Changed in version 7.1: A kernel that is not one of the supported names raises an UnknownOptionError when the estimator is created, so that the fit method of the model raises, also if the bandwidth is given. Earlier versions raised it when the covariance was first used, for example when std_errors of the results was read, so that fit returned results that raised when the covariance was used.

Methods

deferred_cov()

Covariance calculation deferred until executed.

Properties

ALLOWED_KWARGS

DEFAULT_KERNEL

all_params

The set of parameters estimated for each of the time periods.

bandwidth

Bandwidth of the kernel.

cov

Estimated covariance.

eps

Model residuals.

name

Covariance estimator name.

s2

Error variance.