linearmodels.iv.model.IVGMMCUE

class linearmodels.iv.model.IVGMMCUE(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 continuously updating 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.IVGMM

Estimation of IV models using the generalized method of moments.

Notes

Available 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

In most circumstances, the center weight option should be True to avoid starting value dependence. It is True unless center is passed in weight_config.

The covariance of the moment conditions has to be nonsingular. A clustered covariance that is estimated from G clusters has rank at most G, and at most G - 1 if the moment conditions are centered, so that there have to be more clusters than moment conditions if center is True. If center is False and there are as many clusters as moment conditions, the covariance is nonsingular but the objective function is the same for every value of the parameters, so that there is nothing to optimize. There have to be more clusters than moment conditions whether or not the moment conditions are centered.

\[\begin{split}\hat{\beta}_{cue} & =\min_{\beta}\bar{g}(\beta)'W(\beta)^{-1}g(\beta)\\ g(\beta) & =n^{-1}\sum_{i=1}^{n}z_{i}(y_{i}-x_{i}\beta)\end{split}\]

where \(W(\beta)\) is a weight matrix that depends on \(\beta\) through \(\epsilon_i = y_i - x_i\beta\).

The bandwidth of a kernel weight matrix (weight_type="kernel") is bandwidth if it is given in weight_config, and nobs - 2 if optimal_bw is False. Otherwise, which is the default and what optimal_bw=True does, it is estimated from the data, as the bandwidth of the kernel covariance of IV2SLS and IVLIML is. It is estimated once, from the residuals of the first step estimates (the two-stage least squares estimates, which are also the first step of IVGMM), and the same bandwidth is used for the starting values, for every evaluation of the objective function, and for the weight matrix, J statistic and centered J statistic of the estimates. The objective function is smooth in the parameters, as the optimizer needs it to be. A bandwidth that is estimated again at every evaluation changes by whole lags with the parameters, which makes the objective a step function, and the optimizer stopped before the minimum in about one fit in ten in a simulation with autocorrelated errors. The bandwidth that was used is in weight_config.

In 7.0 and earlier the default bandwidth 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 IVGMMCUE(dependent, exog, endog, instruments, weight_type="kernel", optimal_bw=False). Passing bandwidth or optimal_bw silences the warning. The same holds for cov_type="kernel" in fit, whose bandwidth is estimated from the residuals of the final estimates. Before 7.1, optimal_bw=True estimated the bandwidth of the objective function at every evaluation and used nobs - 2 for the starting values, so its estimates change slightly. 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.

Methods

estimate_parameters(starting, x, y, z[, ...])

Estimate the parameters by minimizing the objective function.

fit(*[, starting, display, cov_type, ...])

Estimate model parameters.

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

Create a model from a formula.

j(params, x, y, z)

Optimization target.

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.