linearmodels.system.model.IVSystemGMM

class linearmodels.system.model.IVSystemGMM(equations: Mapping[str, Mapping[str, ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None] | Sequence[ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None]], *, sigma: ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None = None, weight_type: str = 'robust', **weight_config: bool | str | float)[source]

System Generalized Method of Moments (GMM) estimation of linear IV models.

Parameters:
equations: Mapping[str, Mapping[str, ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None] | Sequence[ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...] | None]]

Dictionary-like structure containing dependent, exogenous, endogenous and instrumental variables. Each key is an equations label and must be a string. Each value must be either a tuple of the form (dependent, exog, endog, instrument[, weights]) or a dictionary with keys “dependent”, “exog”. The dictionary may contain optional keys for “endog”, “instruments”, and “weights”. Endogenous and/or Instrument can be empty if all variables in an equation are exogenous. The variables are array_like, such as lists, NumPy arrays, pandas objects and xarray DataArrays, and a TypeError that names the variable is raised for complex values or text.

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

Prespecified residual covariance to use in GLS estimation, with shape (nequations, nequations). If not provided, FGLS is implemented based on an estimate of sigma. Only used if weight_type is “unadjusted” or “homoskedastic”. A UserWarning is issued, and sigma is ignored, if it is provided with another weight type.

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” - Assume moments are homoskedastic

  • ”robust”, “heteroskedastic” - Allow for heteroskedasticity

  • ”kernel”, “hac” - Allow for heteroskedasticity and autocorrelation

**weight_config: bool | str | float

Additional keyword arguments to pass to the moment condition weight function. All weight types accept center (bool), whether to center the moment conditions, and debiased (bool), whether to use small-sample adjustments. Both are False by default. “kernel” also accepts kernel (str), the name of the kernel, which is “bartlett” if it is not provided, bandwidth (float), and optimal_bw (bool). The names of the kernels are not case sensitive. See HomoskedasticWeightMatrix, HeteroskedasticWeightMatrix and KernelWeightMatrix for the details.

Raises:

UnknownOptionError – If weight_type is not supported or kernel is not a supported kernel. It is both a KeyError and a ValueError.

Notes

Estimates a linear model using GMM. Each equation is of the form

\[y_{i,k} = x_{i,k}\beta_i + \epsilon_{i,k}\]

where k denotes the equation and i denoted the observation index. By stacking vertically arrays of dependent and placing the exogenous variables into a block diagonal array, the entire system can be compactly expressed as

\[Y = X\beta + \epsilon\]

where

\[\begin{split}Y = \left[\begin{array}{c}Y_1 \\ Y_2 \\ \vdots \\ Y_K\end{array}\right]\end{split}\]

and

\[\begin{split}X = \left[\begin{array}{cccc} X_1 & 0 & \ldots & 0 \\ 0 & X_2 & \dots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & X_K \end{array}\right]\end{split}\]

The system GMM estimator uses the moment condition

\[z_{ij}(y_{ij} - x_{ij}\beta_j) = 0\]

where j indexes the equation. The estimator for the coefficients is given by

\[\begin{split}\hat{\beta}_{GMM} & = (X'ZW^{-1}Z'X)^{-1}X'ZW^{-1}Z'Y \\\end{split}\]

where \(W\) is a positive definite weighting matrix.

The weight matrix is the inverse of an estimate of the covariance of the moment conditions. weight_type selects the estimator: “unadjusted” (“homoskedastic”), “robust” (“heteroskedastic”) or “kernel” ("hac"), and weight_config contains its options. These are center and debiased for all of them, and kernel, bandwidth and optimal_bw for “kernel”.

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, from the residuals that the weight matrix is computed from. These are the residuals of the first step estimates in two-step GMM, which is the default. A bandwidth that is estimated from the data, for the weight matrix or the covariance, 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 to use the kernel with fewer observations. See kernel_optimal_bandwidth(). In 7.0 and earlier the default was nobs - 2, which is not a consistent estimator of the covariance of the moment conditions, 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, where nobs is the number of observations of each equation, in weight_config, for example IVSystemGMM(equations, 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 kernel covariance of the parameters (cov_type="kernel" in fit) is not affected, since it has always estimated its bandwidth from the data unless bandwidth is given. See KernelWeightMatrix.

The weights of an equation, if they are given, must be strictly positive and finite. They are rescaled to have a mean of 1 in the equation. A NaN weight is missing, and its observation is dropped from all of the equations.

Rows are paired by position, both within an equation and across the equations. 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 the dependent variable of its equation, so that a value cannot be attached to the wrong observation. The dependent variables that carry labels must also use the same index in every equation. A ValueError is raised if an index differs. Either reindex the input to the index of the dependent variable, 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 none of the dependent variables carries labels, the inputs that do must use the same index as the first of them that does, in the order exog, endog, instruments and weights of each equation. 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

add_constraints(r[, q])

Add parameter constraints to a model.

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

Estimate model parameters.

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

Specify a system GMM model using the formula interface.

predict(params, *[, equations, data, eval_env])

Predict values for additional data.

reset_constraints()

Remove all model constraints.

Properties

constraints

Model constraints.

formula

Set or get the formula used to construct the model.

has_constant

Vector indicating which equations contain constants.

param_names

Model parameter names.