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) 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.IVGMMEstimation 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
centerweight option should beTrueto avoid starting value dependence. It isTrueunlesscenteris passed inweight_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
centerisTrue. IfcenterisFalseand 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") isbandwidthif it is given inweight_config, andnobs - 2ifoptimal_bwisFalse. Otherwise, which is the default and whatoptimal_bw=Truedoes, it is estimated from the data, as the bandwidth of the kernel covariance ofIV2SLSandIVLIMLis. It is estimated once, from the residuals of the first step estimates (the two-stage least squares estimates, which are also the first step ofIVGMM), 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 inweight_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.fitissues aDefaultBandwidthWarning(aUserWarning) when it uses the default. To restore the previous behavior, passoptimal_bw=Falseorbandwidth=nobs - 2inweight_config, for exampleIVGMMCUE(dependent, exog, endog, instruments, weight_type="kernel", optimal_bw=False). Passingbandwidthoroptimal_bwsilences the warning. The same holds forcov_type="kernel"infit, whose bandwidth is estimated from the residuals of the final estimates. Before 7.1,optimal_bw=Trueestimated the bandwidth of the objective function at every evaluation and usednobs - 2for the starting values, so its estimates change slightly. 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.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 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.