linearmodels.iv.model.IV2SLS¶
-
class linearmodels.iv.model.IV2SLS(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)[source]¶ Estimation of IV models using two-stage least squares.
- 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.
- 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.TypeError – If an input is complex or cannot be converted to float64.
See also
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.
linearmodels.iv.model.IVGMMCUEEstimation of IV models using continuously updating GMM.
Notes
The 2SLS estimator is defined
\[\begin{split}\hat{\beta}_{2SLS} & =(X'Z(Z'Z)^{-1}Z'X)^{-1}X'Z(Z'Z)^{-1}Z'Y\\ & =(\hat{X}'\hat{X})^{-1}\hat{X}'Y\\ \hat{X} & =Z(Z'Z)^{-1}Z'X\end{split}\]The 2SLS estimator is a special case of a k-class estimator with \(\kappa=1\),
The estimates do not use the estimate of \(\kappa\) of LIML, but the Anderson-Rubin and Basmann F tests of overidentification of the results do. The estimate of \(\kappa\) is not defined if there are fewer than \(1 + n_{endog}\) observations more than the number of exogenous regressors and instruments, or if the residuals of the dependent variable and the endogenous regressors on the exogenous regressors and instruments are collinear (see
IVLIML). The model is estimated then, and the tests are anInvalidTestStatistic.Changed in version 7.1: The Anderson-Rubin and Basmann F tests are an
InvalidTestStatisticif \(\kappa\) is not defined. Earlier versions computed them from the rounding error of a singular matrix, or the statistics were NaN.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 tofit. 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.Todo
VCV: bootstrap
Methods
estimate_parameters(x, y, z, kappa)Parameter estimation without error checking.
fit(*[, cov_type, debiased])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.