Tutorials › Propensity Score Matching and Instrumental Variables › A Worked Cross-Sectional 2SLS Analysis

Two-Stage Least Squares · Tutorial 507 of 699

A Worked Cross-Sectional 2SLS Analysis

Learn to carry out and check a cross-sectional 2SLS analysis, including the correct robust covariance calculation and a context-specific interpretation.

Advanced 12 min read

What You'll Learn

  • Specify a structural equation and its corresponding instrument set for cross-sectional 2SLS.
  • Calculate a 2SLS estimate using instrument and regressor matrices.
  • Compute HC0 robust standard errors using structural residuals and the instrument-coordinate “meat.”
  • Test a coefficient and construct an asymptotic confidence interval.
  • Compare the IV estimate with OLS and identify assumptions and diagnostics that affect interpretation.

From a Structural Question to a 2SLS Estimate

A cross-sectional 2SLS analysis is not just a regression with a first-stage prediction substituted for an observed regressor. It is an analysis of a specified structural relationship, using instruments to isolate variation in an endogenous regressor and then estimating uncertainty with the 2SLS covariance formula. The steps connect: a different structural model or instrument set changes the estimate, while an incorrect standard error can make the final inference misleading.

Suppose an outcome \(y_i\) is related to an endogenous regressor \(x_i\) and a vector of observed controls \(w_i\). A common linear structural model is

$$ y_i=\beta_0+\beta_1x_i+w_i'\gamma+u_i. $$

Here \(u_i\) contains unobserved causes of \(y_i\), and \(x_i\) is endogenous when it is correlated with \(u_i\). Let \(z_i\) be a vector of excluded instruments. The instrument vector includes the intercept, the excluded instruments, and the included exogenous controls. In matrix notation, let \(Q\) contain the structural regressors (including the intercept, \(x\), and \(w\)), and let \(A\) contain the instruments. The controls in \(w\) instrument themselves.

Definition: Two-stage least squares (2SLS) estimates the structural coefficient vector using the part of the regressors projected onto the instrument space. With \(P_A=A(A'A)^{-1}A'\), the estimator is $$ \hat\beta=(Q'P_AQ)^{-1}Q'P_Ay. $$ It requires the relevant matrices to have full rank. In particular, the instruments must provide enough independent variation to identify the endogenous regressors after accounting for included exogenous regressors.

For a causal interpretation, the instrument set must also be substantively credible. The excluded instruments must be associated with the endogenous regressor (relevance), be independent of the structural error (instrument exogeneity), and affect the outcome only through the endogenous regressor, conditional on the included controls (the exclusion restriction). Cross-sectional robust inference additionally relies on independent observational units and appropriate moment conditions; heteroskedasticity-robust standard errors allow the error variance to differ across units. These conditions are assumptions about the design and population, not facts established by calculating a 2SLS coefficient.

Worked Example: Estimate 2SLS From a Small Cross-Section

Worked Example: Estimate 2SLS From a Small Cross-Section

Consider eight hypothetical individuals. Let \(y\) be a health score, \(x\) be treatment exposure in hours, and \(z\) be an indicator for access to an encouragement, with \(z=1\) for access and \(z=0\) otherwise. For this illustration, use an intercept and \(z\) as instruments for the intercept and \(x\). The table records the data.

Individual\(z\)\(x\) (hours)\(y\) (score)
1014
2024
3026
4036
5138
6148
71410
81510

For compactness, write \(Q=[\mathbf{1},x]\) and \(A=[\mathbf{1},z]\). The structural equation is \(y_i=\beta_0+\beta_1x_i+u_i\). The sample has four observations in each instrument group, so

$$ A'A= \begin{pmatrix} 8&4\\ 4&4 \end{pmatrix}, \qquad A'Q= \begin{pmatrix} 8&24\\ 4&16 \end{pmatrix}, \qquad A'y= \begin{pmatrix} 56\\ 36 \end{pmatrix}. $$

The determinant of \(A'Q\) is \(8(16)-24(4)=32\), so it is invertible. This just-identified example has a full-rank instrument-to-regressor relationship. Its 2SLS estimate can be calculated as \((A'Q)^{-1}A'y\):

$$ \hat\beta = \frac{1}{32} \begin{pmatrix} 16&-24\\ -4&8 \end{pmatrix} \begin{pmatrix} 56\\ 36 \end{pmatrix} = \begin{pmatrix} 1\\ 2 \end{pmatrix}. $$

Thus the estimated intercept is 1 score point and the 2SLS slope is 2 score points per hour of exposure. This is an estimate from the specified model, not proof that the encouragement satisfies exclusion or exogeneity in a population. The sample group means of \(x\), 2 hours for \(z=0\) and 4 hours for \(z=1\), show a difference in exposure across instrument groups, but a substantive relevance assessment also considers uncertainty and the study design.

Robust Standard Errors: Use the 2SLS Sandwich

For heteroskedasticity-robust inference, use residuals from the structural equation, \(\hat u_i=y_i-Q_i'\hat\beta\), in the 2SLS sandwich. The HC0 covariance estimator is

$$ \widehat{\mathrm{Var}}_{\mathrm{HC0}}(\hat\beta) = (Q'P_AQ)^{-1}Q'A(A'A)^{-1} \left(\sum_{i=1}^n A_iA_i'\hat u_i^2\right) (A'A)^{-1}A'Q(Q'P_AQ)^{-1}. $$

The middle sum is the robust “meat,” expressed in instrument coordinates. It is not generally \(Q'P_AQ\). That distinction matters even when the final covariance calculation is simple.

Worked Example: Calculate the HC0 Standard Error

Continue with the hypothetical data. The fitted structural residuals are \(1,-1,1,-1,1,-1,1,-1\), so every \(\hat u_i^2=1\). Since \(A_i=(1,z_i)'\), the HC0 meat is

$$ \sum_i A_iA_i'\hat u_i^2 =A'A = \begin{pmatrix} 8&4\\ 4&4 \end{pmatrix}. $$

The projected-regressor cross-product is

$$ Q'P_AQ=(A'Q)'(A'A)^{-1}(A'Q) = \begin{pmatrix} 8&24\\ 24&80 \end{pmatrix}, \qquad (Q'P_AQ)^{-1} = \begin{pmatrix} 1.25&-0.375\\ -0.375&0.125 \end{pmatrix}. $$

Substitute the correct meat into the sandwich. Because the example is just identified and the meat equals \(A'A\), the middle factors simplify:

$$ \begin{aligned} \widehat{\mathrm{Var}}_{\mathrm{HC0}}(\hat\beta) &=(Q'P_AQ)^{-1}(Q'P_AQ)(Q'P_AQ)^{-1}\\ &=(Q'P_AQ)^{-1}\\ &= \begin{pmatrix} 1.25&-0.375\\ -0.375&0.125 \end{pmatrix}. \end{aligned} $$

The robust standard error for the slope is therefore \(\sqrt{0.125}=0.3536\) score points per hour. The equality of this covariance matrix and \((Q'P_AQ)^{-1}\) follows here from the just-identified design and the residual squares; it is not a general shortcut for robust 2SLS.

The derivation also explains why a standard OLS standard error from a regression of \(y\) on first-stage fitted values is not generally the correct 2SLS standard error. The robust sandwich must account for the instrument-based estimator and use structural residuals; treating fitted regressors as if they had been directly observed omits relevant uncertainty.

Worked Example: Test and Interpret the Slope

Worked Example: Test and Interpret the Slope

Use the estimate \(\hat\beta_1=2\) and its HC0 standard error \(\sqrt{0.125}\). For \(H_0:\beta_1=0\) against \(H_a:\beta_1\ne0\), the asymptotic robust Wald statistic is

$$ z=\frac{\hat\beta_1-0}{SE(\hat\beta_1)} =\frac{2}{\sqrt{0.125}} =5.656854\approx5.657. $$

Under the null and the usual large-sample approximation, this statistic is compared with a standard normal distribution. Its two-sided p-value is approximately \(1.54\times10^{-8}\). At a significance level of \(0.05\), the result is inconsistent with the null value of zero under that approximation. It does not give the probability that the null is true, nor does it establish the instrument assumptions.

A 95% asymptotic confidence interval is

$$ 2\pm1.96\sqrt{0.125} =2\pm0.69296 =[1.307,\ 2.693]. $$

In context, the interval is an estimate of the structural change in the health score per additional hour of exposure, under the model and instrument assumptions. Its repeated-sampling interpretation is that the interval procedure would cover the true coefficient in 95% of samples under those assumptions and the approximation used. With only eight observations, the asymptotic approximation is especially fragile; the arithmetic illustrates the procedure rather than supporting a dependable real-world conclusion.

Check the Model, Then Compare Alternatives

A numerical result is useful only after checking that the analysis matches the question and design. Confirm that the outcome, endogenous regressor, controls, and instruments are coded as intended, and that the instrument set has sufficient rank. Examine whether the instrument has meaningful variation and is related to the endogenous regressor after accounting for controls. The formal strength diagnostics are a separate topic; a visible first-stage difference alone is not an adequate guarantee against weak identification. Also consider whether observations can reasonably be treated as independent. If the data have group or time dependence, cross-sectional HC0 errors may not provide the appropriate inference.

The central example makes the distinction between OLS and IV concrete. Its OLS slope is

$$ \hat\beta_{1,\mathrm{OLS}} =\frac{\sum_i(x_i-\bar{x})(y_i-\bar{y})}{\sum_i(x_i-\bar{x})^2} =\frac{20}{12} =1.667. $$

The OLS estimate differs from the 2SLS estimate of 2. This difference alone does not show that either estimate is correct: OLS requires its own exogeneity condition, while 2SLS requires valid and relevant instruments. When regressors are exogenous, OLS can be more precise; when an endogenous regressor is present and the instruments are valid, 2SLS targets the structural coefficient using instrument-induced variation. Neither method repairs omitted-variable bias or a misspecified structural equation automatically.

Common warning signs include a first stage with little conditional association, instruments whose assignment may be related to unobserved outcome causes, omitted controls that undermine the intended conditional comparison, and influential observations that dominate the estimate. Robust standard errors address heteroskedasticity in the specified cross-sectional sampling framework; they do not correct invalid instruments, weak identification, dependence between observations, or an incorrect model. The earlier material on heteroskedasticity-robust 2SLS inference develops the covariance logic; clustered or serially dependent data require inference suited to that dependence structure.

Common pitfall: “I regressed the outcome on the first-stage fitted values, so the usual second-stage standard error is valid.” This treats estimated fitted values as observed regressors and generally understates or otherwise misstates uncertainty. Use the 2SLS covariance sandwich, with structural residuals and the instrument-coordinate meat \(\sum_i A_iA_i'\hat u_i^2\).

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. In a model with an intercept, one endogenous regressor, and one exogenous control, what belongs in the instrument matrix?
  2. Why is the HC0 meat in the worked example \(A'A\), rather than \(Q'P_AQ\)?
  3. Using the worked slope and unrounded standard error, calculate the robust Wald statistic to three decimals.
  4. Does a significant 2SLS Wald test establish that the instrument satisfies the exclusion restriction?
  5. In what units should the slope and its standard error be reported if the outcome is measured in points and exposure in hours?

Solutions. (1) The instrument matrix contains the intercept, the excluded instrument or instruments, and the included exogenous control; the control instruments itself. (2) Each squared residual is 1, so the meat is \(\sum_i A_iA_i'=A'A=\begin{pmatrix}8&4\\4&4\end{pmatrix}\), which is in instrument coordinates. (3) \(2/\sqrt{0.125}=5.656854\), which rounds to 5.657. (4) No. A coefficient test addresses a hypothesis about the coefficient under the model and inference assumptions; it does not verify instrument validity. (5) Both are in health-score points per hour of exposure.

Clinical Biostats