Tutorials › Causal Inference › End-to-End Two-Stage Least Squares Workshop

Linear IV Estimation · Tutorial 536 of 972

End-to-End Two-Stage Least Squares Workshop

Work through a complete two-stage least squares analysis, from specifying the instrument and models to calculating and reporting a robust confidence interval.

Intermediate 10 min read

What You'll Learn

  • Specify the outcome, endogenous treatment, instrument, and causal assumptions for a simple IV analysis.
  • Calculate first-stage and reduced-form estimates from a binary instrument.
  • Obtain the just-identified 2SLS coefficient as a ratio of those estimates.
  • Calculate an HC0 robust standard error and use it for asymptotic inference.
  • Report the estimate with its units, uncertainty, and a clear limitation.

From a Dataset to an IV Result

An instrumental-variables analysis is not just a final coefficient. A reader needs to see how the outcome, endogenous treatment, instrument, and model fit together; how the first stage and reduced form lead to 2SLS; and how uncertainty is calculated. This workshop follows that sequence using a small, hypothetical observational dataset.

Suppose researchers are interested in the effect of tutoring hours on a test score. Students who receive more tutoring may differ in motivation or prior preparation, so a regression of scores on tutoring hours need not identify a causal effect. The proposed instrument is an invitation to a tutoring program. An invitation may change the number of tutoring hours received, but a causal interpretation also requires that it affect scores only through tutoring and be unrelated to other causes of scores.

Model and assumptions: Let \(Y_i\) be student \(i\)'s test score in points, \(D_i\) the student's tutoring hours, and \(Z_i\) an indicator equal to 1 if the student received an invitation and 0 otherwise. In this example, the structural equation is \(Y_i=\beta_0+\beta_1D_i+u_i\), and the first-stage equation is \(D_i=\pi_0+\pi_1Z_i+v_i\). The IV interpretation requires relevance (\(\pi_1\ne 0\)), instrument exogeneity (\(Z_i\) is uncorrelated with the structural error, or the corresponding conditional moment holds when covariates are included), and exclusion (the invitation affects the score only through tutoring hours). A causal interpretation also presumes a well-defined treatment and outcome and no interference between students. The constant-effect interpretation in this model requires that one tutoring hour has the same effect for all students.

Because these are observational data, those assumptions need a substantive defense; a regression table cannot establish them. In particular, a strong association between invitation and tutoring does not show that invitation is independent of unmeasured causes of test scores or that it has no direct effect. The example uses no additional covariates, so the assumptions are stated without conditioning on \(X_i\). In an analysis with covariates, the same choices about outcome, endogenous regressor, instruments, and controls must be made consistently in the first and second stages.

The Hypothetical Data and Model Checks

The eight students below are hypothetical. Tutoring hours are the endogenous treatment, the invitation is the instrument, and the score is the outcome.

StudentInvitation \(Z_i\)Tutoring hours \(D_i\)Test score \(Y_i\) (points)
A0110
B0212
C0313
D0415
E1313
F1415
G1517
H1619

Worked Example: Estimate the First Stage and Reduced Form

For a binary instrument and an intercept, the slope in a regression on \(Z_i\) is the difference in group means, the mean for invited students minus the mean for non-invited students. The first stage regresses \(D_i\) on \(Z_i\). The reduced form regresses \(Y_i\) on \(Z_i\).

For the first stage, the mean tutoring hours among students with \(Z_i=0\) are \((1+2+3+4)/4=2.5\). Among students with \(Z_i=1\), they are \((3+4+5+6)/4=4.5\). Thus the fitted first-stage equation is:

$$ \widehat{D}_i=2.5+2.0Z_i. $$

The estimated first-stage slope is \(4.5-2.5=2.0\) hours: in this dataset, invited students average 2.0 more tutoring hours. This describes the observed instrument-treatment association; it does not, by itself, establish instrument validity.

For the reduced form, the score means are \((10+12+13+15)/4=12.5\) points for \(Z_i=0\), and \((13+15+17+19)/4=16.0\) points for \(Z_i=1\). The fitted reduced-form equation is:

$$ \widehat{Y}_i=12.5+3.5Z_i. $$

The estimated reduced-form slope is \(16.0-12.5=3.5\) points. It is the invitation-score association, not yet the effect of an additional tutoring hour.

From the Two Regressions to 2SLS

With one endogenous treatment and one excluded instrument, the model is just identified: there is one excluded instrument for the one endogenous regressor. In this simple setting, the 2SLS slope equals the reduced-form slope divided by the first-stage slope. Equivalently, the first stage supplies fitted treatment values, and the second stage regresses the outcome on those fitted values and an intercept.

Just-identified 2SLS result: With an intercept, a single binary instrument \(Z_i\), and a nonzero first-stage slope, the 2SLS treatment coefficient is the ratio of the outcome-on-instrument slope to the treatment-on-instrument slope: $$ \widehat{\beta}_1^{\,2SLS}=\frac{\widehat{\tau}_{RF}}{\widehat{\pi}_1}. $$ Here \(\widehat{\tau}_{RF}\) denotes the reduced-form slope and \(\widehat{\pi}_1\) the first-stage slope.

Worked Example: Calculate the 2SLS Estimate

The first-stage fitted tutoring hours are 2.5 for each student with \(Z_i=0\) and 4.5 for each student with \(Z_i=1\). The second-stage slope is therefore the difference in mean scores divided by the difference in fitted tutoring hours. Substituting the estimates from the two regressions gives:

$$ \widehat{\beta}_1^{\,2SLS} =\frac{16.0-12.5}{4.5-2.5} =\frac{3.5}{2.0} =1.75. $$

The second-stage intercept is \(12.5-(1.75)(2.5)=8.125\), so the fitted second-stage equation is \(\widehat{Y}_i=8.125+1.75\widehat{D}_i\). Under the stated constant-effect and instrument-validity assumptions, the slope is an estimated increase of 1.75 test-score points per additional tutoring hour. Without those assumptions, the calculation is an IV estimate but its causal interpretation is not established.

The second-stage regressor is fitted tutoring hours, not the observed tutoring hours. This distinction matters for estimation and especially for uncertainty: an ordinary least-squares standard error from a regression on fitted treatment does not account for the first-stage estimation. Inference must use a 2SLS variance estimator.

Heteroskedasticity-Robust Inference

A heteroskedasticity-robust 2SLS covariance estimator allows the structural error variance to differ across observations. In matrix notation, let \(X\) contain the intercept and observed endogenous regressor, let \(Z\) contain the intercept and excluded instrument, and define \(P_Z=Z(Z'Z)^{-1}Z'\). If \(\hat{u}_i=Y_i-X_i'\widehat{\beta}^{\,2SLS}\), the HC0 sandwich estimator is:

$$ \widehat{\mathrm{Var}}_{HC0}(\widehat{\beta}^{\,2SLS}) =(X'P_ZX)^{-1}X'Z(Z'Z)^{-1} \left(\sum_{i=1}^{n}Z_iZ_i'\hat{u}_i^2\right) (Z'Z)^{-1}Z'X(X'P_ZX)^{-1}. $$

Here \(Z_i\) in the matrix expression is the vector of instruments for observation \(i\), including the intercept. HC0 uses the squared 2SLS residuals and does not apply a finite-sample degrees-of-freedom correction. Robustness concerns the form of the error variance; it does not repair an invalid instrument, omitted model structure, or a weak first stage.

For the binary-instrument example, the slope component of this sandwich estimator has a particularly transparent form. Write \(\bar{D}_1-\bar{D}_0\) for the observed difference in mean treatment and let \(\hat{u}_i\) be the 2SLS residual. Since the instrument moments make residuals sum to zero within each instrument group, the HC0 variance for the slope is:

$$ \widehat{\mathrm{Var}}_{HC0}(\widehat{\beta}_1^{\,2SLS}) = \frac{ \displaystyle\sum_{Z_i=1}\hat{u}_i^2/n_1^2+ \displaystyle\sum_{Z_i=0}\hat{u}_i^2/n_0^2 }{ (\bar{D}_1-\bar{D}_0)^2 }. $$

Worked Example: Compute the Robust Standard Error and Interval

Use the 2SLS equation \(\widehat{Y}_i=8.125+1.75D_i\) to calculate the structural residuals. In the \(Z_i=0\) group, the fitted scores based on observed tutoring hours are 9.875, 11.625, 13.375, and 15.125 points. Subtracting these from the observed scores gives residuals \(0.125, 0.375, -0.375, -0.125\). Their squared sum is:

$$ 0.125^2+0.375^2+(-0.375)^2+(-0.125)^2=0.3125. $$

For the \(Z_i=1\) group, fitted scores are 13.375, 15.125, 16.875, and 18.625 points. The residuals are \(-0.375, -0.125, 0.125, 0.375\), whose squared sum is also 0.3125. There are four students in each group, and the difference in mean tutoring hours is 2.0 hours. Therefore:

$$ \widehat{\mathrm{Var}}_{HC0}(\widehat{\beta}_1^{\,2SLS}) =\frac{0.3125/4^2+0.3125/4^2}{2.0^2} =0.009766, \qquad SE_{HC0}=\sqrt{0.009766}=0.09882. $$

Using a standard normal approximation, the test statistic for \(H_0:\beta_1=0\) is \(z=1.75/0.09882=17.71\), giving a two-sided \(p\)-value below 0.001. The 95% Wald confidence interval is:

$$ 1.75\pm1.96(0.09882)=[1.556,\ 1.944]\text{ test-score points per tutoring hour}. $$

Under the model and IV assumptions, this interval is an asymptotic confidence interval for the constant causal effect: its endpoints describe effects in test-score points per additional tutoring hour. The procedure does not assign a 95% probability to the fixed parameter being in this particular interval. With only eight observations, the normal approximation may be poor; the calculation is a transparent illustration, not a recommendation to rely on asymptotic inference in such a small study.

Reporting the Analysis

A compact table can show how the instrument is associated with treatment and outcome and how those estimates produce the 2SLS result. Label each quantity, give units, and identify the standard-error method. The table below reports the estimates from the hypothetical data; the confidence interval is the asymptotic HC0 Wald interval calculated above.

QuantityEstimateUncertainty or interpretation
First-stage slope2.000 hoursMean tutoring-hour difference by invitation
Reduced-form slope3.500 pointsMean score difference by invitation
2SLS treatment coefficient1.750 points per hourHC0 SE = 0.09882; 95% interval [1.556, 1.944]

Worked Example: Write a Concise Result

A concise report could read: “In the hypothetical sample, the invitation was associated with 2.00 additional tutoring hours and a 3.50-point higher test score. The just-identified 2SLS estimate was 1.75 test-score points per tutoring hour (HC0 SE 0.0988; asymptotic 95% CI 1.56 to 1.94). A causal interpretation requires the invitation to be relevant, independent of unmeasured causes of scores, and to affect scores only through tutoring; the constant-effect interpretation also assumes a common effect across students.”

This wording separates observed instrument associations from the treatment effect interpretation and makes the assumptions visible. It also avoids implying that the robust standard error or narrow interval can verify instrument validity.

Common Mistakes and Practical Limits

  • Calling the reduced form the treatment effect. The reduced-form estimate is the score difference associated with invitation. In this just-identified model, the 2SLS estimate divides that difference by the first-stage treatment difference.
  • Using the ordinary second-stage standard error. Regressing the outcome on fitted treatment can reproduce the 2SLS point estimate, but its ordinary OLS standard error is not the 2SLS standard error. Use a 2SLS covariance estimator that accounts for the instrumented estimation.
  • Treating robust as synonymous with valid. HC0 permits heteroskedasticity in the structural errors. It does not establish exclusion or exogeneity and does not resolve weak identification.
  • Overstating the causal conclusion. The estimate is causal only under the IV assumptions and the stated effect model. If treatment effects vary, the constant-effect interpretation need not apply; the coefficient is not automatically the population average treatment effect.
  • Ignoring sample size. A computed standard error and p-value do not guarantee reliable finite-sample inference. This eight-person example is especially unsuitable for treating a normal approximation as definitive.
Key takeaway: A transparent 2SLS report connects a specified structural model to the first stage, reduced form, 2SLS estimate, and appropriate robust uncertainty calculation. The calculations answer how the estimate was obtained; the instrument assumptions determine whether it can be interpreted causally.

Check Your Understanding

Use the workshop's models and calculations to answer the following questions.

  1. What are the first-stage and reduced-form slopes in the hypothetical data, and what are their units?
  2. Show how dividing the reduced-form slope by the first-stage slope gives the 2SLS coefficient.
  3. Why is the 2SLS residual calculated using observed tutoring hours, even though the second stage uses fitted tutoring hours?
  4. What does the HC0 robust standard error allow, and which IV assumptions does it not establish?
  5. State the assumptions needed to interpret the reported 2SLS coefficient as a constant causal effect in this example.
Clinical Biostats