Lecture 9: Large-sample properties of OLS and robust standard errors
Economics 527: Econometric Methods
Consistency of OLS
OLS in terms of sample averages
Regression, \{(Y_i, X_i) : i = 1, \ldots, n\} iid: Y_i = X_i^\top \beta + U_i, \qquad X_i \in \mathbb{R}^k
OLS, \operatorname{rank}\left(X\right) = k: \begin{aligned} \hat\beta_n &= (X^\top X)^{-1} X^\top Y \\ &= \beta + \Big(\frac{1}{n} \sum_{i=1}^n X_i X_i^\top\Big)^{-1} \frac{1}{n} \sum_{i=1}^n X_i U_i \end{aligned}
LLN for \frac{1}{n} \sum X_i U_i
Assume: \mathrm{E}\left[X_i U_i\right] = 0
X_1 U_1, \ldots, X_n U_n: iid; weak LLN, element by element: \frac{1}{n} \sum_{i=1}^n X_i U_i \to_p \mathrm{E}\left[X_i U_i\right] = 0
LLN for \frac{1}{n} \sum X_i X_i^\top
Cauchy-Schwarz, element (r, s): \mathrm{E}\left[|X_{i,r} X_{i,s}|\right] \le \sqrt{\mathrm{E}\left[X_{i,r}^2\right]\, \mathrm{E}\left[X_{i,s}^2\right]} < \infty
Assume: \mathrm{E}\left[X_i X_i^\top\right] p.d.
Weak LLN and Slutsky for the inverse: \begin{aligned} \frac{1}{n} \sum_{i=1}^n X_i X_i^\top &\to_p \mathrm{E}\left[X_i X_i^\top\right] \\ \Big(\frac{1}{n} \sum_{i=1}^n X_i X_i^\top\Big)^{-1} &\to_p \big(\mathrm{E}\left[X_i X_i^\top\right]\big)^{-1} \end{aligned}
Assumptions
Assumptions for consistency: \begin{aligned} & \{(Y_i, X_i) : i = 1, \ldots, n\} \ \text{ iid} \\ & Y_i = X_i^\top \beta + U_i \\ & \mathrm{E}\left[X_i U_i\right] = 0 \\ & \mathrm{E}\left[X_i X_i^\top\right] \ \text{ p.d. (no perfect multicollinearity)} \end{aligned}
Weaker than \mathrm{E}\left[U_i \mid X_i\right] = 0: \mathrm{E}\left[X_i U_i\right] = 0 \quad \nRightarrow \quad \mathrm{E}\left[Y_i \mid X_i\right] = X_i^\top \beta \quad \text{(in general)}
Consistency
Definition. \hat\beta_n consistent for \beta: \hat\beta_n \to_p \beta.
Theorem. Under the assumptions for consistency: \begin{aligned} \hat\beta_n &= \beta + \Big(\underbrace{\frac{1}{n} \sum_{i=1}^n X_i X_i^\top}_{\to_p\, \mathrm{E}\left[X_i X_i^\top\right]}\Big)^{-1} \underbrace{\frac{1}{n} \sum_{i=1}^n X_i U_i}_{\to_p\, 0} \\ &\to_p \beta \qquad \text{(Slutsky)} \end{aligned}
Asymptotic normality of OLS
Assumptions I and II
Approximate the distribution of \hat\beta_n - \beta: scale by \sqrt{n}.
Assumption I. \begin{aligned} & \{(Y_i, X_i) : i = 1, \ldots, n\} \ \text{ iid} \\ & Y_i = X_i^\top \beta + U_i, \qquad \beta \in \mathbb{R}^k \end{aligned}
Assumption II. Q = \mathrm{E}\left[X_i X_i^\top\right] \quad \text{p.d. and finite}
Normalized OLS representation: \sqrt{n}(\hat\beta_n - \beta) = \underbrace{\Big(\frac{1}{n} \sum_{i=1}^n X_i X_i^\top\Big)^{-1}}_{\to_p\, Q^{-1}}\ \frac{1}{\sqrt{n}} \sum_{i=1}^n X_i U_i
Assumption III and the CLT
Assumption III. \mathrm{E}\left[X_i U_i\right] = 0, \qquad \Omega = \mathrm{Var}\left(X_i U_i\right) \quad \text{finite and p.d.}
Variance of X_i U_i, with \mathrm{E}\left[X_i U_i\right] = 0: \Omega = \mathrm{Var}\left(X_i U_i\right) = \mathrm{E}\left[X_i U_i (X_i U_i)^\top\right] = \mathrm{E}\left[U_i^2 X_i X_i^\top\right]
X_1 U_1, \ldots, X_n U_n: iid; multivariate CLT: \frac{1}{\sqrt{n}} \sum_{i=1}^n X_i U_i \to_d N(0, \Omega)
Limit of \sqrt{n}(\hat\beta_n - \beta)
Cramér convergence theorem, without proof: A_n \to_p A, A non-random, \xi_n \to_d \xi: A_n \xi_n \to_d A \xi
Apply to the normalized representation: \begin{aligned} \sqrt{n}(\hat\beta_n - \beta) &= \underbrace{\Big(\frac{1}{n} \sum_{i=1}^n X_i X_i^\top\Big)^{-1}}_{\to_p\, Q^{-1}}\ \underbrace{\frac{1}{\sqrt{n}} \sum_{i=1}^n X_i U_i}_{\to_d\, N(0, \Omega)} \\ &\to_d Q^{-1} N(0, \Omega) \\ &\overset{d}{=} N(0, Q^{-1} \Omega Q^{-1}) \qquad (Q = Q^\top) \end{aligned}
Asymptotic variance
Theorem. Under Assumptions I to III: \sqrt{n}(\hat\beta_n - \beta) \to_d N(0, V), \qquad V = \mathrm{AsyVar}(\hat\beta_n) = Q^{-1} \Omega Q^{-1}
CDF form, for all a \ne 0 and t \in \mathbb{R}: \mathrm{P}\big(a^\top \sqrt{n}(\hat\beta_n - \beta) \le t\big) \to \Phi\Big(\frac{t}{\sqrt{a^\top V a}}\Big)
a = e_j, element j: \sqrt{n}(\hat\beta_{n,j} - \beta_j) \to_d N(0, V_{jj})
Homoskedasticity
Suppose: \mathrm{E}\left[U_i^2 \mid X_i\right] = \sigma^2 \quad \text{(homoskedasticity)}
Law of iterated expectations: \begin{aligned} \Omega &= \mathrm{E}\left[U_i^2 X_i X_i^\top\right] \\ &= \mathrm{E}\left[\mathrm{E}\left[U_i^2 X_i X_i^\top \mid X_i\right]\right] \\ &= \mathrm{E}\left[\underbrace{\mathrm{E}\left[U_i^2 \mid X_i\right]}_{=\,\sigma^2} X_i X_i^\top\right] \\ &= \sigma^2 \mathrm{E}\left[X_i X_i^\top\right] \\ &= \sigma^2 Q \end{aligned}
The sandwich collapses: \begin{aligned} \mathrm{AsyVar}(\hat\beta_n) &= Q^{-1} \Omega Q^{-1} \\ &= Q^{-1} (\sigma^2 Q) Q^{-1} \\ &= \sigma^2 Q^{-1} \end{aligned}
Finite sample against large sample
Normal errors, exact conditional distribution; a \ne 0: \begin{aligned} & Y = X\beta + U, \qquad U \mid X \sim N(0, \sigma^2 I_n) \\ \Longrightarrow\quad & \hat\beta_n \mid X \sim N\big(\beta,\ \sigma^2 (X^\top X)^{-1}\big) \\ \Longrightarrow\quad & \mathrm{P}\big(a^\top (\hat\beta_n - \beta) \le t \mid X\big) = \Phi\Big(\frac{t}{\sqrt{\sigma^2 a^\top (X^\top X)^{-1} a}}\Big) \\ \Longrightarrow\quad & \mathrm{P}\big(a^\top \sqrt{n}(\hat\beta_n - \beta) \le t \mid X\big) = \Phi\Bigg(\frac{t}{\sqrt{\sigma^2 a^\top \Big(\frac{1}{n} \sum_{i=1}^n X_i X_i^\top\Big)^{-1} a}}\Bigg) \end{aligned}
Large sample, homoskedastic errors, a \ne 0: \begin{aligned} & \text{Assumptions I and II}, \quad \mathrm{E}\left[X_i U_i\right] = 0, \quad \mathrm{E}\left[U_i^2 \mid X_i\right] = \sigma^2 > 0 \\ \Longrightarrow\quad & \mathrm{P}\big(a^\top \sqrt{n}(\hat\beta_n - \beta) \le t\big) \to \Phi\Big(\frac{t}{\sqrt{\sigma^2 a^\top \big(\mathrm{E}\left[X_i X_i^\top\right]\big)^{-1} a}}\Big) \end{aligned}
Large sample, heteroskedastic errors, a \ne 0: \begin{aligned} & \text{Assumptions I to III} \\ \Longrightarrow\quad & \mathrm{P}\big(a^\top \sqrt{n}(\hat\beta_n - \beta) \le t\big) \to \Phi\Big(\frac{t}{\sqrt{a^\top Q^{-1} \Omega Q^{-1} a}}\Big) \end{aligned}
Estimation of the asymptotic variance
The estimator \hat V_n
Unknown asymptotic variance: V = Q^{-1} \Omega Q^{-1}, \qquad Q = \mathrm{E}\left[X_i X_i^\top\right], \qquad \Omega = \mathrm{E}\left[U_i^2 X_i X_i^\top\right]
Sample averages and residuals in place of expectations and errors: \begin{aligned} \hat V_n &= \hat Q_n^{-1} \hat\Omega_n \hat Q_n^{-1}, \\ \hat Q_n &= \frac{1}{n} \sum_{i=1}^n X_i X_i^\top = \frac{1}{n} X^\top X, \qquad \hat Q_n^{-1} \to_p Q^{-1}, \\ \hat\Omega_n &= \frac{1}{n} \sum_{i=1}^n \hat U_i^2 X_i X_i^\top \end{aligned}
Residual and error, fixed i; continuous mapping, without proof: \begin{aligned} \hat U_i &= Y_i - X_i^\top \hat\beta_n = U_i + X_i^\top \underbrace{(\beta - \hat\beta_n)}_{\to_p\, 0} \\ &\to_p U_i \end{aligned}
Number of terms in the sum grows with n: \hat U_i \to_p U_i \ \text{(fixed $i$)} \quad \nRightarrow \quad \hat\Omega_n - \frac{1}{n} \sum_{i=1}^n U_i^2 X_i X_i^\top \to_p 0
Proof strategy: piece with U_i^2 plus the rest; show the rest \to_p 0: \hat\Omega_n = \frac{1}{n} \sum_{i=1}^n U_i^2 X_i X_i^\top + \underbrace{\text{rest}}_{\to_p\, 0}
Matrix norm
Frobenius norm of a k \times k matrix A: \|A\| = \sqrt{\sum_{r=1}^k \sum_{s=1}^k A_{rs}^2} = \sqrt{\operatorname{tr}(A^\top A)}
Element by element \Longleftrightarrow in norm; to show: \|\hat\Omega_n - \Omega\| \to_p 0
Expansion of \hat\Omega_n
Substitute \hat U_i = U_i - X_i^\top(\hat\beta_n - \beta): \begin{aligned} \hat\Omega_n &= \frac{1}{n} \sum_{i=1}^n \big(U_i - X_i^\top (\hat\beta_n - \beta)\big)^2 X_i X_i^\top \\ &= \frac{1}{n} \sum_{i=1}^n U_i^2 X_i X_i^\top + \frac{1}{n} \sum_{i=1}^n \big(X_i^\top (\hat\beta_n - \beta)\big)^2 X_i X_i^\top \\ &\qquad - 2\, \frac{1}{n} \sum_{i=1}^n \big(U_i X_i^\top (\hat\beta_n - \beta)\big) X_i X_i^\top \end{aligned}
First term, weak LLN; \Omega finite (Assumption III): \frac{1}{n} \sum_{i=1}^n U_i^2 X_i X_i^\top \to_p \Omega
To show: the other two terms \to_p 0.
Cauchy-Schwarz and \|X_i X_i^\top\|
Cauchy-Schwarz: \big|X_i^\top (\hat\beta_n - \beta)\big| \le \|X_i\|\, \|\hat\beta_n - \beta\|
Frobenius norm, \operatorname{tr}(AB) = \operatorname{tr}(BA): \begin{aligned} \|X_i X_i^\top\| &= \sqrt{\operatorname{tr}(X_i X_i^\top X_i X_i^\top)} \\ &= \sqrt{(X_i^\top X_i)^2} = \|X_i\|^2 \end{aligned}
Cross term \to_p 0
Norm of the cross term: \begin{aligned} & \Big\|\frac{1}{n} \sum_{i=1}^n \big(U_i X_i^\top (\hat\beta_n - \beta)\big) X_i X_i^\top\Big\| \\ &\quad \le \frac{1}{n} \sum_{i=1}^n \big\|\big(U_i X_i^\top (\hat\beta_n - \beta)\big) X_i X_i^\top\big\| \quad \text{(triangle inequality)} \\ &\quad = \frac{1}{n} \sum_{i=1}^n |U_i|\, \big|X_i^\top (\hat\beta_n - \beta)\big|\, \|X_i X_i^\top\| \quad \text{(scalars out of the norm)} \\ &\quad \le \frac{1}{n} \sum_{i=1}^n |U_i|\, \|X_i\|\, \|\hat\beta_n - \beta\|\, \|X_i X_i^\top\| \quad \text{(Cauchy-Schwarz)} \\ &\quad = \frac{1}{n} \sum_{i=1}^n |U_i|\, \|X_i\|\, \|\hat\beta_n - \beta\|\, \|X_i\|^2 \quad \big(\|X_i X_i^\top\| = \|X_i\|^2\big) \\ &\quad = \Big(\frac{1}{n} \sum_{i=1}^n |U_i|\, \|X_i\| \cdot \|X_i\|^2\Big) \|\hat\beta_n - \beta\| \\ &\quad \le \sqrt{\frac{1}{n} \sum_{i=1}^n U_i^2 \|X_i\|^2}\ \sqrt{\frac{1}{n} \sum_{i=1}^n \|X_i\|^4}\ \|\hat\beta_n - \beta\| \quad \text{(Cauchy-Schwarz)} \\ &\quad \le \sqrt{\sqrt{\frac{1}{n} \sum_{i=1}^n U_i^4}\ \sqrt{\frac{1}{n} \sum_{i=1}^n \|X_i\|^4}} \\ &\qquad\quad \times \sqrt{\frac{1}{n} \sum_{i=1}^n \|X_i\|^4}\ \|\hat\beta_n - \beta\| \quad \text{(Cauchy-Schwarz)} \\ &\quad = \Big(\frac{1}{n} \sum_{i=1}^n U_i^4\Big)^{1/4} \Big(\frac{1}{n} \sum_{i=1}^n \|X_i\|^4\Big)^{1/4} \Big(\frac{1}{n} \sum_{i=1}^n \|X_i\|^4\Big)^{1/2} \|\hat\beta_n - \beta\| \\ &\quad = \underbrace{\Big(\frac{1}{n} \sum_{i=1}^n U_i^4\Big)^{1/4}}_{\to_p\, (\mathrm{E}\left[U_i^4\right])^{1/4}} \underbrace{\Big(\frac{1}{n} \sum_{i=1}^n \|X_i\|^4\Big)^{3/4}}_{\to_p\, (\mathrm{E}\left[\|X_i\|^4\right])^{3/4}} \underbrace{\|\hat\beta_n - \beta\|}_{\to_p\, 0} \end{aligned}
Weak LLN: Assume: \mathrm{E}\left[U_i^4\right] < \infty, \mathrm{E}\left[\|X_i\|^4\right] < \infty.
Then, Slutsky: cross term \to_p 0.
Squared term \to_p 0
- Triangle inequality and Cauchy-Schwarz, then weak LLN and consistency: \begin{aligned} \Big\|\frac{1}{n} \sum_{i=1}^n \big(X_i^\top (\hat\beta_n - \beta)\big)^2 X_i X_i^\top\Big\| &\le \frac{1}{n} \sum_{i=1}^n \big(X_i^\top (\hat\beta_n - \beta)\big)^2\, \|X_i X_i^\top\| \\ &\le \Big(\underbrace{\frac{1}{n} \sum_{i=1}^n \|X_i\|^4}_{\to_p\, \mathrm{E}\left[\|X_i\|^4\right] < \infty}\Big) \underbrace{\|\hat\beta_n - \beta\|^2}_{\to_p\, 0} \\ &\to_p 0 \end{aligned}
\hat\Omega_n \to_p \Omega and \hat V_n \to_p V
Combine the three terms: \hat\Omega_n = \underbrace{\frac{1}{n} \sum_{i=1}^n U_i^2 X_i X_i^\top}_{\to_p\, \Omega} + \underbrace{\text{rest}}_{\to_p\, 0} \to_p \Omega
Theorem. Assumptions I to III, \mathrm{E}\left[U_i^4\right] < \infty, \mathrm{E}\left[\|X_i\|^4\right] < \infty: \hat V_n = \hat Q_n^{-1} \hat\Omega_n \hat Q_n^{-1} \to_p Q^{-1} \Omega Q^{-1} = V \qquad \text{(Slutsky)}
Robust and usual standard errors
Robust standard errors
\overset{a}{\sim}: approximate distribution for large n: \begin{aligned} & \sqrt{n}(\hat\beta_{n,j} - \beta_j) \overset{a}{\sim} N(0,\ V_{jj}) \\ \Longrightarrow\quad & \hat\beta_{n,j} \overset{a}{\sim} N\Big(\beta_j,\ \frac{V_{jj}}{n}\Big) \end{aligned}
Definition. Robust (heteroskedasticity-consistent, White) standard error: \begin{aligned} \text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big) &= \sqrt{\hat V_{n,jj} / {\color{blue} n}} \\ &= \sqrt{{\color{blue} \frac{1}{n}} \big[\hat Q_n^{-1} \hat\Omega_n \hat Q_n^{-1}\big]_{jj}} \\ &= \sqrt{{\color{blue} \frac{1}{n}} \Big[\Big({\color{red} \frac{1}{n}} X^\top X\Big)^{-1} \hat\Omega_n \Big({\color{red} \frac{1}{n}} X^\top X\Big)^{-1}\Big]_{jj}} \\ &= \sqrt{{\color{blue} \frac{1}{n}} \Big[\Big({\color{red} \frac{1}{n}} X^\top X\Big)^{-1} \Big({\color{blue} \frac{1}{n}} \sum_{i=1}^n \hat U_i^2 X_i X_i^\top\Big) \Big({\color{red} \frac{1}{n}} X^\top X\Big)^{-1}\Big]_{jj}} \\ &= \sqrt{{\color{blue} \frac{1}{n}} \Big[{\color{red} n}\, (X^\top X)^{-1}\, {\color{blue} \frac{1}{n}} \Big(\sum_{i=1}^n \hat U_i^2 X_i X_i^\top\Big)\, {\color{red} n}\, (X^\top X)^{-1}\Big]_{jj}} \\ &= \sqrt{\Big[(X^\top X)^{-1} \Big(\sum_{i=1}^n \hat U_i^2 X_i X_i^\top\Big) (X^\top X)^{-1}\Big]_{jj}} \end{aligned}
t-ratio with robust standard errors
\sqrt{\hat V_{n,jj}} \to_p \sqrt{V_{jj}} > 0; apply to the component CLT: \begin{aligned} \frac{\hat\beta_{n,j} - \beta_j}{\text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big)} &= \frac{\hat\beta_{n,j} - \beta_j}{\sqrt{\hat V_{n,jj} / n}} \\ &= \frac{\hat\beta_{n,j} - \beta_j}{\sqrt{\hat V_{n,jj}} / \sqrt{n}} \\ &= \frac{\sqrt{n}(\hat\beta_{n,j} - \beta_j)}{\sqrt{\hat V_{n,jj}}} \\ &\to_d \frac{N(0, V_{jj})}{\sqrt{V_{jj}}} \\ &= N(0, 1) \end{aligned}
Asymptotic confidence interval: \begin{aligned} CI_{1-\alpha} = \Big[ & \hat\beta_{n,j} - z_{1-\alpha/2}\, \text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big), \\ & \hat\beta_{n,j} + z_{1-\alpha/2}\, \text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big)\Big] \end{aligned}
Coverage, t-ratio \to_d Z \sim N(0, 1): \begin{aligned} \mathrm{P}\big(\beta_j \in CI_{1-\alpha}\big) &= \mathrm{P}\Big(\Big|\frac{\hat\beta_{n,j} - \beta_j}{\text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big)}\Big| \le z_{1-\alpha/2}\Big) \\ &\to \mathrm{P}\big(|Z| \le z_{1-\alpha/2}\big) \\ &= 1 - \alpha \end{aligned}
Usual and robust standard errors compared
Validity of the t-ratio (large n: conditions for \hat V_n \to_p V):
Errors Usual std. err Robust std. err U \mid X \sim N(0, \sigma^2 I_n) exact, t_{n-k} large n, N(0,1) \mathrm{E}\left[U_i^2 \mid X_i\right] = \sigma^2 large n, N(0,1) large n, N(0,1) \mathrm{E}\left[U_i^2 \mid X_i\right] depends on X_i invalid in general large n, N(0,1) Homoskedasticity: standard-error ratio \to_p 1, t quantile \to z_{1-\alpha/2}; asymptotically equivalent intervals: \begin{aligned} \text{usual, exact (row 1):}\quad & \hat\beta_{n,j} \pm t_{n-k,\,1-\alpha/2}\, \text{std. err}\big(\hat\beta_{n,j}\big) \\ \text{usual, large } n\text{:}\quad & \hat\beta_{n,j} \pm z_{1-\alpha/2}\, \text{std. err}\big(\hat\beta_{n,j}\big) \\ \text{robust, large } n\text{:}\quad & \hat\beta_{n,j} \pm z_{1-\alpha/2}\, \text{std. err}_{\text{rob}}\big(\hat\beta_{n,j}\big) \end{aligned}
Summary
Consistency and asymptotic normality
Assumptions for consistency \Longrightarrow \hat\beta_n \to_p \beta.
Normalized representation: \sqrt{n}(\hat\beta_n - \beta) = \Big(\frac{1}{n} \sum X_i X_i^\top\Big)^{-1} \frac{1}{\sqrt{n}} \sum X_i U_i
Assumptions I to III: \sqrt{n}(\hat\beta_n - \beta) \to_d N(0, V), \qquad V = Q^{-1} \Omega Q^{-1}
\mathrm{E}\left[U_i^2 \mid X_i\right] = \sigma^2 \Longrightarrow \Omega = \sigma^2 Q, V = \sigma^2 Q^{-1}.
Variance estimation and standard errors
\hat V_n = \hat Q_n^{-1} \hat\Omega_n \hat Q_n^{-1}, \hat Q_n = \frac{1}{n} \sum X_i X_i^\top, \hat\Omega_n = \frac{1}{n} \sum \hat U_i^2 X_i X_i^\top.
Assumptions I to III, \mathrm{E}\left[U_i^4\right] < \infty, \mathrm{E}\left[\|X_i\|^4\right] < \infty \Longrightarrow \hat V_n \to_p V.
\text{std. err}_{\text{rob}}(\hat\beta_{n,j}) = \sqrt{\hat V_{n,jj}/n}; robust t-ratio \to_d N(0,1); normal confidence interval: coverage \to 1-\alpha.
Heteroskedasticity: usual standard errors invalid in general; robust valid under stated conditions.
U \mid X \sim N(0,\sigma^2 I_n): usual t-ratio exactly t_{n-k}; t_{n-k,\,1-\alpha/2} \to z_{1-\alpha/2}.
Clustered standard errors
Robust and clustered variance estimators
\mathrm{E}\left[U \mid X\right] = 0; robust form when \mathrm{E}\left[U_i U_j \mid X\right] = 0 for i \ne j: \begin{aligned} \mathrm{Var}\left(\hat\beta_n \mid X\right) &= (X^\top X)^{-1} X^\top \mathrm{Var}\left(U \mid X\right) X (X^\top X)^{-1} \\ &= (X^\top X)^{-1} X^\top \mathrm{E}\left[U U^\top \mid X\right] X (X^\top X)^{-1} \\ &= (X^\top X)^{-1} \Big(\sum_{i=1}^n \sum_{j=1}^n \mathrm{E}\left[U_i U_j \mid X\right] X_i X_j^\top\Big) (X^\top X)^{-1} \\ &= (X^\top X)^{-1} \Big(\sum_{i=1}^n \mathrm{E}\left[U_i^2 \mid X\right] X_i X_i^\top\Big) (X^\top X)^{-1} \end{aligned}
Robust estimator, \hat U_i^2 in place of \mathrm{E}\left[U_i^2 \mid X\right]: (X^\top X)^{-1} \Big(\sum_{i=1}^n \hat U_i^2 X_i X_i^\top\Big) (X^\top X)^{-1}
Clusters: observations split into groups g = 1, \ldots, G; each i in one group.
Example: test scores of students i in school g; unobserved teacher quality in U_i for all i \in g.
Errors uncorrelated across clusters, correlated within a cluster: \mathrm{E}\left[U_i U_j \mid X\right] \begin{cases} = 0, & i, j \text{ in different clusters} \\ \ne 0, & i, j \text{ in the same cluster} \end{cases}
Cross-cluster terms drop out of the double sum: \mathrm{Var}\left(\hat\beta_n \mid X\right) =(X^\top X)^{-1} \Big(\sum_{g=1}^G \sum_{i \in g} \sum_{j \in g} \mathrm{E}\left[U_i U_j \mid X\right] X_i X_j^\top\Big) (X^\top X)^{-1}
Clustered estimator, \hat U_i \hat U_j in place of \mathrm{E}\left[U_i U_j \mid X\right]: (X^\top X)^{-1} \Big(\sum_{g=1}^G \sum_{i \in g} \sum_{j \in g} \hat U_i \hat U_j X_i X_j^\top\Big) (X^\top X)^{-1}