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 if weights are not strictly positive and finite.

  • TypeError – If an input is complex or cannot be converted to float64.

See also

linearmodels.iv.model.IVLIML

Limited information ML and k-class estimation of IV models.

linearmodels.iv.model.IVGMM

Estimation of IV models using the generalized method of moments.

linearmodels.iv.model.IVGMMCUE

Estimation 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 an InvalidTestStatistic.

Changed in version 7.1: The Anderson-Rubin and Basmann F tests are an InvalidTestStatistic if \(\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. A ValueError is raised if the index of exog, endog, instruments or weights differs from the index of dependent. Either reindex the input to the index of dependent, 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 dependent does not carry labels, the inputs that do must use the same index as the first of exog, endog, instruments and weights that does. The same rule applies to clusters passed to fit. 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.

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

Formula used to create the model.

has_constant

Flag indicating the model includes a constant or equivalent.

isnull

Locations of observations with missing values.

notnull

Locations of observations included in estimation.