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
TypeErrorthat 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
UserWarningis 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, anddebiased(bool), whether to use small-sample adjustments. Both are False by default. “kernel” also acceptskernel(str), the name of the kernel, which is “bartlett” if it is not provided,bandwidth(float), andoptimal_bw(bool). The names of the kernels are not case sensitive. SeeHomoskedasticWeightMatrix,HeteroskedasticWeightMatrixandKernelWeightMatrixfor the details.
- Raises:¶
UnknownOptionError – If
weight_typeis not supported orkernelis not a supported kernel. It is both aKeyErrorand aValueError.
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_typeselects the estimator: “unadjusted” (“homoskedastic”), “robust” (“heteroskedastic”) or “kernel” ("hac"), andweight_configcontains its options. These arecenteranddebiasedfor all of them, andkernel,bandwidthandoptimal_bwfor “kernel”.The bandwidth of a kernel weight matrix (
weight_type="kernel") isbandwidthif it is given inweight_config, andnobs - 2ifoptimal_bwisFalse. Otherwise, which is the default and whatoptimal_bw=Truedoes, 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.fitraises aValueErrorfor fewer observations, and if the estimated bandwidth is not finite. Passbandwidthto use the kernel with fewer observations. Seekernel_optimal_bandwidth(). In 7.0 and earlier the default wasnobs - 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.fitissues aDefaultBandwidthWarning(aUserWarning) when it uses the default. To restore the previous behavior, passoptimal_bw=Falseorbandwidth=nobs - 2, wherenobsis the number of observations of each equation, inweight_config, for exampleIVSystemGMM(equations, weight_type="kernel", optimal_bw=False). Passingbandwidthoroptimal_bwsilences the warning, andoptimal_bw=Trueselects the bandwidth from the data without it. The kernel covariance of the parameters (cov_type="kernel"infit) is not affected, since it has always estimated its bandwidth from the data unlessbandwidthis given. SeeKernelWeightMatrix.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
ValueErroris raised if an index differs. Either reindex the input to the index of the dependent variable, or callto_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 orderexog,endog,instrumentsandweightsof each equation. Dates and time deltas are compared by value, so that the same dates at different resolutions, e.g.,datetime64[us]anddatetime64[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.
Remove all model constraints.
Properties
Model constraints.
Set or get the formula used to construct the model.
Vector indicating which equations contain constants.
Model parameter names.