Tutorials › Propensity Score Matching and Instrumental Variables › HAC Standard Errors for 2SLS

Two-Stage Least Squares · Tutorial 494 of 699

HAC Standard Errors for 2SLS

Learn to build and interpret a HAC sandwich covariance for 2SLS, including the instrument-score sequence, kernel weights, bandwidth choices, and key diagnostics.

Advanced 12 min read

What You'll Learn

  • Define the instrument-residual score sequence used in HAC 2SLS inference.
  • Construct a long-run covariance estimate from contemporaneous and lagged score cross-products.
  • Assemble the HAC covariance matrix using the 2SLS sandwich formula.
  • Understand how kernel weights and bandwidth affect the estimated standard errors.
  • Diagnose sensitivity to bandwidth, ordering, and weak or invalid instruments.
  • Distinguish HAC inference from heteroskedasticity-robust and cluster-robust inference.

Why 2SLS Needs HAC Standard Errors

When observations have a meaningful order—such as consecutive time periods—errors or other features of the data may be dependent across nearby observations. Heteroskedasticity-robust 2SLS inference allows the error variance to differ across observations, but it does not account for serial dependence. HAC (heteroskedasticity-and-autocorrelation-consistent) covariance estimates extend the 2SLS sandwich to account for both unequal variances and dependence across the ordered observations.

The essential object is not the residual sequence alone. It is the sequence of instrument-residual scores. HAC estimation measures how those scores co-vary at different lags, then maps their long-run covariance into the coefficient covariance using the 2SLS bread. The ordering, lag weights, and bandwidth are therefore part of the estimator, not cosmetic settings.

Model, Scores, and Assumptions

For ordered observations \(t=1,\ldots,n\), write the linear structural equation as \(y_t=x_t'\beta+u_t\). Here \(y_t\) is the outcome, \(x_t\) is a \(p\)-vector of regressors that may include endogenous variables and exogenous controls, \(\beta\) is the \(p\)-vector of coefficients, and \(u_t\) is the structural error. Let \(z_t\) be a \(k\)-vector of instruments, including any required exogenous regressors. Assume \(k\ge p\), and that the instruments identify the coefficients.

Definition: The IV score at observation \(t\) is \(g_t=z_tu_t\), a \(k\)-vector. Its sample counterpart is \(\hat g_t=z_t\hat u_t\), where \(\hat u_t=y_t-x_t'\hat\beta\) uses the 2SLS estimate. A HAC estimate first estimates the long-run covariance of this ordered score sequence, then sandwiches that estimate with the 2SLS mapping from instrument moments to coefficients.

The standard conditions include instrument validity, \(E[z_tu_t]=0\), and identification: the population matrix \(Q_{XZ}=E[x_tz_t']\) has sufficient rank for the 2SLS coefficient vector to be identified. For the usual HAC approximation, the score sequence must also have suitable weak-dependence and moment properties, and its long-run covariance must be finite. Stationarity is a common sufficient framework, though other asymptotic frameworks can be used. These conditions justify a central limit approximation for sums of scores; they do not require independent or homoskedastic errors.

HAC does not repair a violation of instrument validity or identification. Nor does it make an invalid time ordering meaningful: observations must be arranged according to the dependence being modeled. In particular, validity of each instrument for its own observation does not automatically establish all assumptions needed in a specific time-series IV design.

Building the HAC 2SLS Covariance

Define the sample moment matrices and the 2SLS bread as

$$ Q_{XZ}=\frac{1}{n}\sum_{t=1}^n x_tz_t', \qquad Q_{ZZ}=\frac{1}{n}\sum_{t=1}^n z_tz_t', \qquad Q_{ZX}=Q_{XZ}', \qquad G=Q_{XZ}Q_{ZZ}^{-1}Q_{ZX}. $$

Assuming the required inverses exist, define \(H=G^{-1}Q_{XZ}Q_{ZZ}^{-1}\). The 2SLS estimation error can be written as \(H\) times the sample average of the instrument-residual scores. In population notation, the corresponding first-order representation is \(\hat\beta-\beta\approx H(n^{-1}\sum_t g_t)\). Thus the long-run covariance of the scores determines the coefficient covariance.

For lag \(\ell\ge0\), estimate score cross-products by

$$ \hat\Gamma_\ell = \frac{1}{n} \sum_{t=\ell+1}^{n} \hat g_t\hat g_{t-\ell}'. $$

Choose a maximum lag \(L\) and weights \(w_\ell\) from a kernel. The Bartlett, or Newey–West, weights are \(w_\ell=1-\ell/(L+1)\) for \(1\le\ell\le L\). The estimated long-run covariance is

$$ \hat\Omega = \hat\Gamma_0+ \sum_{\ell=1}^{L}w_\ell \left(\hat\Gamma_\ell+\hat\Gamma_\ell'\right). $$

The transpose is essential: \(\hat\Gamma_\ell\) records covariance in one lag direction, and adding its transpose accounts for the reverse direction and makes the result symmetric. The resulting HAC covariance estimate for 2SLS is

$$ \widehat{\operatorname{Var}}_{\mathrm{HAC}}(\hat\beta) = \frac{1}{n}H\hat\Omega H' = \frac{1}{n} G^{-1}Q_{XZ}Q_{ZZ}^{-1} \hat\Omega Q_{ZZ}^{-1}Q_{ZX}G^{-1}. $$

The standard error for coefficient \(j\) is the square root of the \(j\)th diagonal element of this matrix. Units follow the corresponding coefficient: for example, if an outcome is measured in days and a regressor in dollars, the coefficient and its standard error are measured in days per dollar.

Why the Score Sandwich Is Appropriate

The justification follows directly from the 2SLS normal equations. Substituting \(y_t=x_t'\beta+u_t\) into the estimator gives the sample error as the bread times the average instrument-error product:

$$ \hat\beta-\beta = G^{-1}Q_{XZ}Q_{ZZ}^{-1} \left(\frac{1}{n}\sum_{t=1}^n z_tu_t\right). $$

Under the moment, rank, and dependence conditions, the normalized sum of scores has an asymptotic covariance given by their long-run covariance \(\Omega\), which includes contemporaneous variation and all lagged cross-covariances. Therefore,

$$ \operatorname{Avar}(\hat\beta) = \frac{1}{n}H\Omega H'. $$

Replacing unknown quantities by sample estimates and truncating the lag sum with kernel weights yields the HAC estimator above. For consistency of a standard kernel estimate, the maximum lag typically grows with sample size but more slowly than \(n\), so that \(L\to\infty\) and \(L/n\to0\), along with regularity conditions on dependence and moments. In a finite sample, software often uses a fixed or data-selected bandwidth; that choice is an approximation, and sensitivity to it should be assessed.

Worked Example: A Scalar HAC 2SLS Standard Error

Suppose a hypothetical ordered sample has \(n=100\), one coefficient and one instrument. The estimated scalar quantities are \(Q_{XZ}=0.5\) and \(Q_{ZZ}=1\). Suppose the score cross-products give \(\hat\Gamma_0=0.0600\), \(\hat\Gamma_1=0.0200\), and \(\hat\Gamma_2=-0.00500\), and use Bartlett weights with \(L=2\). These are hypothetical summaries of the ordered data, not results from a real study.

First, \(G=Q_{XZ}Q_{ZZ}^{-1}Q_{ZX}=0.5(1)^{-1}(0.5)=0.25\), so \(H=G^{-1}Q_{XZ}Q_{ZZ}^{-1}=(0.25)^{-1}(0.5)(1)=2\). The weights are \(w_1=1-1/3=2/3\) and \(w_2=1-2/3=1/3\). Therefore,

$$ \hat\Omega = 0.0600+ 2\left[\left(\frac{2}{3}\right)(0.0200) +\left(\frac{1}{3}\right)(-0.00500)\right] =0.08333. $$

The HAC variance and standard error are

$$ \widehat{\operatorname{Var}}_{\mathrm{HAC}}(\hat\beta) = \frac{1}{100}(2)(0.08333)(2) =0.003333, \qquad SE_{\mathrm{HAC}}(\hat\beta)=\sqrt{0.003333}=0.05774. $$

The coefficient's standard error is 0.05774 in the coefficient's units. This calculation illustrates why the instrument score and the 2SLS bread both matter: using the score long-run variance alone would omit the factor \(H\) on each side.

Worked Example: How Bandwidth Changes the Estimate

Keep the hypothetical score cross-products from the previous example, but compare three bandwidths. With \(L=0\), there are no lag terms, so \(\hat\Omega=0.0600\). With \(L=1\), \(w_1=1/2\), giving \(\hat\Omega=0.0600+2(0.5)(0.0200)=0.0800\). With \(L=2\), the calculation above gives \(\hat\Omega=0.08333\).

Since \(n=100\) and \(H=2\), the variance is \(4\hat\Omega/100\). The resulting standard errors are \(\sqrt{0.002400}=0.04899\) for \(L=0\), \(\sqrt{0.003200}=0.05657\) for \(L=1\), and \(\sqrt{0.003333}=0.05774\) for \(L=2\). In this example, including positive lag-one score dependence increases the estimated standard error; the negative lag-two cross-product offsets a small part of that increase.

A larger bandwidth does not necessarily produce a larger standard error: lagged cross-products may be negative, and their weighted contributions can lower the estimate. The comparison is a sensitivity check, not a rule for selecting the bandwidth by whichever value gives a preferred inference.

Worked Example: A Two-Coefficient HAC Covariance

Consider a hypothetical model with \(n=200\), two coefficients, and two instruments. Suppose the sample matrices are \(Q_{ZZ}=I\) and \(Q_{XZ}=\operatorname{diag}(1,0.5)\), where \(I\) is the \(2\times2\) identity matrix. Then \(G=\operatorname{diag}(1,0.25)\) and \(H=\operatorname{diag}(1,2)\). Suppose the estimated score long-run covariance is

$$ \hat\Omega= \begin{pmatrix} 0.0400 & 0.0100\\ 0.0100 & 0.0900 \end{pmatrix}. $$

The sandwich middle multiplication is

$$ H\hat\Omega H' = \begin{pmatrix} 1&0\\0&2 \end{pmatrix} \begin{pmatrix} 0.0400&0.0100\\0.0100&0.0900 \end{pmatrix} \begin{pmatrix} 1&0\\0&2 \end{pmatrix} = \begin{pmatrix} 0.0400&0.0200\\0.0200&0.3600 \end{pmatrix}. $$

Dividing by \(n=200\) gives estimated variances 0.0002000 and 0.001800, covariance 0.0001000, and standard errors \(\sqrt{0.0002000}=0.01414\) and \(\sqrt{0.001800}=0.04243\). The off-diagonal covariance is retained in the full matrix, even though individual coefficient standard errors use only its diagonal.

Choosing a Bandwidth and Checking the Result

The bandwidth controls how many lagged score relationships contribute and how strongly they contribute. A bandwidth that is too short can omit meaningful dependence, leaving standard errors understated or otherwise distorted. A bandwidth that is too long can add noisy estimates of distant-lag covariances, making inference unstable in a limited sample. Bartlett weights taper contributions toward zero at the cutoff; other standard kernels use different weighting profiles, but the same score-sandwich logic applies.

Useful diagnostics and checks include:

  • Verify the order. Confirm that adjacent rows really are adjacent in the process of interest. Arbitrarily sorting observations changes the lag products.
  • Inspect score dependence. Examine the ordered score sequence or its lagged cross-products. Residual autocorrelation alone does not completely describe dependence in \(z_t\hat u_t\).
  • Compare plausible bandwidths. Report whether standard errors and substantive conclusions are sensitive to reasonable bandwidth choices, rather than treating one choice as definitive.
  • Check matrix behavior. A covariance estimate should be symmetric, and its diagonal entries should be nonnegative up to numerical precision. Unexpected behavior can indicate coding, scaling, or implementation problems.
  • Assess identification separately. HAC standard errors do not solve weak-instrument problems. A seemingly ordinary standard error is not proof that the instruments provide strong identifying information.

HAC inference is also not a substitute for cluster-robust inference when dependence is primarily within a known set of clusters. HAC typically models dependence by distance in an ordered sequence; cluster-robust covariance allows arbitrary within-cluster dependence under its own asymptotic framework. The heteroskedasticity-robust 2SLS covariance is the corresponding no-cross-observation-covariance alternative. These methods answer different dependence questions, so the design—not which option produces the smallest standard error—should guide the choice.

Common Mistakes and Limitations

  • Using \(x_t\hat u_t\) as the IV score by default. The moment conditions for IV use \(z_tu_t\). The instrument-score sequence must be propagated through the 2SLS mapping \(H\); an ordinary OLS score does not generally give the 2SLS covariance.
  • Ignoring the transpose term. For each positive lag, include both \(\hat\Gamma_\ell\) and \(\hat\Gamma_\ell'\). Omitting one direction can yield an asymmetric covariance estimate.
  • Treating the bandwidth as a harmless setting. The lag cutoff changes the estimated long-run covariance and can materially change standard errors, especially in shorter samples.
  • Assuming HAC makes the instruments valid. HAC changes the covariance estimate, not the identifying moment condition \(E[z_tu_t]=0\).
  • Confusing robust with exact. The usual HAC result is an asymptotic approximation. Its reliability depends on sample size, dependence, moments, bandwidth, and identification strength.

The main practical limitation is that long-run covariance estimation itself can be noisy. No kernel or bandwidth can recover reliable information that the sample does not contain, and an estimated HAC covariance does not address model misspecification or invalid instruments. Interpret results alongside the IV design, identification evidence, and bandwidth sensitivity.

Key takeaway: For HAC 2SLS, form the ordered scores \(\hat g_t=z_t\hat u_t\), estimate their long-run covariance with weighted lagged cross-products, and sandwich that estimate with the 2SLS mapping. The bandwidth and ordering are substantive parts of the inference.

Check Your Understanding

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

  1. What is the HAC score for observation \(t\) in an IV model, and why is it not generally \(x_t\hat u_t\)?
  2. With Bartlett weights and \(L=3\), what are \(w_1\), \(w_2\), and \(w_3\)?
  3. If \(n=50\), \(H=1.5\), and \(\hat\Omega=0.0400\) in a scalar example, calculate the HAC variance and standard error.
  4. What does changing the bandwidth change, and why should several plausible choices sometimes be compared?
  5. Does a HAC covariance estimate establish that the instruments are valid? Explain.

Solutions. (1) The score is \(\hat g_t=z_t\hat u_t\), because the IV moment conditions are based on instruments multiplied by structural errors; \(x_t\hat u_t\) is not generally the relevant moment score. (2) The weights are \(3/4\), \(1/2\), and \(1/4\). (3) The variance is \((1/50)(1.5)(0.0400)(1.5)=0.001800\), so the standard error is \(\sqrt{0.001800}=0.04243\). (4) Bandwidth changes the number and weights of lagged score cross-products included. Comparing plausible choices reveals whether inference is sensitive to the truncation of dependence. (5) No. HAC estimates uncertainty under a dependence structure; instrument validity remains a separate identifying assumption.

Clinical Biostats