ARBIMETRA · Financial intelligence, made practical.

ARBIMETRA LAB

Instrumental Variables / 2SLS

Estimates a regression with endogenous regressors using instruments, with relevance, overidentification and endogeneity diagnostics.

What it does

Estimates a regression with endogenous regressors using instruments, with relevance, overidentification and endogeneity diagnostics.

Use it when a regressor is correlated with the error and a credible instrument exists.

Data you need

  • Dependent variable
  • Endogenous variable(s)
  • Instrument(s)

Optional: Exogenous controls

Supported data: Numeric. Level: Advanced.

Formula and method

β̂ = (X′PzX)⁻¹X′PzY, Pz = Z(Z′Z)⁻¹Z′

In the first stage each endogenous variable is projected on the instruments and controls. In the second, the outcome is regressed on those fitted values. Residuals use the actual regressors, so standard errors are not those of a naive second-stage OLS.

Assumptions

  • Instruments are relevant
  • Instruments are excluded from the outcome equation
  • Instruments are exogenous

Input checks

  • At least as many instruments as endogenous variables
  • Weak-instrument warning when first-stage F is below 10

Diagnostics included

First-stage F, Sargan overidentification, Durbin-Wu-Hausman.

How to read the result

Compare with OLS, and treat weak-instrument warnings seriously.

Worked example

Illustrative run on Simulated study data (teaching data). These figures are the actual output of this model on that example, and they say nothing about your own data.

  • training: 2SLS 1.9692 (s.e. 0.2479, p = <0.0001) against OLS 2.8755. Smallest first-stage F = 218.9771.
  • The 2SLS coefficient on training is statistically significant at the 5% level.

Limitations

  • A supplied instrument does not establish causal identification

Numerical validation

Validated 24 of 24 automated checks passed, including numerical results, invalid input, missing values, small samples, constant variables, charts and the interpretation text.

CheckReferenceResultAbs. errorToleranceSource
2SLS by matrix formula2.081707162.081707166.7e-151e-9Independent NumPy calculation
2SLS standard error0.0783790.0783799.7e-171e-9Independent NumPy calculation
2SLS against statsmodels IV2SLS2.081707162.081707160.0e+01e-9statsmodels IV2SLS
True coefficient is recovered22.081707168.2e-21e-1Known data-generating value
Sargan statistic7.527105217.527105215.3e-131e-9Independent NumPy calculation

Computed with python 3.13.2, numpy 2.2.5, scipy 1.14.1, pandas 2.3.3, statsmodels 0.14.4, scikit-learn 1.7.0, in your browser. A passing check confirms the listed comparison only. It does not make any result suitable for your data, and it is not a claim of equivalence with other statistical software.

Questions

Does passing the Sargan test prove my instruments are valid?

No. It can only detect some inconsistencies among instruments, and it needs at least one valid instrument to begin with.

ARBIMETRA LAB is an educational and research tool. Results should be checked by the researcher and are not professional advice.