IV_REGRESSION

Estimate a single-equation instrumental-variables model with two-stage least squares (2SLS).

Syntax

IV_REGRESSION(Y, X, LIST(Z1, Z2, ...))

IV_REGRESSION(LIST(Y, X1, X2, ...), LIST(Z1, Z2, ...))
ArgumentDescription
Y The dependent or outcome series.
X, X1... One or more regressors treated as endogenous.
LIST(Z1,Z2,...) The excluded instruments. At least as many instruments as endogenous regressors are required.

RainbowStats aligns the outcome, endogenous regressors, and instruments to their common date range before estimation.

Model

For one endogenous regressor, the two stages are:

First stage: X = α + Zπ + v
Structural equation: Y = c + βX + u

The 2SLS estimator is calculated as:

β̂IV = (X′PZX)−1X′PZY

The instrument projection matrix is PZ = Z(Z′Z)−1Z′. A constant is included.

Example pattern

Data=SAME_DATE_RANGE(LIST(Y,X,Z1,Z2))
IV=IV_REGRESSION(Y,X,LIST(Z1,Z2))
SLIDESHOW(IV)

Beta=EXTRACT(IV,"beta")
SE=EXTRACT(IV,"se")
TStat=EXTRACT(IV,"tstat")
FirstStageF=EXTRACT(IV,"first_stage_f")

Replace Y, X, and the instruments with series appropriate to the research design. This is a syntax pattern, not an endorsement of any particular instrument.

Multiple endogenous regressors

IV=IV_REGRESSION(LIST(Y,X1,X2),LIST(Z1,Z2,Z3))
SLIDESHOW(IV)

BetaX1=EXTRACT(IV,"beta:1")
BetaX2=EXTRACT(IV,"beta:2")
FX1=EXTRACT(IV,"first_stage_f:1")
FX2=EXTRACT(IV,"first_stage_f:2")

Coefficient index 0 is the intercept. Coefficients 1 onward correspond to the endogenous regressors in their listed order. First-stage numbering begins at 1.

Available extracts

ExtractReturns
firststageThe first-stage regression for the first endogenous regressor.
firststage:nFirst-stage regression number n, using 1-based numbering.
secondstageThe displayed second-stage regression using fitted endogenous values.
betaThe IV coefficient for the first endogenous regressor.
beta:nCoefficient n; beta:0 is the intercept.
se or se:nConventional homoskedastic 2SLS standard error.
tstat or tstat:nIV coefficient divided by its reported standard error.
first_stage_fExcluded-instrument F statistic for the first endogenous regressor.
first_stage_f:nExcluded-instrument F statistic for endogenous regressor n.
slideshowFirst-stage panels followed by the second-stage presentation.

Required analytical checks

  1. Explain endogeneity. State why ordinary regression may be biased.
  2. Defend relevance. Show why each instrument predicts the endogenous regressor.
  3. Defend exclusion. Explain why each instrument has no direct path to the outcome.
  4. Inspect every first stage. Report the excluded-instrument F statistic and the sample used.
  5. Disclose instrument selection. Report candidates tried, not only those retained.
  6. Check sensitivity. Compare credible specifications and investigate unstable signs or magnitudes.
  7. Interpret the estimand carefully. IV may identify a local effect for observations affected by the instrument, not a universal average effect.

What the command does not establish

Best use

Use IV_REGRESSION when the instrument comes from a clearly articulated design—such as a defensible policy rule, institutional assignment mechanism, natural experiment, or other source of plausibly exogenous variation—and when that design is explained before the regression results are examined.

Related commands