Tutorials › Causal Inference › Heteroskedasticity-Robust 2SLS Standard Errors

Linear IV Estimation · Tutorial 527 of 972

Heteroskedasticity-Robust 2SLS Standard Errors

Construct and interpret robust 2SLS standard errors, and see why they can differ from homoskedastic standard errors even when the 2SLS coefficient is unchanged.

Intermediate 10 min read

What You'll Learn

  • State the linear IV model and assumptions needed for heteroskedasticity-robust 2SLS variance estimation
  • Write the sandwich variance estimator using instruments, regressors, and 2SLS residuals
  • Explain why independent observations can have different error variances without invalidating the robust estimator
  • Compare robust and homoskedastic standard errors in a just-identified numerical example
  • Calculate a robust standard error with multiple instruments
  • Recognize why robust standard errors do not repair invalid instruments or dependent observations

Why 2SLS Needs a Robust Variance Estimate

Two-stage least squares (2SLS) estimates a structural relationship using variation in regressors predicted by instruments. Its coefficient estimate does not require the outcome error to have the same variance for every observation. But the usual homoskedastic variance formula does make that assumption. If the error variance differs across observations, that formula can misstate the sampling uncertainty of the 2SLS estimate.

The heteroskedasticity-robust variance estimator replaces the common error variance with a sum of observation-level contributions. Each contribution combines that observation’s squared 2SLS residual with its instrument values. The resulting estimator is often called a sandwich estimator because it has a middle “meat” matrix between two “bread” matrices.

Model and Assumptions

Let \(y\) be an \(n \times 1\) vector of outcomes, \(X\) an \(n \times K\) matrix of structural regressors, and \(Z\) an \(n \times L\) matrix of instruments, where \(L \geq K\). The structural model is

$$ y = X\beta + u. $$

Here \(\beta\) is the \(K \times 1\) coefficient vector and \(u\) is the \(n \times 1\) error vector. The rows of \(X\) and \(Z\) are \(x_i'\) and \(z_i'\). The regressors may include endogenous variables; any included exogenous regressors should also be included among the instruments. Assume that \(Z\) has full column rank and that \(X'P_ZX\) is invertible, where

$$ P_Z = Z(Z'Z)^{-1}Z'. $$

The 2SLS estimator is

$$ \hat{\beta}_{2SLS} = (X'P_ZX)^{-1}X'P_Zy. $$

For the robust variance estimator to be justified, the instruments must satisfy the relevant exogeneity moments, such as \(E[z_i u_i]=0\), and provide enough identifying variation for the coefficient vector. The observations are assumed independent, with suitable finite moments and a stable, nonsingular identification structure. Their error variances need not be equal: conditional on the instruments and regressors, \(\operatorname{Var}(u_i\mid Z,X)\) may differ from one observation to another. Independence matters here; allowing unequal variances is not the same as allowing arbitrary dependence across observations.

Definition: The heteroskedasticity-robust 2SLS variance estimator uses the 2SLS residuals to estimate the contribution of each observation to sampling variability, without imposing a common error variance. Its standard error for a coefficient is the square root of the corresponding diagonal entry of the estimated variance matrix.

The Sandwich Formula

Let \(\hat u=y-X\hat{\beta}_{2SLS}\), with \(i\)th residual \(\hat u_i\). A common heteroskedasticity-robust estimator, often called the HC0 form, is

$$ \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta}_{2SLS}) = (X'P_ZX)^{-1} X'Z(Z'Z)^{-1} \left(\sum_{i=1}^{n} z_i z_i'\hat u_i^2\right) (Z'Z)^{-1}Z'X (X'P_ZX)^{-1}. $$

The middle matrix is the estimated “meat.” It sums the outer product \(z_i z_i'\) for each observation, weighted by that observation’s squared residual. The two surrounding parts are the “bread.” Because this is a matrix, its diagonal entries estimate the variances of the coefficient estimates, while its off-diagonal entries estimate their covariances.

The 2SLS estimating equation gives a short justification for this form. Substituting \(y=X\beta+u\) into the estimator yields

$$ \hat{\beta}_{2SLS}-\beta = (X'P_ZX)^{-1}X'Z(Z'Z)^{-1}Z'u. $$

With \(X\) and \(Z\) treated as fixed, the middle random quantity is a linear combination of the errors. If the errors are independent but have different conditional variances, then

$$ \operatorname{Var}(Z'u\mid X,Z) = \sum_{i=1}^{n} z_i z_i'\operatorname{Var}(u_i\mid X,Z). $$

Premultiplying and postmultiplying this expression by the coefficient matrices in the equation for \(\hat{\beta}_{2SLS}-\beta\) gives the sandwich structure. Replacing the unknown error variances by squared residuals gives the displayed estimator. Under the stated regularity conditions, this estimates the sampling variance consistently as the sample grows; it is not generally an exactly unbiased finite-sample variance estimate.

Connection to the Homoskedastic Formula

If the errors instead have a common conditional variance, \(\operatorname{Var}(u_i\mid X,Z)=\sigma^2\), then the middle population quantity is \(\sigma^2 Z'Z\). Substitution into the sandwich expression reduces it to

$$ \operatorname{Var}(\hat{\beta}_{2SLS}\mid X,Z) = \sigma^2(X'P_ZX)^{-1}. $$

This is the homoskedastic 2SLS variance formula. Its usual estimated version replaces \(\sigma^2\) with a residual variance estimate, commonly \(\hat{\sigma}^2=\hat u'\hat u/(n-K)\). The robust formula does not make that common-variance substitution: it retains the observation-specific squared residuals inside the meat. Even if the two estimators happen to be similar in a particular sample, they rely on different variance assumptions.

Worked Example: Comparing Robust and Homoskedastic Standard Errors

Consider a hypothetical just-identified model with one regressor and one instrument, with no intercept. The observations are shown below. For this calculation, assume the instrument is valid and the identification conditions hold; the table alone cannot establish those assumptions.

Observation\(z_i\)\(x_i\)\(y_i\)
1-112
2-121
3135
4146

In this scalar just-identified case, the 2SLS estimate is \(\hat{\beta}_{2SLS}=\sum_i z_i y_i/\sum_i z_i x_i\). Substituting the data gives

$$ \hat{\beta}_{2SLS} = \frac{(-1)(2)+(-1)(1)+(1)(5)+(1)(6)} {(-1)(1)+(-1)(2)+(1)(3)+(1)(4)} = \frac{8}{4} = 2. $$

The residuals are \(\hat u_i=y_i-2x_i\), which gives \(0,-3,-1,-2\). The robust variance in this scalar case is

$$ \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta}_{2SLS}) = \frac{\sum_i z_i^2\hat u_i^2}{(\sum_i z_i x_i)^2} = \frac{0^2+(-3)^2+(-1)^2+(-2)^2}{4^2} = \frac{14}{16} = 0.875. $$

Thus the robust standard error is \(\sqrt{0.875}=0.9354\) outcome units per unit of \(x\). For comparison, the residual sum of squares is \(14\), so the conventional homoskedastic residual variance estimate is \(14/(4-1)=4.667\). Also, \(X'P_ZX=(\sum_i z_i x_i)^2/\sum_i z_i^2=16/4=4\). The homoskedastic variance estimate and standard error are therefore

$$ \widehat{\operatorname{Var}}_{\mathrm{homo}}(\hat{\beta}_{2SLS}) = 4.667\left(\frac{1}{4}\right) = 1.167, \qquad SE_{\mathrm{homo}} = \sqrt{1.167} = 1.080. $$

The robust and homoskedastic estimates differ because they weight the observed residuals differently. The robust calculation uses each \(z_i^2\hat u_i^2\), rather than summarizing all residual sizes with a single variance estimate. The difference in this small hypothetical sample does not establish which assumption is appropriate in an application.

Worked Example: Robust Variance With Multiple Instruments

Now consider a hypothetical model with one regressor, no intercept, and two instruments. The instrument rows are \(z_i'=(1,1),(1,-1),(-1,1),(-1,-1)\). Let \(x=(1,2,3,4)'\) and \(y=(3,4,6,8)'\). The instruments are orthogonal in this sample, so \(Z'Z=4I\), where \(I\) is the \(2 \times 2\) identity matrix. The relevant cross-product and projected-regressor quantities are

$$ X'Z=(-4,-2), \qquad X'P_ZX = X'Z(Z'Z)^{-1}Z'X = \frac{(-4)^2+(-2)^2}{4} = 5. $$

The outcome cross-product is \(Z'y=(-7,-3)'\). Hence

$$ \hat{\beta}_{2SLS} = 5^{-1}(-4,-2)\frac{1}{4} \begin{pmatrix}-7\\-3\end{pmatrix} = \frac{8.5}{5} = 1.7. $$

The residuals \(y_i-1.7x_i\) are \(1,0.6,0.9,1.2\). The bread on one side of the scalar sandwich is

$$ (X'P_ZX)^{-1}X'Z(Z'Z)^{-1} = \frac{1}{5}(-4,-2)\frac{1}{4}I = (-0.2,-0.1). $$

The meat is

$$ \sum_i z_i z_i'\hat u_i^2 = \begin{pmatrix} 3.61 & 1.27\\ 1.27 & 3.61 \end{pmatrix}. $$

For example, its first diagonal entry is \(1^2+0.6^2+0.9^2+1.2^2=3.61\); its off-diagonal entry is \(1^2-(0.6)^2-(0.9)^2+(1.2)^2=1.27\), with signs determined by the paired instrument values. Therefore,

$$ \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta}_{2SLS}) = (-0.2,-0.1) \begin{pmatrix} 3.61 & 1.27\\ 1.27 & 3.61 \end{pmatrix} \begin{pmatrix}-0.2\\-0.1\end{pmatrix} = 0.2313, \qquad SE_{\mathrm{rob}}=\sqrt{0.2313}=0.4809. $$

The matrix calculation accounts for both instruments and their covariance contribution in the meat. It does not require that the two instruments be treated as separate coefficient estimates.

Worked Example: Unequal Instrument Values in a Scalar Calculation

A final hypothetical example illustrates why instrument values affect the robust variance. Again use a scalar model with no intercept, now with \(z=(1,2,1,2)'\), \(x=(1,2,2,3)'\), and \(y=(2,5,3,8)'\). The estimate is

$$ \hat{\beta}_{2SLS} = \frac{\sum_i z_i y_i}{\sum_i z_i x_i} = \frac{31}{13} = 2.385. $$

The residuals, using the unrounded estimate \(31/13\), are \((-5,3,-23,11)'/13\). The robust variance is

$$ \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta}_{2SLS}) = \frac{\sum_i z_i^2\hat u_i^2}{(\sum_i z_i x_i)^2} = \frac{1074/169}{13^2} = \frac{1074}{28561} = 0.03760, $$

so \(SE_{\mathrm{rob}}=\sqrt{0.03760}=0.1939\). For the homoskedastic comparison, the residual sum of squares is \(684/169\), giving \(\hat{\sigma}^2=(684/169)/3=228/169\). Since \(\sum_i z_i^2=10\), the estimated homoskedastic variance and standard error are

$$ \widehat{\operatorname{Var}}_{\mathrm{homo}}(\hat{\beta}_{2SLS}) = \frac{228}{169}\frac{10}{13^2} = \frac{2280}{28561} = 0.07983, \qquad SE_{\mathrm{homo}}=0.2825. $$

Both calculations use the same 2SLS coefficient, \(2.385\). Their standard errors differ because the robust calculation preserves the association between each squared residual and that observation’s squared instrument value.

What Robust Standard Errors Do—and Do Not—Address

A heteroskedasticity-robust 2SLS standard error is appropriate when independent observations may have unequal error variances and the IV model’s identification and exogeneity conditions are credible. It describes estimated sampling variability under those conditions; it does not validate the instruments. In particular, changing the variance estimator cannot make an instrument exogenous or create identifying information that is absent.

The formula above also relies on independence across observations. If observations are dependent within groups, treating them as independent can still give an inappropriate standard error. Robustness to unequal individual variances should not be confused with robustness to such dependence.

A frequent mistake is to run the second stage using fitted values and then report the ordinary OLS standard error from that regression. The fitted regressor does not make the ordinary second-stage OLS variance formula appropriate for 2SLS. For this tutorial’s focus, the relevant calculation is the 2SLS sandwich: use the original instrument matrix, the structural residuals \(y-X\hat{\beta}_{2SLS}\), and the full bread matrices. A standard error is not chosen by looking at which one is smaller or more convenient; its assumptions must match the sampling structure and model.

Key takeaway: The robust 2SLS sandwich replaces a single residual variance with the instrument-weighted sum \(\sum_i z_i z_i'\hat u_i^2\). It accommodates heteroskedasticity under independent sampling, but it does not repair invalid instruments or account for dependence between observations.

Check Your Understanding

Use the formulas and distinctions in this tutorial to answer the following questions.

  1. In the sandwich formula, what information does the meat matrix contain, and why is it observation-specific?
  2. Which error-variance assumption leads to the homoskedastic formula \(\sigma^2(X'P_ZX)^{-1}\)?
  3. In a just-identified scalar model, how would you compute the robust variance from \(z_i\), \(x_i\), and the 2SLS residuals?
  4. Why can the robust and homoskedastic standard errors differ even though the 2SLS coefficient estimate is the same?
  5. Does using heteroskedasticity-robust standard errors establish that the instruments are valid? Explain.
Clinical Biostats