هذا الكتاب غير متوفر بعد باللغة العربية. النسخ المتوفرة: English.
University Economics — Year 2 · السنة الجامعية 2
30Multiple Regression
A regression with one regressor compares people who differ in that regressor and, usually, in much else. Adding regressors compares people who differ in the first and are alike in the others. This chapter writes the model in matrix form, derives the least-squares estimator, shows what “holding the others constant” means exactly, and measures what leaving a variable out does to a coefficient. The chart shows the question on real data: the estimated return to a year of schooling as the comparison is made more like for like.
With no control, a year of schooling goes with log earnings 4.10 per cent higher. Adding age raises the estimate to 5.22; adding age squared brings it to 3.99; race and marriage move it little; adding 1975 earnings halves it, to 2.04. Each number is a correct answer to a different question. Which question is the right one is not a matter of statistics, and the last step is a warning taken up in Chapter 32.
You already know
From the Year 1 volume: the ordinary least squares estimator with one regressor, fitted values and residuals, the error term, the zero conditional mean assumption, , the omitted variable, estimators, standard errors and confidence intervals. From mathematics: matrices, the transpose, the inverse, the rank, and orthogonal projection.
30.1 The model in matrix form
Definition 30.1 (Multiple regression model)
The multiple regression model writes an outcome as a linear function of several regressors plus an error: , .
Definition 30.2 (Regressor matrix)
The regressor matrix is the matrix whose row is : one row per observation, one column per regressor, the first column a column of ones.
With and the -vectors of outcomes and errors and the -vector of coefficients, the model is . Three assumptions make the object least squares estimates: the model is linear in ; has full column rank , so that no column is a linear combination of the others; and , so that the errors have mean zero whatever the regressors. The coefficient is then the change in the conditional mean of when rises by one and the other regressors are held fixed.
30.2 The least-squares estimator
Least squares chooses to minimise the sum of squared residuals . Setting the gradient to zero gives the following equations.
Definition 30.3 (Normal equations)
The normal equations of least squares are ; when has full column rank, is invertible and they have the single solution .
The normal equations say : the residual vector is orthogonal to every column of . So the fitted vector is the orthogonal projection of on the space spanned by the columns of , and is what is left, at right angles to that space. With a column of ones in , the residuals sum to zero.
The listings use the CPS comparison sample described in the box. The first loads it; the second solves the normal equations with numpy and compares the result with statsmodels.
How it is measured — The comparison sample
LaLonde (1986) asked whether econometric methods applied to survey data could reproduce what a field experiment had found about a training programme. To do so he built comparison samples of men from two American surveys, the Current Population Survey and the Panel Study of Income Dynamics. Dehejia and Wahba (1999) re-examined the same samples and distribute them; the CPS one has 15,992 men, with their age, schooling, race, marital status, whether they have a high-school diploma, and their earnings in 1974, 1975 and 1978. In the file, 25.9 per cent of the men have 1978 earnings equal to the largest value, 25,564.7: earnings above some level were recorded at that level, so the top of the distribution is cut off. This chapter uses the 13,055 men with positive earnings in both 1975 and 1978. Dropping the men with no earnings in 1978 selects on the outcome itself, so the coefficients describe men in work, not all men; the experiment itself returns in Chapter 33.
"""The CPS comparison sample: men with positive earnings in 1975 and 1978."""
import numpy as np
from econdata import nsw
d = nsw("cps_controls")
cap = d.re78.max()
print(f"men in the file: {len(d)}")
print(f"share at the 1978 maximum of {cap:,.1f}: {(d.re78 == cap).mean():.1%}")
d = d[(d.re78 > 0) & (d.re75 > 0)].copy()
d["lre78"] = np.log(d.re78)
d["lre75"] = np.log(d.re75)
print(f"men with positive earnings in 1975 and 1978: {len(d)}")
cols = ["lre78", "education", "age", "black", "hispanic", "married", "lre75"]
table = d[cols].describe().loc[["mean", "std", "min", "max"]].T
print(table.round(2).to_string())
$ python load_cps.py
men in the file: 15992
share at the 1978 maximum of 25,564.7: 25.9%
men with positive earnings in 1975 and 1978: 13055
mean std min max
lre78 9.55 0.90 1.08 10.15
education 12.03 2.85 0.00 18.00
age 33.24 10.81 16.00 55.00
black 0.07 0.25 0.00 1.00
hispanic 0.07 0.26 0.00 1.00
married 0.73 0.44 0.00 1.00
lre75 9.36 1.03 2.37 10.14
"""Least squares by the normal equations, against statsmodels."""
import numpy as np
import statsmodels.api as sm
from econdata import nsw
d = nsw("cps_controls")
d = d[(d.re78 > 0) & (d.re75 > 0)]
y = np.log(d.re78).to_numpy()
names = ["const", "education", "age", "age2", "black", "hispanic", "married"]
cols = [np.ones(len(d)), d.education, d.age, d.age**2, d.black, d.hispanic, d.married]
X = np.column_stack(cols)
n, k = X.shape
beta = np.linalg.solve(X.T @ X, X.T @ y) # the normal equations X'X b = X'y
fit = sm.OLS(y, X).fit()
for name, b, b_sm in zip(names, beta, fit.params):
print(f"{name:10s} {b:12.6f} {b_sm:12.6f}")
print("same coefficients to 1e-8:", np.allclose(beta, fit.params, rtol=0, atol=1e-8))
e = y - X @ beta
print("residuals orthogonal to every column:", np.allclose(X.T @ e, 0, atol=1e-5))
r2 = 1 - (e @ e) / ((y - y.mean()) @ (y - y.mean()))
adj = 1 - (1 - r2) * (n - 1) / (n - k)
print(f"R2 {r2:.4f} ({fit.rsquared:.4f}), adjusted {adj:.4f} ({fit.rsquared_adj:.4f})")
$ python ols_by_hand.py
const 7.100734 7.100734
education 0.038343 0.038343
age 0.098755 0.098755
age2 -0.001202 -0.001202
black -0.170828 -0.170828
hispanic -0.052405 -0.052405
married 0.262576 0.262576
same coefficients to 1e-8: True
residuals orthogonal to every column: True
R2 0.1181 (0.1181), adjusted 0.1177 (0.1177)
Holding age, race and marriage fixed, a year of schooling goes with earnings 3.83 per cent higher; married men earn 26.3 log points more than unmarried men of the same age, schooling and race. Age enters with a positive coefficient and a negative one on its square: earnings rise with age at a falling rate.
30.3 Partialling out
What does “holding the others fixed” do to the data? Split the regressors into , the one of interest, and , the others (with the column of ones), so that .
Definition 30.4 (Frisch–Waugh–Lovell theorem)
The Frisch–Waugh–Lovell theorem states that the least-squares coefficient on in the regression of on and equals the coefficient in the regression of on , where and are the residuals from regressing and on .
Proposition 30.5 (Frisch–Waugh–Lovell)
Let , and . Then the coefficient on in the regression of on is .
Proof. is symmetric, , and . Write , with orthogonal to and to every column of . Then , since is already orthogonal to . Multiply by : . Multiply by : . Since and , ; and . ∎
The coefficient on schooling uses only the variation in schooling that age, race and marriage do not predict. The rest of the variation is discarded.
"""Frisch-Waugh-Lovell: the education coefficient by partialling out the controls."""
import numpy as np
from econdata import nsw
d = nsw("cps_controls")
d = d[(d.re78 > 0) & (d.re75 > 0)]
y = np.log(d.re78).to_numpy()
x = d.education.to_numpy(dtype=float)
W = np.column_stack([np.ones(len(d)), d.age, d.age**2, d.black, d.hispanic, d.married])
def resid(v, M):
"""Residual of v after least squares on the columns of M."""
return v - M @ np.linalg.lstsq(M, v, rcond=None)[0]
b_long = np.linalg.lstsq(np.column_stack([x, W]), y, rcond=None)[0][0]
rx = resid(x, W)
ry = resid(y, W)
b_fwl = (rx @ ry) / (rx @ rx)
b_half = (rx @ y) / (rx @ rx)
b_short = np.linalg.lstsq(np.column_stack([np.ones(len(d)), x]), y, rcond=None)[0][1]
print(f"long regression: {b_long:.6f}")
print(f"residual on residual: {b_fwl:.6f}")
print(f"y on residualised x: {b_half:.6f}")
print(f"education alone (no controls): {b_short:.6f}")
print(f"variance of x {x.var():.3f}; of its residual {rx.var():.3f}")
$ python fwl.py
long regression: 0.038343
residual on residual: 0.038343
y on residualised x: 0.038343
education alone (no controls): 0.040973
variance of x 8.101; of its residual 7.117
30.4 The omitted-variable bias formula
Definition 30.6 (Omitted-variable bias)
Omitted-variable bias is the difference between the coefficient on a regressor in a regression that leaves out a variable and the coefficient in the regression that includes it.
Let the long regression be and the short one leave out. Let be the coefficient on when itself is regressed on and . Then, exactly in any sample,
Proof: regress both sides of on and . Least squares is linear in the outcome, the regression of and of on themselves gives coefficient one on themselves, is orthogonal to and so its coefficients are zero, and gives on (Exercise 11).
The formula needs only two signs: the effect of the omitted variable on the outcome and its association with the regressor.
| and positively associated () | negatively associated () | |
|---|---|---|
| raises () | short coefficient too high | short coefficient too low |
| lowers () | short coefficient too low | short coefficient too high |
"""The omitted-variable bias formula, short = long + gamma delta."""
import numpy as np
from econdata import nsw
d = nsw("cps_controls")
d = d[(d.re78 > 0) & (d.re75 > 0)]
y = np.log(d.re78).to_numpy()
z = np.log(d.re75).to_numpy() # the variable left out of the short regression
W = np.column_stack([np.ones(len(d)), d.education, d.age, d.age**2, d.black,
d.hispanic, d.married]) # fmt: skip
def ols(target, M):
return np.linalg.lstsq(M, target, rcond=None)[0]
short = ols(y, W)[1]
full = ols(y, np.column_stack([W, z]))
long, gamma = full[1], full[-1]
delta = ols(z, W)[1]
print(f"short regression (no 1975 earnings): {short:.6f}")
print(f"long regression: {long:.6f}")
print(f"gamma, effect of log 1975 earnings: {gamma:.6f}")
print(f"delta, 1975 earnings on education: {delta:.6f}")
print(f"long + gamma * delta: {long + gamma * delta:.6f}")
print("equal to 1e-12:", abs(short - long - gamma * delta) < 1e-12)
$ python ovb.py
short regression (no 1975 earnings): 0.038343
long regression: 0.020429
gamma, effect of log 1975 earnings: 0.399801
delta, 1975 earnings on education: 0.044806
long + gamma * delta: 0.038343
equal to 1e-12: True
A man with 1 per cent higher earnings in 1975, at the same schooling, age, race and marriage, earns 0.40 per cent more in 1978; and a year of schooling goes with 4.5 per cent higher 1975 earnings. The product, 1.8 points, is the part of the schooling coefficient that 1975 earnings take over. Whether it should be taken over is another matter: 1975 earnings are themselves partly a result of schooling, so controlling for them removes part of the effect being measured.
30.5 Near-collinear regressors
Definition 30.7 (Perfect collinearity)
Regressors are perfectly collinear when one column of is an exact linear combination of the others; then has rank below , is singular, and the coefficients are not identified.
A common case is a full set of indicator variables with a constant: an indicator for married men, one for unmarried men, and the column of ones, which is their sum. Near-collinearity is not a failure of the assumptions, but it costs precision. Under the assumptions of Chapter 31, with the of the regression of on the other regressors and the sample variance of ,
The formula follows from the Frisch–Waugh–Lovell theorem: is a regression on , whose sum of squares is (Exercise 12).
Definition 30.8 (Variance inflation factor)
The variance inflation factor of regressor is : the factor by which the variance of exceeds what it would be if were uncorrelated with the other regressors.
"""Near-collinear regressors: the standard error of b1 as the correlation rises."""
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(30)
n = 500
print(" rho corr in sample b1 se(b1) VIF")
for rho in (0.0, 0.5, 0.9, 0.99):
x1 = rng.standard_normal(n)
x2 = rho * x1 + np.sqrt(1 - rho**2) * rng.standard_normal(n)
y = 1 + x1 + x2 + rng.standard_normal(n)
fit = sm.OLS(y, sm.add_constant(np.column_stack([x1, x2]))).fit()
r = np.corrcoef(x1, x2)[0, 1]
vif = 1 / (1 - r**2)
print(f"{rho:5.2f} {r:14.3f} {fit.params[1]:6.3f} {fit.bse[1]:7.3f} {vif:6.1f}")
x1 = rng.standard_normal(n)
X = np.column_stack([np.ones(n), x1, 2 * x1])
print(f"rank of X with x2 = 2 x1: {np.linalg.matrix_rank(X)} of {X.shape[1]} columns")
$ python collinearity.py
rho corr in sample b1 se(b1) VIF
0.00 -0.028 1.002 0.045 1.0
0.50 0.538 0.934 0.057 1.4
0.90 0.906 1.019 0.103 5.6
0.99 0.990 1.123 0.311 48.5
rank of X with x2 = 2 x1: 2 of 3 columns
At a correlation of 0.99 the variance inflation factor is 48.5 and the standard error of is 0.311, about seven times the 0.045 of uncorrelated regressors; the estimate itself is still unbiased. Near-collinearity is a shortage of information about the separate effects, not an error to be corrected; the remedies are more data or a question that does not need the separate effects.
30.6 Fit
The of a multiple regression is , as with one regressor. Adding a regressor never lowers it, since least squares could always set the new coefficient to zero.
Definition 30.9 (Adjusted R-squared)
The adjusted is ; it can fall when a regressor is added.
In the listing is 0.1181 and 0.1177: with 13,055 observations and seven coefficients the correction is tiny. Neither number says whether the coefficient on schooling is the effect of schooling. Adding 1975 earnings raises from 0.118 to 0.254 and moves the schooling coefficient from 3.83 to 2.04; a better fit is not a better answer to a causal question.
Model — The linear regression model
Assumes. The conditional mean of the outcome is linear in the regressors; the regressor matrix has full column rank; the error has mean zero given the regressors.
Predicts. Least squares estimates each coefficient without bias: the change in the mean outcome when one regressor rises by one and the others are held fixed.
Tested. Linearity can be checked against more flexible forms (Chapter 32); the zero conditional mean assumption cannot be tested from the residuals, which are orthogonal to the regressors by construction, but can be tested against an experiment, as LaLonde did (Chapter 33).
Breaks. When a variable that affects the outcome and is correlated with a regressor is left out, the coefficient absorbs its effect, by the amount ; and when a control is itself an outcome of the regressor, holding it fixed removes part of the effect.
30.7 Exercises
Exercise 30.1 ★
Read the opening chart. Give the estimate with no control, after adding age, and with every control. Which single step moves the estimate most?
Solution
Solution of Exercise 30.1.
4.10 per cent with no control, 5.22 after adding age, 2.04 with every control. The largest single move is the last, adding log 1975 earnings: from 3.83 to 2.04, 1.79 points; adding age squared moves it 1.23 points, adding age 1.12.
Exercise 30.2 ★
A quarter of the men have 1978 earnings at the cap. What does the cap do to the measured differences in log earnings between men with much schooling and men with little?
Solution
Solution of Exercise 30.2.
Men above the cap are recorded at the cap, so high earners appear to earn less than they do. Men with much schooling are more often above the cap, so the cap compresses the gap between them and men with little schooling: the measured return to schooling is likely too small.
Exercise 30.3 ★
Compute from , and .
Solution
Solution of Exercise 30.3.
.
Exercise 30.4 ★
1975 earnings are measured after most of the men had finished school. Why might controlling for them be a mistake? What would show that a control is a bad one?
Solution
Solution of Exercise 30.4.
Schooling raises 1975 earnings, and 1975 earnings predict 1978 earnings. Holding 1975 earnings fixed compares men with different schooling but the same 1975 earnings, which removes the part of the effect of schooling that works through earlier earnings. A control is bad if it is itself affected by the regressor: evidence would be that the regressor predicts the control (here a year of schooling goes with 4.5 per cent higher 1975 earnings), or, better, that the control was measured after the regressor was set.
Exercise 30.5 ★★
By hand: with five observations, , and , regress on a constant, and . Write and , solve the normal equations, and compute and .
Solution
Solution of Exercise 30.5.
, . The solution is : check , , . Fitted values ; residuals , so . With , , so and .
Exercise 30.6 ★★
Predict, then compute: adding age raises the schooling coefficient from 4.10 to 5.22. The correlation between age and schooling in the sample is ; age has a coefficient of 0.0192 in the long regression, and the regression of age on schooling has slope . Check the omitted-variable bias formula.
Solution
Solution of Exercise 30.6.
Earnings rise with age () and older men have less schooling (), so leaving age out biases the schooling coefficient down. The formula: , the short coefficient.
Exercise 30.7 ★★
(D) (a) With the Brenland household survey, regress the log gross income of heads with positive income on years of schooling, then add age and age squared. (b) With the CPS sample, add nodegree to the regression of the listing ols_by_hand.py. What happens to the schooling coefficient, its standard error, and its variance inflation factor?
Solution
Solution of Exercise 30.7.
(a) 5.80 per cent per year of schooling with no control, ; 5.84 per cent with age and age squared, . (b) With nodegree the schooling coefficient falls from 3.83 to 2.16 per cent; men without a diploma earn 14.8 log points less at the same years of schooling. The standard error rises from 0.0028 to 0.0039, and the VIF of schooling from 1.14 to 2.24: years of schooling and having a diploma are strongly related.
Exercise 30.8 ★★
Change to 2000 in the collinearity listing. By what factor should the standard errors fall? Compare with the output.
Solution
Solution of Exercise 30.8.
By (30.2) the standard error falls as : by a factor of 2. The output gives 0.022, 0.025, 0.052 and 0.160 against 0.045, 0.057, 0.103 and 0.311. The ratios are close to 2, though not exactly, because new draws give new sample correlations.
Exercise 30.9 ★★
A regression includes a constant, an indicator for married men and an indicator for unmarried men. Show that does not have full column rank. Give two ways to fix it, and say what the coefficients then mean.
Solution
Solution of Exercise 30.9.
The column of ones equals the sum of the two indicators, so the three columns are linearly dependent and the rank is 2. Either drop one indicator: the constant is then the mean for the omitted group (other regressors fixed) and the remaining coefficient the difference between the groups. Or drop the constant: each indicator’s coefficient is its group’s mean.
Exercise 30.10 ★★★
Show that is symmetric and idempotent, that , and that is the residual vector of the regression of on .
Solution
Solution of Exercise 30.10.
Let . Then , since is symmetric, and
So is symmetric and . . The regression of on has coefficients and fitted values , so its residual is .
Exercise 30.11 ★★★
Prove (30.1) in full.
Solution
Solution of Exercise 30.11.
Let and , so that the short regression’s coefficients are . From the long regression, , where collects and . Then , since and . The first element of is , so .
Exercise 30.12 ★★★
Using the Frisch–Waugh–Lovell theorem and , derive (30.2).
Solution
Solution of Exercise 30.12.
By the theorem with , a function of only. With , (since is orthogonal to the other columns), and . So and . The sum of squared residuals of on the others is .
30.8 Problem: Brenland’s household survey
Problem 30.1
Weekend problem — Brenland’s household survey: matrices, the return to schooling with controls, partialling out and omitted-variable bias, and the collinearity of age and experience
Brenland’s household survey of 2025 has 2,000 households; 1,922 heads have positive gross income. Let be the log gross income of head , his years of schooling and his age.
Part I — Matrices.
- Write the regressor matrix of the regression of on a constant, , and : its size and a typical row.
- What is the size of ? Of ?
- What does the first element of count? The first element of ?
- Why must be invertible for the estimator to exist?
- What does the first normal equation say about the residuals?
Part II — Returns to schooling with controls.
- Regress on a constant and . Give the coefficient on and .
- Add and . Give the coefficient on , its 95 per cent confidence interval, and .
- Interpret the coefficient on in the long regression.
- At what age is predicted income highest, holding schooling fixed?
- Why does the coefficient on barely move?
Part III — Partialling out and omitted-variable bias.
- Regress on a constant, and , and keep the residual . Compare the variances of and .
- Regress on . What coefficient do you get?
- Give and , the coefficients on when and are regressed on a constant and .
- Write the short coefficient as the long one plus the bias, with two omitted variables.
- Compute the bias and check the identity.
- Why are and so different in size, and yet give a bias near zero?
Part IV — Collinearity of age and experience.
- Define experience as . Regress on a constant, , and experience. What goes wrong?
- Give the rank of the regressor matrix.
- Which combinations of the coefficients can still be estimated?
- Give the variance inflation factors of , and in the regression of Part II.
- Why is the high VIF of and no problem for the coefficient on ?
- With half the sample, by what factor would the standard error of the schooling coefficient grow?
- If ability raised income and was positively correlated with schooling, which way would the estimate be biased?
- Could controlling for hours worked fix that bias? Could it create another?
- State the result: the return to schooling with its interval, and the size of the omitted-variable bias from age.
Solution
Solution of Problem 30.1.
Part I. 1. is ; row is . 2. ; . 3. The number of heads, 1,922; the sum of . 4. The estimator is ; if is singular some coefficients are not identified. 5. The residuals sum to zero. Part II. 6. 0.0580; . 7. 0.0584, interval 0.0518 to 0.0649; , . 8. Among heads of the same age, a year more schooling goes with gross income about 5.8 per cent higher. 9. The coefficients are 0.0724 on and on ; the peak is at years. 10. In the survey schooling and age are almost uncorrelated, so leaving age out removes little. Part III. 11. The variance of is 6.728, of 6.712: age predicts almost none of schooling. 12. 0.0584, the long coefficient, as the theorem says. 13. and . 14. . 15. ; , the short coefficient. 16. is measured in squared years, so its coefficients are small and its large; the two terms have opposite signs and nearly cancel. Part IV. 17. Experience is an exact linear combination of the constant, and : has rank 3 with 4 columns, and the coefficients are not identified. 18. 3. 19. Only combinations such as and : the effect of schooling at a given age, or of age at given schooling; never the three separately. 20. 1.00 for , 43.5 for and for . 21. The VIF of is 1.00: is almost uncorrelated with and , and its variance does not depend on how well and can be told apart. 22. By about . 23. Upwards: and . 24. No: hours do not measure ability. They may be a bad control, since schooling may change hours worked. 25. The return to a year of schooling in Brenland is 5.84 per cent (95 per cent interval 5.18 to 6.49) holding age fixed; leaving age out changes it by points, because age and schooling are almost uncorrelated in the survey.