linearmodels.iv.model.IVGMM

class linearmodels.iv.model.IVGMM(dependent: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...], exog: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None, endog: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None, instruments: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None, *, weights: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None = None, weight_type: str = 'robust', **weight_config: Any)[source]

Estimation of IV models using the generalized method of moments (GMM).

Parameters:
dependent: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...]

Dependent variable (nobs by 1).

exog: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None

Exogenous regressors (nobs by nexog). None if the model has no exogenous regressors.

endog: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None

Endogenous regressors (nobs by nendog). None if the model has no endogenous regressors.

instruments: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None

Instrumental variables (nobs by ninstr). None if the model has no instruments.

weights: IVData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None = None

Observation weights used in estimation. The weights must be strictly positive and finite. They are rescaled to have a mean of 1. A NaN weight is missing, and its observation is dropped. The default is to weight all observations equally.

weight_type: str = 'robust'

Name of moment condition weight function to use in the GMM estimation. The default is “robust”. The names are not case sensitive. The supported weight functions are:

  • ”unadjusted”, “homoskedastic”

  • ”robust”, “heteroskedastic”

  • ”kernel”

  • ”clustered”, “one-way”

See Notes for their assumptions.

**weight_config: Any

Additional keyword arguments to pass to the moment condition weight function. The keys are center (bool) and debiased (bool) for every weight function, kernel (str), bandwidth (int) and optimal_bw (bool) for “kernel”, and clusters (array_like) for “clustered”. The names of the kernels are not case sensitive. clusters is required and has one element for each observation. See HomoskedasticWeightMatrix, HeteroskedasticWeightMatrix, KernelWeightMatrix and OneWayClusteredWeightMatrix for the details.

Raises:
  • ValueError – If the model has no regressors, if there are fewer instruments than endogenous regressors, if [exog, endog] or [exog, instruments] does not have full column rank, if all observations have a missing value, if the inputs have different numbers of observations or labels that do not match (see Notes), or if weights are not strictly positive and finite.

  • UnknownOptionError – If weight_type is not supported, or if it is “kernel” and kernel is not a supported kernel. It is both a KeyError and a ValueError. Before 7.1, an unsupported kernel was reported by fit.

  • TypeError – If an input is complex or cannot be converted to float64.

See also

linearmodels.iv.model.IV2SLS

Estimation of IV models using two-stage least squares.

linearmodels.iv.model.IVLIML

Limited information ML and k-class estimation of IV models.

linearmodels.iv.model.IVGMMCUE

Estimation of IV models using continuously updating GMM.

Notes

Available GMM weight functions are:

  • “unadjusted”, “homoskedastic” - Assumes moment conditions are homoskedastic

  • “robust”, “heteroskedastic” - Allows for heteroskedasticity but not autocorrelation

  • “kernel” - Allows for heteroskedasticity and autocorrelation

  • “clustered”, “one-way” - Allows for one-way cluster dependence

The estimator is defined as

\[\hat{\beta}_{gmm}=(X'ZW^{-1}Z'X)^{-1}X'ZW^{-1}Z'Y\]

where \(W\) is a positive definite weight matrix and \(Z\) contains both the exogenous regressors and the instruments.

The bandwidth of a kernel weight matrix (weight_type="kernel") is bandwidth if it is given in weight_config. If neither bandwidth nor optimal_bw is given, it is estimated from the data, as the bandwidth of the kernel covariance of IV2SLS and IVLIML is. In 7.0 and earlier it was nobs - 2, which is not a consistent estimator, so the estimates, standard errors and J statistic can be different. fit issues a DefaultBandwidthWarning (a UserWarning) when it uses the default. To restore the previous behavior, pass optimal_bw=False or bandwidth=nobs - 2 in weight_config, for example IVGMM(dependent, exog, endog, instruments, weight_type="kernel", optimal_bw=False). Passing bandwidth or optimal_bw silences the warning, and optimal_bw=True selects the bandwidth from the data without it. The same holds for cov_type="kernel" in fit. See KernelWeightMatrix and IVGMMCovariance.

The bandwidth that is estimated from the data needs at least 4 observations with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel. fit raises a ValueError for fewer observations, and if the estimated bandwidth is not finite. Pass bandwidth or optimal_bw=False to use the kernel with fewer observations. See kernel_optimal_bandwidth().

Rows are paired by position. An input that carries labels (a pandas Series or DataFrame with an index other than the default 0, 1, …, n-1, or an xarray DataArray with coordinates) must use the same index, in the same order, as dependent, so that a value cannot be attached to the wrong observation. A ValueError is raised if the index of exog, endog, instruments or weights differs from the index of dependent. Either reindex the input to the index of dependent, or call to_numpy() to pair its values by position. NumPy arrays and pandas objects with a default index do not carry labels and are always paired by position. If dependent does not carry labels, the inputs that do must use the same index as the first of exog, endog, instruments and weights that does. The same rule applies to clusters passed to fit or in weight_config. Dates and time deltas are compared by value, so that the same dates at different resolutions, e.g., datetime64[us] and datetime64[ns], are the same labels.

The weight matrix is the inverse of an estimate of the covariance of the moment conditions, so that the estimate has to be nonsingular. A clustered estimate from G clusters has rank at most G, and at most G - 1 if the moment conditions are centered (center is True), since the centered cluster sums add to zero. There have to be at least as many clusters as moment conditions, and more if they are centered. The first step moment conditions of an exactly identified model add to zero as well, so that it needs more clusters than moment conditions with every value of center. The rank of a kernel or robust estimate is bounded in the same way by the number of observations. fit raises a ValueError that says so if the estimate is singular, since the estimates would be numerical noise. The estimate is not used, and so it is not tested, if iter_limit is 1.

Todo

  • VCV: bootstrap

Methods

estimate_parameters(x, y, z, w)

Parameter estimation without error checking.

fit(*[, iter_limit, tol, initial_weight, ...])

Estimate model parameters.

from_formula(formula, data, *[, weights, ...])

Create a model from a formula.

predict(params, *[, exog, endog, data, eval_env])

Predict values for additional data.

resids(params)

Compute model residuals.

wresids(params)

Compute weighted model residuals.

Properties

formula

Formula used to create the model.

has_constant

Flag indicating the model includes a constant or equivalent.

isnull

Locations of observations with missing values.

notnull

Locations of observations included in estimation.