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) anddebiased(bool) for every weight function,kernel(str),bandwidth(int) andoptimal_bw(bool) for “kernel”, andclusters(array_like) for “clustered”. The names of the kernels are not case sensitive.clustersis required and has one element for each observation. SeeHomoskedasticWeightMatrix,HeteroskedasticWeightMatrix,KernelWeightMatrixandOneWayClusteredWeightMatrixfor 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 ifweightsare not strictly positive and finite.UnknownOptionError – If
weight_typeis not supported, or if it is “kernel” andkernelis not a supported kernel. It is both aKeyErrorand aValueError. Before 7.1, an unsupportedkernelwas reported byfit.TypeError – If an input is complex or cannot be converted to float64.
See also
linearmodels.iv.model.IV2SLSEstimation of IV models using two-stage least squares.
linearmodels.iv.model.IVLIMLLimited information ML and k-class estimation of IV models.
linearmodels.iv.model.IVGMMCUEEstimation 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") isbandwidthif it is given inweight_config. If neitherbandwidthnoroptimal_bwis given, it is estimated from the data, as the bandwidth of the kernel covariance ofIV2SLSandIVLIMLis. In 7.0 and earlier it wasnobs - 2, which is not a consistent estimator, 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 - 2inweight_config, for exampleIVGMM(dependent, exog, endog, instruments, weight_type="kernel", optimal_bw=False). Passingbandwidthoroptimal_bwsilences the warning, andoptimal_bw=Trueselects the bandwidth from the data without it. The same holds forcov_type="kernel"infit. SeeKernelWeightMatrixandIVGMMCovariance.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.
fitraises aValueErrorfor fewer observations, and if the estimated bandwidth is not finite. Passbandwidthoroptimal_bw=Falseto use the kernel with fewer observations. Seekernel_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. AValueErroris raised if the index ofexog,endog,instrumentsorweightsdiffers from the index ofdependent. Either reindex the input to the index ofdependent, 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. Ifdependentdoes not carry labels, the inputs that do must use the same index as the first ofexog,endog,instrumentsandweightsthat does. The same rule applies toclusterspassed tofitor inweight_config. 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.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 (
centerisTrue), 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 ofcenter. The rank of a kernel or robust estimate is bounded in the same way by the number of observations.fitraises aValueErrorthat 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, ifiter_limitis 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 used to create the model.
Flag indicating the model includes a constant or equivalent.
Locations of observations with missing values.
Locations of observations included in estimation.