linearmodels.iv.model.IV2SLS.fit

IV2SLS.fit(*, cov_type: str = 'robust', debiased: bool = False, **cov_config: Any) → OLSResults | IVResults

Estimate model parameters.

Parameters:
cov_type: str = 'robust'

Name of covariance estimator to use. The default is “robust”. The names are not case sensitive. Supported covariance estimators are:

  • ”unadjusted”, “homoskedastic”, “homo”, “homoskedasticcovariance” - Classic homoskedastic inference

  • ”robust”, “heteroskedastic”, “hccm”, “heteroskedasticcovariance” - Heteroskedasticity robust inference

  • ”kernel”, “kernelcovariance” - Heteroskedasticity and autocorrelation robust inference

  • ”clustered”, “one-way”, “onewayclusteredcovariance” - Cluster dependent inference, which is heteroskedasticity robust. It is one-way unless clusters has two columns.

debiased: bool = False

Flag indicating whether to debias the covariance estimator using a degree of freedom adjustment. The default is False.

**cov_config: Any

Additional parameters to pass to the covariance estimator. The keys that are used depend on cov_type. “unadjusted” and “robust” do not use any. “kernel” uses kernel (str), the name of the kernel, which is “bartlett” if it is not provided, and bandwidth (int), which is selected from the data if it is not provided. The names of the kernels are not case sensitive. “clustered” uses clusters (array_like), the cluster assignment of each observation, with one or two columns. Every covariance estimator accepts extra_df (int), the number of degrees of freedom that the model uses in addition to its regressors. It is 0 if it is not provided, and it is only used if debiased is True, when the covariance is scaled by n / (n - k - extra_df), where k is the number of regressors. The keys center and kappa are accepted and ignored: kappa is set by the model. See HomoskedasticCovariance, HeteroskedasticCovariance, KernelCovariance and ClusteredCovariance for the details.

Returns:

Results container. It is an OLSResults if the model has no endogenous regressors and no instruments.

Return type:

linearmodels.iv.results.IVResults or linearmodels.iv.results.OLSResults

Raises:
  • ValueError – If kappa is None, so that it is estimated, as in IVLIML by default, and the estimate of \(\kappa\) is not defined. That occurs if there are fewer than 1 + the number of endogenous regressors observations more than the number of exogenous regressors and instruments, or the residuals of the dependent variable and the endogenous regressors on the exogenous regressors and instruments are collinear. See the notes of IVLIML. It is also raised if the labels of clusters do not match the labels of the other inputs. A key of cov_config that the covariance estimator that cov_type selects does not accept also raises it. The message names the key and lists the accepted keys. This is checked before the model is estimated. Releases before 7.1 raised the TypeError of the constructor of the covariance estimator.

  • UnknownOptionError – If cov_type or kernel is not supported. It is both a KeyError and a ValueError.

Notes

Additional covariance parameters depend on specific covariance used. See the docstring of the specific covariance estimator for a list of supported options. Defaults are used if no covariance configuration is provided.