(Intercept) hostile_sexism partyIndependent partyRepublican
0.06 32.67 22.03 58.82
(Intercept) x_tilde
0.00 32.67
PS 812 - Introduction to Statistical Methods in Political Science
November 10, 2026
\[ \newcommand{\Var}{\text{Var}} \newcommand{\Cov}{\text{Cov}} \newcommand{\Corr}{\text{Corr}} \newcommand{\indep}{\mathrel{\perp\mkern-10mu\perp}} \]
We’ll show that under i.i.d. sampling, OLS is consistent for the Best Linear Predictor
But we want to estimate the CEF \(\mathbb{E}[Y_i \mid \mathbf{X}_i]\)
When the CEF is the BLP!
\[\mathbb{E}[Y_i \mid \mathbf{X}_i] = \mathbf{X}_i^\prime\boldsymbol{\beta}\]
When is the CEF linear?
With a bivariate regression, interpreting the coefficient on \(X_i\) is straightforward
\[\hat{\beta}_1 = \frac{\widehat{\Cov}(X_i, Y_i)}{\widehat{\Var}(X_i)}\]
The difference in the expectation of \(Y_i\) between respondents whose \(X_i\) differs by one unit
\[ \begin{aligned} \mathbb{E}[Y_i \mid X_i = x + 1] - \mathbb{E}[Y_i \mid X_i = x] &= \big(\beta_0 + \beta_1 (x + 1)\big) - \big(\beta_0 + \beta_1 x\big) \\ &= \beta_1 \end{aligned} \]
However, with a multivariate regression, the coefficient captures a different relationship.
The difference in the expected \(Y_i\) between respondents whose \(X_{i1}\) differs by one unit…
\[ \begin{aligned} &\mathbb{E}[Y_i \mid X_{i1} = x_1 + 1, X_{i2} = x_2, \dotsc, X_{i,k-1} = x_{k-1}] - \mathbb{E}[Y_i \mid X_{i1} = x_1, X_{i2} = x_2, \dotsc, X_{i,k-1} = x_{k-1}] \\ &\qquad = \big(\beta_0 + \beta_1 (x_1 + 1) + \beta_2 x_2 + \dotsc + \beta_{k-1} x_{k-1}\big) - \big(\beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dotsc + \beta_{k-1} x_{k-1}\big) \\ &\qquad = \beta_1 \end{aligned} \]
What is OLS actually doing?
Split the regressors into the one we care about, \(X_{i1}\), and everything else, \(\mathbf{X}_{i,-1}\) (which includes the intercept)
\[Y_i = \hat{\beta}_1 X_{i1} + \mathbf{X}_{i,-1}^\prime\hat{\boldsymbol{\beta}}_{-1} + \hat{e}_i\]
Frisch-Waugh-Lovell (FWL): we can get the same \(\hat{\beta}_1\) from three regressions
The slope is exactly \(\hat{\beta}_1\)
\[\hat{\beta}_1 = \frac{\widehat{\Cov}(\tilde{X}_{i1}, \tilde{Y}_i)}{\widehat{\Var}(\tilde{X}_{i1})}\]
\(\hat{\beta}_1\) only uses the variation in \(X_{i1}\) that is not linearly predicted by the other covariates to explain \(Y_i\)
“Controlling for” \(\mathbf{X}_{i,-1}\) means partialling out its linear relationship with both \(X_{i1}\) and \(Y_i\)
Remember that the “partialling out” is linear
In our example, \(\mathbf{X}_{i,-1}\) is the intercept plus the Independent and Republican dummies
So partialling out party just subtracts each respondent’s party mean
\[\tilde{X}_{i1} = X_{i1} - \bar{X}_{\text{party}(i)} \qquad \tilde{Y}_i = Y_i - \bar{Y}_{\text{party}(i)}\]
\(\hat{\beta}_1\) is the slope using only the within-party variation
(Intercept) hostile_sexism partyIndependent partyRepublican
0.06 32.67 22.03 58.82
(Intercept) x_tilde
0.00 32.67
To let the slope on hostile sexism differ between parties too we add interactions
\[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_i + \hat{\beta}_2 X_i^{\text{Ind}} + \hat{\beta}_3 X_i^{\text{Rep}} + \hat{\beta}_4 X_i X_i^{\text{Ind}} + \hat{\beta}_5 X_i X_i^{\text{Rep}}\]
Within each party, the fit is still a line in \(X_i\), but now each has its own intercept and slope
\[\begin{aligned} \text{Democrats:} \quad & \hat{\beta}_0 + \hat{\beta}_1 X_i \\ \text{Independents:} \quad & (\hat{\beta}_0 + \hat{\beta}_2) + (\hat{\beta}_1 + \hat{\beta}_4) X_i \\ \text{Republicans:} \quad & (\hat{\beta}_0 + \hat{\beta}_3) + (\hat{\beta}_1 + \hat{\beta}_5) X_i \end{aligned}\]
\(\hat{\beta}_1\) is now the slope among Democrats (the baseline), and \(\hat{\beta}_4\), \(\hat{\beta}_5\) are differences in slopes relative to Democrats
With every interaction in, this is the same as fitting a separate OLS line within each party
(Intercept) hostile_sexism partyIndependent
0.95 29.06 20.93
partyRepublican hostile_sexism:partyIndependent hostile_sexism:partyRepublican
56.08 4.12 7.76
Does the slope on hostile sexism differ by education?
\[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_i + \hat{\beta}_2 X_i^{\text{Col}} + \hat{\beta}_3 X_i X_i^{\text{Col}}\]
Within each education group, the fit is a line in \(X_i\) with its own intercept and slope
\[\begin{aligned} \text{No college degree:} \quad & \hat{\beta}_0 + \hat{\beta}_1 X_i \\ \text{College degree:} \quad & (\hat{\beta}_0 + \hat{\beta}_2) + (\hat{\beta}_1 + \hat{\beta}_3) X_i \end{aligned}\]
\(\hat{\beta}_1\) is the slope among respondents without a degree (the baseline), and \(\hat{\beta}_3\) is the difference in slopes for college graduates
(Intercept) hostile_sexism college hostile_sexism:college
15.42 79.18 -14.47 20.43
Racial resentment: a three question measure from Kinder and Sanders (1996), also averaged and re-scaled to \([0, 1]\)
With two continuous covariates, the fit is a plane over \((X_{i1}, X_{i2})\)
\[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_{i1} + \hat{\beta}_2 X_{i2}\]
A linear interaction with two continuous covariates adds the product of hostile sexism and racial resentment to the equation.
\[\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_{i1} + \hat{\beta}_2 X_{i2} + \hat{\beta}_3 X_{i1} X_{i2}\]
Holding \(X_{i2}\) at a value \(x_2\), we’re still estimating a line for \(X_{i1}\), but its slope now depends on \(x_2\)
\[\big[\hat{\beta}_0 + \hat{\beta}_1 (x_1 + 1) + \hat{\beta}_2 x_2 + \hat{\beta}_3 (x_1 + 1) x_2\big] - \big[\hat{\beta}_0 + \hat{\beta}_1 x_1 + \hat{\beta}_2 x_2 + \hat{\beta}_3 x_1 x_2\big] = \hat{\beta}_1 + \hat{\beta}_3 x_2\]
We’ve made a few regularity assumptions to ensure the BLP exists
What do we need to make OLS consistent for the BLP?
Write \(Y_i\) in terms of the projection error, \(Y_i = \mathbf{X}_i^\prime\boldsymbol{\beta} + e_i\), and substitute it into \(\hat{\boldsymbol{\beta}}\)
\[ \begin{aligned} \hat{\boldsymbol{\beta}} &= \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\big(\mathbf{X}_i^\prime\boldsymbol{\beta} + e_i\big)\right) \\ &= \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)\boldsymbol{\beta} + \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i\right) \\ &= \boldsymbol{\beta} + \left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i\right) \end{aligned} \]
By the law of large numbers, each sample mean converges to its population mean
\[\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime \xrightarrow{p} \mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime] \qquad \frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i \xrightarrow{p} \mathbb{E}[\mathbf{X}_i e_i] = \mathbf{0}\]
The inverse is a continuous function, so by the continuous mapping theorem
\[\hat{\boldsymbol{\beta}} \xrightarrow{p} \boldsymbol{\beta} + \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\mathbf{0} = \boldsymbol{\beta}\]
Really, we just need an LLN to apply to our sample plug-ins
For the sample mean, the CLT gave us \(\sqrt{n}(\hat{\mu} - \mu) \xrightarrow{d} \mathcal{N}(0, \sigma^2)\). The same idea applies to \(\hat{\boldsymbol{\beta}}\)
Multiply the decomposition by \(\sqrt{n}\)
\[\sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big) = \underbrace{\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}}_{\xrightarrow{p}\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}} \ \underbrace{\sqrt{n}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i - \mathbf{0}\right)}_{\xrightarrow{d}\ \mathcal{N}(\mathbf{0},\ \boldsymbol{\Omega})}\]
A multivariate CLT applies to the sample mean of the i.i.d. \(\mathbf{X}_ie_i\) random vectors and
\[\boldsymbol{\Omega} = \Var(\mathbf{X}_i e_i) = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime]\]
By Slutsky’s theorem
\(\sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big) \xrightarrow{d} \mathcal{N}\Big(\mathbf{0},\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\boldsymbol{\Omega}\,\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\Big)\)
Now let’s obtain \(\Var(\hat{\boldsymbol{\beta}})\) - the variance-covariance matrix of the sampling distribution of \(\hat{\boldsymbol{\beta}}\)
Applying this to \(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta} = \frac{1}{\sqrt{n}} \cdot \sqrt{n}\big(\hat{\boldsymbol{\beta}} - \boldsymbol{\beta}\big)\)
\[\Var(\hat{\boldsymbol{\beta}}) = \frac{1}{n}\Var\Bigg(\underbrace{\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime\right)^{-1}}_{\mathbf{A}\ \xrightarrow{p}\ \big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}} \ \underbrace{\sqrt{n}\left(\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i e_i - \mathbf{0}\right)}_{\mathbf{Z}\ \xrightarrow{d}\ \mathcal{N}(\mathbf{0},\ \boldsymbol{\Omega})}\Bigg)\]
The result is a sandwich: two slices of bread around the filling
\[\underbrace{\Var(\hat{\boldsymbol{\beta}})}_{k \times k} \approx \frac{1}{n} \underbrace{\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}}_{k \times k} \ \underbrace{\boldsymbol{\Omega}}_{k \times k} \ \underbrace{\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}}_{k \times k}\]
Written out, the variance-covariance matrix of \(\hat{\boldsymbol{\beta}}\) is
\[\Var(\hat{\boldsymbol{\beta}}) = \begin{pmatrix} \Var(\hat{\beta}_0) & \Cov(\hat{\beta}_0, \hat{\beta}_1) & \cdots & \Cov(\hat{\beta}_0, \hat{\beta}_{k-1}) \\ \Cov(\hat{\beta}_1, \hat{\beta}_0) & \Var(\hat{\beta}_1) & \cdots & \Cov(\hat{\beta}_1, \hat{\beta}_{k-1}) \\ \vdots & \vdots & \ddots & \vdots \\ \Cov(\hat{\beta}_{k-1}, \hat{\beta}_0) & \Cov(\hat{\beta}_{k-1}, \hat{\beta}_1) & \cdots & \Var(\hat{\beta}_{k-1}) \end{pmatrix}\]
\(\mathbb{E}[\mathbf{X}_i e_i] = \mathbf{0}\), so \(\boldsymbol{\Omega}\) is the expectation of an outer product
\[\boldsymbol{\Omega} = \Var(\mathbf{X}_i e_i) = \mathbb{E}\big[(\mathbf{X}_i e_i)(\mathbf{X}_i e_i)^\prime\big] - \underbrace{\mathbb{E}[\mathbf{X}_i e_i]\,\mathbb{E}[\mathbf{X}_i e_i]^\prime}_{\mathbf{0}} = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime]\]
Each respondent contributes \(\mathbf{X}_i\mathbf{X}_i^\prime\) weighted by their squared error
\[\small \underbrace{\mathbf{X}_i e_i}_{k \times 1} \quad \underbrace{(\mathbf{X}_i e_i)^\prime}_{1 \times k} = e_i^2 \begin{pmatrix} 1 \\ X_{i1} \\ \vdots \\ X_{i,k-1} \end{pmatrix} \begin{pmatrix} 1 & X_{i1} & \cdots & X_{i,k-1} \end{pmatrix} = \begin{pmatrix} e_i^2 & e_i^2 X_{i1} & \cdots & e_i^2 X_{i,k-1} \\ e_i^2 X_{i1} & e_i^2 X_{i1}^2 & \cdots & e_i^2 X_{i1} X_{i,k-1} \\ \vdots & \vdots & \ddots & \vdots \\ e_i^2 X_{i,k-1} & e_i^2 X_{i,k-1} X_{i1} & \cdots & e_i^2 X_{i,k-1}^2 \end{pmatrix}\]
Plug-in principle again: replace each expectation with a sample mean and each unobserved \(e_i\) with its residual \(\hat{e}_i = Y_i - \mathbf{X}_i^\prime\hat{\boldsymbol{\beta}}\)
\[\frac{1}{n}\sum_{i=1}^n \mathbf{X}_i\mathbf{X}_i^\prime = \frac{1}{n}\mathbf{X}^\prime\mathbf{X} \qquad \widehat{\boldsymbol{\Omega}} = \frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\]
Plug these into the sandwich (the \(n\)’s cancel)
\[\begin{aligned} \widehat{\Var}(\hat{\boldsymbol{\beta}}) &= \frac{1}{n}\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1}\left(\frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\right)\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1} \\ &= (\mathbf{X}^\prime\mathbf{X})^{-1}\left(\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime\right)(\mathbf{X}^\prime\mathbf{X})^{-1} \end{aligned}\]
This is the heteroskedasticity-consistent (HC0) or Eicker-Huber-White estimator - usually called robust standard errors
You’ll often see the filling written as an equivalent matrix product involving a \(n \times n\) matrix \(\widehat{\mathbf{D}}\)
\[\sum_{i=1}^n \hat{e}_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime = \underbrace{\mathbf{X}^\prime}_{k \times n} \ \underbrace{\widehat{\mathbf{D}}}_{n \times n} \ \underbrace{\mathbf{X}}_{n \times k} = \begin{pmatrix} \mathbf{X}_1 & \mathbf{X}_2 & \cdots & \mathbf{X}_n \end{pmatrix} \begin{pmatrix} \hat{e}_1^2 & 0 & \cdots & 0 \\ 0 & \hat{e}_2^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \hat{e}_n^2 \end{pmatrix} \begin{pmatrix} \mathbf{X}_1^\prime \\ \mathbf{X}_2^\prime \\ \vdots \\ \mathbf{X}_n^\prime \end{pmatrix}\]
Later on, we’ll connect this to the variance-covariance matrix of the errors in the classical regression setting
The HC0 variance estimator is a \(k \times k\) sandwich
\[\underbrace{\widehat{\Var}(\hat{\boldsymbol{\beta}})}_{k \times k} = \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}}_{k \times k} \ \underbrace{\mathbf{X}^\prime\widehat{\mathbf{D}}\mathbf{X}}_{k \times k} \ \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}}_{k \times k}\]
Let’s take a look at this with a complete regression with both attitude measures and the party dummies
[1] 4562 5
e_hat <- resid(fit_full)
bread <- solve(t(X) %*% X) # (X'X)^{-1}, k x k
D <- diag(e_hat^2) # n x n, squared residuals on the diagonal
filling <- t(X) %*% D %*% X # X'DX, k x k
V_hc0 <- bread %*% filling %*% bread # k x k
round(sqrt(diag(V_hc0)), 3) # standard errors: the square roots of the diagonal (Intercept) hostile_sexism racial_resentment partyIndependent partyRepublican
0.559 2.026 1.573 1.841 1.042
sandwichsandwich package computes these for any lm() fit (Intercept) hostile_sexism racial_resentment partyIndependent partyRepublican
0.559 2.026 1.573 1.841 1.042
vcovHC is type = "HC3" which is a small-sample correction
HC1 rescales HC0 by \(n/(n - k)\) (Stata’s , robust)HC2 and HC3 rescale each \(\hat{e}_i^2\) by how much observation \(i\) pulls on its own fitAsymptotic normality lets us use the same approach to testing as before
\[\frac{\hat{\beta}_j - \beta_j}{\widehat{SE}(\hat{\beta}_j)} \xrightarrow{d} \mathcal{N}(0, 1) \qquad \widehat{SE}(\hat{\beta}_j) = \sqrt{\big[\widehat{\Var}(\hat{\boldsymbol{\beta}})\big]_{jj}}\]
95% confidence interval: \(\hat{\beta}_j \pm 1.96 \times \widehat{SE}(\hat{\beta}_j)\)
Test of \(H_0: \beta_j = 0\): \(t = \hat{\beta}_j / \widehat{SE}(\hat{\beta}_j)\), with two-sided p-value \(2\big(1 - \Phi(|t|)\big)\)
estimate se lower upper t p
(Intercept) -4.325 0.559 -5.422 -3.229 -7.734 1.04e-14
hostile_sexism 24.153 2.026 20.183 28.123 11.924 8.85e-33
racial_resentment 19.623 1.573 16.541 22.706 12.476 1.01e-35
partyIndependent 19.423 1.841 15.815 23.032 10.550 5.10e-26
partyRepublican 53.285 1.042 51.242 55.328 51.125 0.00e+00
With one regressor, the OLS slope is
\[\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2} = \frac{\sum_{i=1}^n (X_i - \bar{X})\,Y_i}{\sum_{i=1}^n (X_i - \bar{X})^2}\]
Substitute \(Y_i = \beta_0 + \beta_1 X_i + e_i\). Because \(\sum_i (X_i - \bar{X}) = 0\) and \(\sum_i (X_i - \bar{X})X_i = \sum_i (X_i - \bar{X})^2\)
\[\hat{\beta}_1 = \beta_1 + \frac{\sum_{i=1}^n (X_i - \bar{X})\,e_i}{\sum_{i=1}^n (X_i - \bar{X})^2}\]
Divide the top and the bottom by \(n\)
\[\hat{\beta}_1 - \beta_1 = \frac{\overbrace{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})\,e_i}^{\approx\ \frac{1}{n}\sum_{i=1}^n (X_i - \mu_X)\,e_i}}{\underbrace{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2}_{\xrightarrow{p}\ \Var(X_i)}}\]
Since \(\bar{X} \xrightarrow{p} \mu_X\), the numerator behaves like a sample mean of the i.i.d. \((X_i - \mu_X)e_i\), which have mean \(0\) and variance \(\mathbb{E}[(X_i - \mu_X)^2 e_i^2]\)
The variance of a sample mean of \(n\) i.i.d. terms is \(\frac{1}{n}\) times the variance of one term
And we get the sandwich estimator in scalar form:
\[\Var(\hat{\beta}_1) \approx \frac{1}{n}\,\frac{\overbrace{\mathbb{E}\big[(X_i - \mu_X)^2 e_i^2\big]}^{\text{filling}}}{\underbrace{\Var(X_i)^2}_{\text{bread}}}\]
Plug-in: replace the expectations with sample means and \(e_i\) with \(\hat{e}_i\) (the \(n\)’s cancel)
\[\begin{aligned} \widehat{\Var}(\hat{\beta}_1) &= \frac{1}{n}\,\frac{\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2\,\hat{e}_i^2}{\Big(\frac{1}{n}\sum_{i=1}^n (X_i - \bar{X})^2\Big)^2} \\ &= \frac{\sum_{i=1}^n (X_i - \bar{X})^2\,\hat{e}_i^2}{\Big(\sum_{i=1}^n (X_i - \bar{X})^2\Big)^2} \end{aligned}\]
and \(\widehat{SE}(\hat{\beta}_1) = \sqrt{\widehat{\Var}(\hat{\beta}_1)}\)
Our standard error for the slope is smaller when we have…
Given our standard errors for \(\hat{\beta}_0\) and \(\hat{\beta}_1\), we may want to know how precise our BLP estimate of \(Y\) is at a given \(x\)
\[\hat{Y}(x) = \hat{\beta}_0 + \hat{\beta}_1 x\]
This is a sum of two random variables, so we need the full variance-covariance matrix of \(\hat{\boldsymbol{\beta}}\)
\[\Var\bigg(\hat{Y}(x)\bigg) = \Var(\hat{\beta}_0) + x^2\,\Var(\hat{\beta}_1) + 2x\,\Cov(\hat{\beta}_0, \hat{\beta}_1)\]
To get the intuition for how the variance changes, re-write the line as: \(\hat{Y}(x) = \bar{Y} + \hat{\beta}_1\,(x - \bar{X})\)
(Intercept) hostile_sexism
(Intercept) 0.6418807 -1.362200
hostile_sexism -1.3622003 4.614875
# A tibble: 3 × 4
x fit lower upper
<dbl> <dbl> <dbl> <dbl>
1 0 6.23 4.66 7.80
2 0.01 7.17 5.63 8.71
3 0.02 8.11 6.61 9.61
lm() defaultscoeftest() from lmtest will implement the tests with whatever variance covariance matrix we want to give it
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -4.32538 0.70955 -6.0959 1.178e-09 ***
hostile_sexism 24.15327 1.85536 13.0181 < 2.2e-16 ***
racial_resentment 19.62334 1.41061 13.9112 < 2.2e-16 ***
partyIndependent 19.42301 1.41708 13.7064 < 2.2e-16 ***
partyRepublican 53.28474 0.85917 62.0190 < 2.2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -4.32538 0.55927 -7.734 1.274e-14 ***
hostile_sexism 24.15327 2.02556 11.924 < 2.2e-16 ***
racial_resentment 19.62334 1.57288 12.476 < 2.2e-16 ***
partyIndependent 19.42301 1.84110 10.550 < 2.2e-16 ***
partyRepublican 53.28474 1.04225 51.125 < 2.2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lm() defaultslm() default |
Robust (HC0) | |
|---|---|---|
| (1) | (2) | |
| Intercept | −4.33*** | −4.33*** |
| (0.71) | (0.56) | |
| Hostile sexism | 24.15*** | 24.15*** |
| (1.86) | (2.03) | |
| Racial resentment | 19.62*** | 19.62*** |
| (1.41) | (1.57) | |
| Independent | 19.42*** | 19.42*** |
| (1.42) | (1.84) | |
| Republican | 53.28*** | 53.28*** |
| (0.86) | (1.04) | |
| N | 4,562 | 4,562 |
| R² | 0.68 | 0.68 |
Outcome: Trump thermometer. Democrats are the omitted party baseline. Standard errors in parentheses. Two-sided tests of H₀: βj = 0: * p < 0.05, ** p < 0.01, *** p < 0.001.
— Keisuke Hirano
The classical OLS model adds an assumption about the errors: homoskedasticity
\[\mathbb{E}[e_i^2 \mid \mathbf{X}_i] = \sigma^2\]
Under homoskedasticity, the filling simplifies by the law of iterated expectations
\[\boldsymbol{\Omega} = \mathbb{E}[e_i^2\,\mathbf{X}_i\mathbf{X}_i^\prime] = \mathbb{E}\big[\mathbb{E}[e_i^2 \mid \mathbf{X}_i]\,\mathbf{X}_i\mathbf{X}_i^\prime\big] = \sigma^2\,\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\]
And the sandwich reduces to…
\[\Var(\hat{\boldsymbol{\beta}}) \approx \frac{1}{n}\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\,\sigma^2\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\,\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1} = \frac{\sigma^2}{n}\big(\mathbb{E}[\mathbf{X}_i\mathbf{X}_i^\prime]\big)^{-1}\]
\[\Var(\hat{\boldsymbol{\beta}}) \approx \frac{1}{n}\sigma^2\left(\frac{1}{n}\mathbf{X}^\prime\mathbf{X}\right)^{-1} = \sigma^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]
A natural plug-in for \(\sigma^2\) is \(\frac{1}{n}\sum_{i=1}^n \hat{e}_i^2\).
The unbiased estimator divides by \(n - k\), the number of observations minus the number of coefficients
\[\hat{\sigma}^2 = \frac{1}{n - k}\sum_{i=1}^n \hat{e}_i^2\]
Related to our earlier results for the unbiased population variance estimator
The classical OLS variance estimator is therefore
\[\widehat{\Var}(\hat{\boldsymbol{\beta}}) = \hat{\sigma}^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]
Default for summary(lm())
HC2 correction (default in lm_robust() in the estimatr package).Many textbooks start from a much stronger set of assumptions. Conditional on the \(n \times k\) matrix \(\mathbf{X}\)
The benefit of this is that we get exact finite-sample results instead of asymptotic approximations
\[\mathbb{E}[\hat{\boldsymbol{\beta}} \mid \mathbf{X}] = \boldsymbol{\beta} \qquad \Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\,\underbrace{\Var(\mathbf{e} \mid \mathbf{X})}_{\sigma^2\mathbf{I}_n}\,\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1} = \sigma^2(\mathbf{X}^\prime\mathbf{X})^{-1}\]
Our “agnostic” approach so far needed only i.i.d. sampling and the regularity conditions
With a linear CEF, the “filling” of the sandwich variance can be written in terms of the variance-covariance matrix of the errors \(\boldsymbol{\Sigma} = \Var(\mathbf{e} \mid \mathbf{X})\)
\[\Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) = (\mathbf{X}^\prime\mathbf{X})^{-1}\,\mathbf{X}^\prime\boldsymbol{\Sigma}\mathbf{X}\,(\mathbf{X}^\prime\mathbf{X})^{-1}\]
Each standard error estimator assumes a different \(\boldsymbol{\Sigma}\)
Homoskedastic
\[\small \begin{pmatrix} \sigma^2 & 0 & \cdots & 0 \\ 0 & \sigma^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma^2 \end{pmatrix}\]
Heteroskedastic
\[\small \begin{pmatrix} \sigma_1^2 & 0 & \cdots & 0 \\ 0 & \sigma_2^2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma_n^2 \end{pmatrix}\]
Clustered
\[\small \left(\begin{array}{ccc|ccc|c} \sigma_1^2 & \sigma_{12} & \cdots & 0 & 0 & \cdots & \cdots \\ \sigma_{12} & \sigma_2^2 & \cdots & 0 & 0 & \cdots & \cdots \\ \vdots & \vdots & \ddots & \vdots & \vdots & & \\ \hline 0 & 0 & \cdots & \sigma_j^2 & \sigma_{jk} & \cdots & \cdots \\ 0 & 0 & \cdots & \sigma_{jk} & \sigma_k^2 & \cdots & \cdots \\ \vdots & \vdots & & \vdots & \vdots & \ddots & \\ \hline \vdots & \vdots & & \vdots & \vdots & & \ddots \end{array}\right)\]
Under assumptions 1-3, OLS is the Best Linear Unbiased Estimator (BLUE)
Proof sketch: write an alternative estimator that deviates from OLS: \(\mathbf{C} = (\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime + \mathbf{D}\).
\[\small \Var(\tilde{\boldsymbol{\beta}} \mid \mathbf{X}) = \sigma^2\mathbf{C}\mathbf{C}^\prime = \sigma^2\big[(\mathbf{X}^\prime\mathbf{X})^{-1} + \underbrace{(\mathbf{X}^\prime\mathbf{X})^{-1}\mathbf{X}^\prime\mathbf{D}^\prime}_{\mathbf{0}} + \underbrace{\mathbf{D}\mathbf{X}(\mathbf{X}^\prime\mathbf{X})^{-1}}_{\mathbf{0}} + \mathbf{D}\mathbf{D}^\prime\big] = \Var(\hat{\boldsymbol{\beta}} \mid \mathbf{X}) + \sigma^2\mathbf{D}\mathbf{D}^\prime\]
| Compute \(\hat{\boldsymbol{\beta}}\) |
Consistent for the BLP |
Asymptotic inference on the BLP(robust SEs) |
Unbiased for the CEF |
BLUE(classical SEs) | Exact finite-sample inference(\(t_{n-k}\)) |
|
|---|---|---|---|---|---|---|
| No perfect collinearity | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| i.i.d. sampling + regularity conditions | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Linear CEF, \(\mathbb{E}[e_i \mid \mathbf{X}_i] = 0\) | ✓ | ✓ | ✓ | |||
| Homoskedasticity, \(\Var(e_i \mid \mathbf{X}_i) = \sigma^2\) | ✓ | ✓ | ||||
| Normal errors | ✓ |
Wrapping up inference for regression
More regression mechanics
Problem Set 5 due Tuesday, November 17
Second Midterm Exam on Wednesday, November 18
PS 812 - University of Wisconsin-Madison