Tutorials › Propensity Score Matching and Instrumental Variables › Weighted Two-Stage Least Squares

Two-Stage Least Squares · Tutorial 500 of 699

Weighted Two-Stage Least Squares

Learn to construct weighted 2SLS, interpret its projection and covariance formulas, and check when the weighting scheme supports the intended estimator.

Advanced 12 min read

What You'll Learn

  • Define weighted 2SLS using a diagonal matrix of positive observation weights.
  • Derive the weighted projection onto the instrument space and the resulting estimator.
  • Distinguish weighted homoskedastic covariance from heteroskedasticity-robust covariance.
  • Calculate a weighted 2SLS estimate and its robust standard error.
  • Diagnose invalid weighting, poor identification, and implementation errors.

Why Weight Both Stages?

In ordinary 2SLS, instruments project the regressors onto the instrument space, and the second stage uses those projected regressors. When observations have different weights, both operations must use the same weighted geometry. Weighting only the first stage or only the second does not generally produce weighted 2SLS.

Weights can represent different things: inverse error variances, sampling adjustments, or chosen emphasis in an objective function. Those interpretations are not interchangeable. The matrix calculation defines an estimator, but the reason for the weights and the assumptions that make them appropriate must be established separately.

Definition: Let \(y\) be an \(n \times 1\) outcome vector, \(X\) an \(n \times K\) regressor matrix, and \(Z\) an \(n \times L\) instrument matrix. The columns of \(X\) include the endogenous and included exogenous regressors; \(Z\) contains valid instruments, including the included exogenous regressors. Let \(W=\operatorname{diag}(w_1,\ldots,w_n)\), with \(w_i>0\). Weighted 2SLS minimizes the weighted distance between \(y\) and \(X\beta\) after projecting \(X\) onto the columns of \(Z\) using the \(W\)-weighted inner product. Assume \(Z'WZ\) and \(X'WZ(Z'WZ)^{-1}Z'WX\) are nonsingular.

The model is \(y=X\beta+u\). For consistency, a central condition is that the weighted instrument moments are valid: in a population formulation, \(E[w_i z_i u_i]=0\), where \(z_i\) is the instrument vector for observation \(i\). This follows, for example, if weights are fixed or suitably exogenous and \(E[z_i u_i]=0\) holds conditionally on the variables determining the weights. Ordinary instrument validity alone does not ensure validity after weighting if the weights depend on the structural error.

The Weighted Projection and Estimator

The weighted projection of any vector \(v\) onto the columns of \(Z\) is

$$ P_Z^W=Z(Z'WZ)^{-1}Z'W,\qquad \widehat{X}=P_Z^W X. $$

This projection minimizes \((v-Z\gamma)'W(v-Z\gamma)\) over \(\gamma\). It is idempotent, \(P_Z^W P_Z^W=P_Z^W\), but it is not generally symmetric in the ordinary Euclidean inner product. Instead, it is self-adjoint under the weighted inner product: \(W P_Z^W=(P_Z^W)'W\). Equivalently, premultiplying each row by \(\sqrt{w_i}\) turns the problem into ordinary projection using \(W^{1/2}Z\).

The second stage is a weighted least-squares regression of \(y\) on \(\widehat{X}\). Thus the estimator is

$$ \widehat{\beta}_{W,2SLS} =(X'W P_Z^W X)^{-1}X'W P_Z^W y =\left[X'WZ(Z'WZ)^{-1}Z'WX\right]^{-1} X'WZ(Z'WZ)^{-1}Z'Wy. $$

The rank conditions in the definition ensure these inverses exist. In a model with multiple endogenous regressors, the instruments must provide enough independent weighted variation to identify all coefficients; having a formally large instrument count does not by itself establish that rank condition.

Justification: Weighted least squares in the second stage minimizes \((y-\widehat{X}\beta)'W(y-\widehat{X}\beta)\). Its normal equation is \(\widehat{X}'W\widehat{X}\widehat{\beta}=\widehat{X}'Wy\). Since \(P_Z^W\) is idempotent and \(W\)-self-adjoint, \(\widehat{X}'W\widehat{X}=X'W P_Z^W X\) and \(\widehat{X}'Wy=X'W P_Z^W y\). Substituting the projection formula gives the displayed weighted 2SLS expression.

Worked Example: Calculating Weighted 2SLS

Consider a hypothetical model with one endogenous regressor \(x\), one instrument \(z\), and no intercept. The three observations are \((y,x,z)=(2,1,1),(5,3,2),(4,2,1)\), with weights \(1,2,1\). Assume for illustration that the weighted instrument moments are valid and that the model is identified. With one instrument and one regressor, the estimator reduces to \(z'Wy/(z'W x)\).

First calculate the weighted sums: \(z'Wz=1(1^2)+2(2^2)+1(1^2)=10\), \(z'W x=1(1)(1)+2(2)(3)+1(1)(2)=15\), and \(z'Wy=1(1)(2)+2(2)(5)+1(1)(4)=26\).

The weighted first-stage fitted values are \(\widehat{x}=z(z'Wz)^{-1}z'W x=1.5z\), or \((1.5,3,1.5)'\). Regressing \(y\) on these fitted values with weights gives \[ \widehat{\beta}_{W,2SLS} =\frac{\widehat{x}'Wy}{\widehat{x}'W\widehat{x}} =\frac{39}{22.5}=1.733. \] This equals \(z'Wy/(z'W x)=26/15=1.733\), as it must in this exactly identified, no-intercept example. The coefficient is in units of outcome per unit of \(x\). The stated validity and rank assumptions are premises of the illustration, not claims that three observations can verify them.

Weights and Covariance Calculations

Changing the weights changes not only the contribution of each observation to the outcome fit but also the projection of each regressor onto the instruments. Covariance calculations must reflect this change. Define

$$ D=(Z'WZ)^{-1},\qquad G=X'WZ D Z'W X. $$

With heteroskedastic errors, an observation-level sandwich estimate is

$$ \widehat{\operatorname{Var}}(\widehat{\beta}_{W,2SLS}) =G^{-1}X'WZ D \left(\sum_{i=1}^n w_i^2 z_i z_i'\widehat{u}_i^2\right) D Z'WXG^{-1}, \qquad \widehat{u}_i=y_i-x_i'\widehat{\beta}_{W,2SLS}. $$

The \(w_i^2\) in the middle is essential: the weighted moment contribution of observation \(i\) is \(w_i z_i\widehat{u}_i\), whose outer product includes \(w_i^2\). This formula is the observation-level heteroskedasticity-robust sandwich; dependence across observations requires a covariance estimator that accounts for that dependence, rather than this independent-observation form.

A simpler covariance expression applies under a specific variance model. If \(\operatorname{Var}(u\mid X,Z)=\sigma^2W^{-1}\), then the weighted-transformed errors \(W^{1/2}u\) have covariance \(\sigma^2 I\), and the covariance of weighted 2SLS is \(\sigma^2G^{-1}\). In contrast, merely assuming constant variance \(\operatorname{Var}(u\mid X,Z)=\sigma^2I\) while using arbitrary \(W\) does not generally yield \(\sigma^2G^{-1}\). In that case the middle covariance factor involves \(Z'W^2Z\), not \(Z'WZ\). The weights must match the variance assumption before using the simpler expression.

Worked Example: A Robust Standard Error in the Just-Identified Case

Continue the hypothetical three-observation example. The fitted coefficient is \(26/15\), so the structural residuals are \(2-26/15=4/15\), \(5-3(26/15)=-3/15\), and \(4-2(26/15)=8/15\). For a scalar coefficient and instrument, \(G=(z'W x)^2/(z'Wz)=225/10=22.5\), while \(X'WZ D=15/10=1.5\).

The robust moment “meat” is \(\sum_i w_i^2 z_i^2\widehat{u}_i^2 =16/225+144/225+64/225=224/225\). Therefore the estimated variance and standard error are \[ \widehat{\operatorname{Var}}(\widehat{\beta}_{W,2SLS}) =\left(\frac{1.5}{22.5}\right)^2\frac{224}{225} =0.004425,\qquad SE=\sqrt{0.004425}=0.0665. \] This arithmetic illustrates the sandwich calculation, not reliable small-sample inference: three observations provide very little basis for estimating variability, and no small-sample correction has been applied.

Worked Example: How Relative Weights Change the Estimate

For the same hypothetical observations, set all weights to one. Then \(z'y=2+10+4=16\) and \(z'x=1+6+2=9\), giving \(\widehat{\beta}_{2SLS}=16/9=1.778\). With weights \((1,2,1)\), the estimate was \(26/15=1.733\). Giving the second observation more weight changed both weighted sums and the estimate.

Multiplying every weight by the same positive constant would not change the coefficient: that constant cancels from the weighted projection and the estimator. Relative weights matter; the overall scale does not. This example does not show that either choice is preferable. That depends on the design, the target population or objective, and whether the weighted moment condition is credible.

Implementation, Diagnostics, and Alternatives

1
State what the weights mean.
Specify whether they are intended to reflect conditional error variances, sampling design, or another weighting target. Check that the weights are positive, finite, and compatible with the weighted moment condition.
2
Use one weighted projection.
Construct \(P_Z^W\) from \(Z'WZ\), and project every column of \(X\) using that same matrix. The instrument set must include the included exogenous regressors as required by the model.
3
Use weights again in the second stage.
Regress \(y\) on the projected regressors by weighted least squares. Ordinary least squares on fitted regressors is not the weighted second stage.
4
Choose covariance assumptions separately.
Use a covariance estimator appropriate to the error variance and dependence structure. A weighting choice alone does not establish homoskedasticity or independence.

A practical check is to compare a direct weighted 2SLS calculation with a two-stage implementation using the same \(W\) at both stages. They should agree up to numerical rounding. Also inspect the range and concentration of weights, the conditioning of \(Z'WZ\) and \(G\), and whether estimates are driven by a few heavily weighted observations. A numerically invertible matrix can still be poorly conditioned, producing unstable estimates.

Weighted 2SLS is not the only approach. Unweighted 2SLS uses the same instrument logic with \(W=I\). Generalized method of moments can use a different weighting matrix for instrument moments; it is not the same operation as multiplying observations by a diagonal \(W\). If weights are inverse conditional error variances, weighted 2SLS can improve efficiency under the stated variance model. If weights are sampling weights, the target and variance calculation must reflect the sampling design. Neither kind of weighting repairs invalid instruments or insufficient identification.

Common Pitfalls and Limits

  • Weighting only one stage. Projecting with \(W\) and then running unweighted least squares does not implement the estimator defined here. Use weighted least squares in both stages.
  • Using an ordinary projection. The matrix \(Z(Z'Z)^{-1}Z'\) ignores unequal observation weights. The weighted projection uses \(Z'WZ\) and \(Z'W\).
  • Assuming weights guarantee valid instruments. If weights are related to the structural error, \(E[w_i z_i u_i]=0\) may fail even when an unweighted moment condition holds.
  • Using the wrong covariance formula. The simple \(\sigma^2G^{-1}\) form requires \(\operatorname{Var}(u\mid X,Z)=\sigma^2W^{-1}\). Arbitrary weights and constant error variance call for a different covariance calculation.

As with other 2SLS procedures, estimates may be unstable when instruments provide little relevant variation. Extreme weights can make the effective information depend heavily on a small subset of observations, and standard errors may then be sensitive to modeling and variance assumptions. Weighted 2SLS also does not by itself establish that the weighted population is the desired target.

Check Your Understanding

Answer each question, then compare your reasoning with the brief solutions.

  1. What is the weighted projection matrix, and why is it not generally symmetric?
  2. If every observation weight is multiplied by 5, does the weighted 2SLS coefficient change? Explain.
  3. In the worked data, what estimate results when all weights equal one?
  4. When is the covariance expression \(\sigma^2G^{-1}\) justified?
  5. Why can ordinary instrument validity fail to guarantee validity after applying observation weights?

Solutions. (1) \(P_Z^W=Z(Z'WZ)^{-1}Z'W\); it is generally not Euclidean-symmetric, though it is self-adjoint in the \(W\)-weighted inner product. (2) No. A common positive multiplier cancels from the projection and estimator. (3) \(z'y/z'x=16/9=1.778\). (4) Under \(\operatorname{Var}(u\mid X,Z)=\sigma^2W^{-1}\), with the stated rank conditions. (5) Weighting changes the moment to \(E[w_i z_i u_i]\), which need not be zero if weights depend on variables related to the error.

Clinical Biostats