यह किताब अभी हिन्दी में उपलब्ध नहीं है। संस्करण: English।
University Economics — Year 1 · स्नातक वर्ष 1
32Simple Regression
Among the 2,204 men of the PSID sample with positive earnings in 1978, each extra year of schooling goes with log earnings higher by : about more earnings. Does a year of school raise earnings by ? The line through the data does not say. This chapter builds the line — least squares — and shows how to read it, how precise it is, when it estimates what we want, and two reasons, regression toward the mean and omitted variables, why it often does not.
The means rise with schooling and lie close to the line; the line explains of the variance of log earnings across men, and the rest is everything else.
You already know
Covariance, correlation and conditional means are Chapter 29; conditional expectation and its best-predictor property, Chapter 30; standard errors and tests, Chapter 31. That a correlation is not a cause was met at school.
How it is measured — Earnings in the PSID and CPS samples
The two samples are comparison groups drawn from two large US surveys and assembled to evaluate a job-training experiment (LaLonde 1986; Dehejia and Wahba 1999): men’s earnings in 1974, 1975 and 1978, in dollars of 1982, with age, schooling and a few other traits.
The CPS sample’s earnings are capped (Chapter 29); the PSID sample’s are not.
32.1 The conditional expectation function and its best line
Definition 32.1 (Population regression line)
The population regression line, or best linear predictor, of given is the line that minimises over and .
Proposition 32.2 (Its coefficients)
and .
Proof. Setting the derivatives with respect to and to zero gives and . The first gives . Substituting it into the second, , that is . The function is convex in , so this is the minimum. ∎
The conditional expectation function is the best predictor of all (Proposition 30.5); the regression line is the best straight line. When the conditional expectation function is a line, the two coincide; otherwise the line is the best linear approximation to it, as in the opening chart.
32.2 Least squares
Definition 32.3 (Ordinary least squares estimator)
The ordinary least squares (OLS) estimator of the line in a sample minimises ; it is
the sample analogue of Proposition 32.2.
Definition 32.4 (Fitted value, residual)
The fitted value of observation is ; its residual is .
Proposition 32.5 (Residuals)
and : the residuals have mean zero and are uncorrelated with in the sample.
Proof. These are the two first-order conditions of the minimisation, and . Since the residuals sum to zero, their sample covariance with is . ∎
"""Least squares by hand: log earnings on years of schooling, PSID sample."""
import numpy as np
from econdata import nsw
d = nsw("psid_controls").query("re78 > 0") # the log needs positive earnings
x, y = d.education.to_numpy(float), np.log(d.re78.to_numpy())
b1 = ((x - x.mean()) * (y - y.mean())).sum() / ((x - x.mean()) ** 2).sum()
b0 = y.mean() - b1 * x.mean()
resid = y - (b0 + b1 * x)
print(f"n {len(y)}; slope {b1:.4f}; intercept {b0:.4f}")
print(f"sum of residuals {resid.sum():.2e}")
print(f"sum of x times residuals {(x * resid).sum():.2e}")
$ python ols_by_hand.py
n 2204; slope 0.0885; intercept 8.8172
sum of residuals -1.65e-12
sum of x times residuals -1.96e-11
"""The same regression with statsmodels."""
import numpy as np # noqa: F401 -- np.log is used inside the formula strings
import statsmodels.formula.api as smf
from econdata import nsw
d = nsw("psid_controls").query("re78 > 0")
fit = smf.ols("np.log(re78) ~ education", data=d).fit()
print(fit.summary().tables[1])
print(f"R-squared {fit.rsquared:.4f}; observations {int(fit.nobs)}")
$ python ols_statsmodels.py
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
Intercept 8.8172 0.061 143.914 0.000 8.697 8.937
education 0.0885 0.005 18.172 0.000 0.079 0.098
==============================================================================
R-squared 0.1304; observations 2204
32.3 Reading a slope
The slope’s meaning depends on whether each variable enters in levels or in logarithms. With and in levels, one more unit of goes with per cent more (approximately, for small ; exactly ). With and , more goes with more units of . With both in logs, is an elasticity: more goes with per cent more .
"""Four functional forms on one pair of variables, and how to read each slope."""
import numpy as np # noqa: F401 -- np.log is used inside the formula strings
import statsmodels.formula.api as smf
from econdata import nsw
d = nsw("psid_controls").query("re78 > 0 and education > 0")
forms = {
"re78 ~ education": "dollars per year of schooling",
"np.log(re78) ~ education": "x 100: per cent per year of schooling",
"re78 ~ np.log(education)": "/ 100: dollars per 1% more schooling",
"np.log(re78) ~ np.log(education)": "elasticity: % per 1% more schooling",
}
for formula, reading in forms.items():
slope = smf.ols(formula, data=d).fit().params.iloc[1]
print(f"{formula:34s} {slope:10.4f} {reading}")
$ python reading_slopes.py
re78 ~ education 1849.0325 dollars per year of schooling
np.log(re78) ~ education 0.0875 x 100: per cent per year of schooling
re78 ~ np.log(education) 16832.1165 / 100: dollars per 1% more schooling
np.log(re78) ~ np.log(education) 0.8315 elasticity: % per 1% more schooling
32.4 Fit
Definition 32.6 (Coefficient of determination)
The coefficient of determination is : the share of the sample variance of that the fitted values reproduce. In a simple regression it equals the squared correlation of and .
"""R-squared three ways."""
import numpy as np
import statsmodels.formula.api as smf
from econdata import nsw
d = nsw("psid_controls").query("re78 > 0")
y = np.log(d.re78)
fit = smf.ols("np.log(re78) ~ education", data=d).fit()
tss = ((y - y.mean()) ** 2).sum()
print(f"squared correlation {np.corrcoef(d.education, y)[0, 1] ** 2:.6f}")
print(
f"explained / total {((fit.fittedvalues - y.mean()) ** 2).sum() / tss:.6f}"
)
print(f"1 - residual / total {1 - (fit.resid**2).sum() / tss:.6f}")
$ python r_squared.py
squared correlation 0.130406
explained / total 0.130406
1 - residual / total 0.130406
A low says that leaves much of the variation in unexplained; it does not say that the slope is small, badly estimated or unimportant. Schooling explains of the variance of log earnings, and the slope is still measured with a statistic of 18.
32.5 When is the slope unbiased?
Definition 32.7 (Error term)
In the model , the error term collects everything other than that affects . For observation it is , unobserved; the residual is its estimate.
Definition 32.8 (Zero conditional mean assumption)
The zero conditional mean assumption is : whatever the value of , the other influences on average to zero.
Model — The simple linear regression model
Assumes. with ; a random sample ; some variation in .
Predicts. is unbiased for , with the standard error of Proposition 32.10 when the variance of does not depend on .
Tested. Consistent with the published estimates: the log-earnings slope of is close to those of studies that do not rest on the zero-conditional-mean assumption (the record Returns to schooling below).
Breaks. When ability or family background are in and also move schooling (the third university year returns to schooling with instruments), or when is measured with error (second university year).
Proposition 32.9 (Unbiasedness)
Under the model’s assumptions, .
Proof. Substituting into gives , since . Given the , the weights are numbers and by random sampling and the zero conditional mean assumption, so the second term has expectation zero. ∎
Proposition 32.10 (Standard error of the slope)
If moreover , then , and the standard error is estimated by with .
Proof. Admitted at this level. ∎
The variance follows from the expression for in the previous proof; the and the case of a variance that changes with are derived in the second university year.
"""The standard error of the slope by the formula, and a t test of the slope."""
import numpy as np
import statsmodels.formula.api as smf
from econdata import nsw
d = nsw("psid_controls").query("re78 > 0")
fit = smf.ols("np.log(re78) ~ education", data=d).fit()
x, n = d.education, len(d)
s2 = (fit.resid**2).sum() / (n - 2) # the error variance, n - 2 degrees of freedom
se = np.sqrt(s2 / ((x - x.mean()) ** 2).sum())
print(f"formula {se:.6f}; statsmodels {fit.bse['education']:.6f}")
print(f"t for slope = 0: {fit.params['education'] / se:.1f}")
print(f"t for slope = 0.10: {(fit.params['education'] - 0.10) / se:.2f}")
$ python slope_se.py
formula 0.004870; statsmodels 0.004870
t for slope = 0: 18.2
t for slope = 0.10: -2.36
32.6 Regression toward the mean
Definition 32.11 (Regression toward the mean)
Regression toward the mean is the tendency of units with extreme values of a variable at one date to have values closer to the mean at another, whenever the two are imperfectly correlated: with equal variances, the slope of one on the other is .
"""Earnings in 1978 on earnings in 1975, and the reverse regression."""
import statsmodels.formula.api as smf
from econdata import nsw
d = nsw("psid_controls")
forward = smf.ols("re78 ~ re75", data=d).fit().params["re75"]
backward = smf.ols("re75 ~ re78", data=d).fit().params["re78"]
r = d.re75.corr(d.re78)
print(f"1978 on 1975: slope {forward:.4f}")
print(f"1975 on 1978: slope {backward:.4f}")
print(f"product {forward * backward:.4f}; r squared {r**2:.4f}")
top = d.re75 >= d.re75.quantile(0.9)
print(
f"top tenth in 1975: mean {d.re75[top].mean():,.0f} then {d.re78[top].mean():,.0f}"
)
$ python toward_mean.py
1978 on 1975: slope 0.8368
1975 on 1978: slope 0.6394
product 0.5350; r squared 0.5350
top tenth in 1975: mean 46,368 then 45,253
Average earnings rose between the two years, yet the gains were largest at the bottom, and in the highest bins they mostly turned into losses (three of the five bins above 30,000 dollars lost): the men of the lowest bin went from 946 to 6,525 dollars on average, those of the highest from 52,086 to 47,719. Nothing pulled them together. A man’s earnings in one year combine a lasting part and a transitory part; men selected for high 1975 earnings include many with a lucky year, which does not repeat. Reverse the regression and the same happens backwards: the slope of 1975 on 1978 is also below one.
On the record — The regression fallacy
In 1933 a book claimed that business enterprises were converging towards the average: groups of firms ranked by their first-year value moved towards the average. A review answered that ranked by their last-year value the lines would diverge, and that the real test of convergence is a consistent decline in the variance among individual enterprises. Friedman (1992) quotes the review and finds the same fallacy in comparisons of countries’ growth sixty years later.
32.7 A regression is not a cause
Definition 32.12 (Omitted variable, confounder)
An omitted variable, or confounder, is a variable left out of the regression that affects and is correlated with . It sits in and breaks the zero conditional mean assumption.
"""An omitted variable: ability raises both schooling and earnings (simulated)."""
import numpy as np
rng = np.random.default_rng(2026)
slopes_short, slopes_long = [], []
for _ in range(1_000):
ability = rng.standard_normal(500)
school = 12 + 1.5 * ability + rng.normal(0, 2, 500)
log_y = 9 + 0.06 * school + 0.10 * ability + rng.normal(0, 0.5, 500)
slopes_short.append(np.polyfit(school, log_y, 1)[0]) # ability left out
X = np.column_stack([np.ones(500), school, ability])
slopes_long.append(np.linalg.lstsq(X, log_y, rcond=None)[0][1])
print("true effect of a year of school: 0.060")
print(f"slope, ability left out: mean {np.mean(slopes_short):.4f}")
print(f"slope, ability included: mean {np.mean(slopes_long):.4f}")
print(f"predicted bias 0.10 * 1.5 / (1.5**2 + 2**2) = {0.10 * 1.5 / 6.25:.4f}")
$ python omitted.py
true effect of a year of school: 0.060
slope, ability left out: mean 0.0839
slope, ability included: mean 0.0601
predicted bias 0.10 * 1.5 / (1.5**2 + 2**2) = 0.0240
The bias is the omitted variable’s effect on times the slope of the omitted variable on : . The second university year derives this formula in general.
Definition 32.13 (Reverse causation)
There is reverse causation when affects , so that a slope of on mixes the effect of on with the effect of on .
"""Supply and demand shocks: the price-quantity slope is neither curve's (simulated)."""
import numpy as np
rng = np.random.default_rng(2026)
n = 10_000
u_d, u_s = rng.normal(0, 1, n), rng.normal(0, 2, n) # demand and supply shocks
# demand q = 10 - p + u_d and supply q = 2 + p + u_s, solved for the market
p = (8 + u_d - u_s) / 2
q = (12 + u_d + u_s) / 2
print("demand slope -1, supply slope +1")
print(f"regression of quantity on price: slope {np.polyfit(p, q, 1)[0]:.3f}")
$ python reverse.py
demand slope -1, supply slope +1
regression of quantity on price: slope -0.599
Price and quantity are set together by supply and demand. Regressing one on the other gives a mixture of the two curves, weighted by which one the shocks moved more. In this market the supply shocks have twice the standard deviation of the demand shocks, so the points trace out mainly the demand curve, and the slope is .
"""The same regression on the top-coded CPS sample."""
import numpy as np # noqa: F401 -- np.log is used inside the formula strings
import statsmodels.formula.api as smf
from econdata import nsw
for name in ("psid_controls", "cps_controls"):
d = nsw(name).query("re78 > 0")
b = smf.ols("np.log(re78) ~ education", data=d).fit().params["education"]
at_cap = (d.re78 == d.re78.max()).mean()
print(f"{name:14s} n {len(d):6d} slope {b:.4f} share at the maximum {at_cap:.3f}")
# The cap alone, in one sample: cap the PSID men at the CPS maximum.
cap = nsw("cps_controls").re78.max()
p = (
nsw("psid_controls")
.query("re78 > 0")
.assign(capped=lambda x: x.re78.clip(upper=cap))
)
b = smf.ols("np.log(capped) ~ education", data=p).fit().params["education"]
share = (p.re78 > cap).mean()
print(f"PSID capped at {cap:,.2f}: slope {b:.4f}, share capped {share:.3f}")
$ python cps_cap.py
psid_controls n 2204 slope 0.0885 share at the maximum 0.000
cps_controls n 13820 slope 0.0433 share at the maximum 0.300
PSID capped at 25,564.70: slope 0.0621, share capped 0.407
Data problems bias slopes too. In the CPS sample of the men with earnings sit at the maximum the survey records, and its slope, , is half the PSID’s. But the two samples are different populations, so that comparison mixes the cap with everything else that differs between them. The cap’s own effect is measured within one sample: capping the PSID men at the CPS maximum, which binds for of them, lowers the slope from to . Capping the highest earnings, which are those of the most schooled, flattens the line.
On the record — Returns to schooling
A regression of log earnings on schooling across people gives slopes like the opening chart’s. Card (1999) reviews the attempts to estimate the causal return: studies that use changes in the schooling system as natural experiments find returns – above the corresponding OLS estimates, and studies of twins suggest an upward ability bias of about . The cross-sectional slope is not the causal effect, but for the standard samples of these studies it is not far from it. The next volumes treat experiments, instruments and panels, the tools behind those estimates.
Exercises
Exercise 32.1 ★
Find the OLS slope and intercept for the points , , , , .
Solution
Solution of Exercise 32.1.
, ; and , so and .
Exercise 32.2 ★
From Output 32.2, give the slope, its standard error and .
Exercise 32.3 ★
A regression of log wages on years of experience has a slope of . Interpret it.
Solution
Solution of Exercise 32.3.
One more year of experience goes with wages about higher ( exactly), on average across workers; it is a description, not yet an effect.
Exercise 32.4 ★
Predict the fitted log earnings of a PSID man with 16 years of schooling, and the earnings it corresponds to.
Solution
Solution of Exercise 32.4.
, which corresponds to dollars — a typical (geometric-mean) value, below the mean earnings of such men.
Exercise 32.5 ★★
Prove that the residuals of an OLS regression with an intercept are uncorrelated with the fitted values.
Solution
Solution of Exercise 32.5.
by Proposition 32.5, and the residuals have mean zero, so their sample covariance with is zero.
Exercise 32.6 ★★
Run the regression of log earnings on schooling for PSID men under 30 and for men over 40. Compare the slopes, with their standard errors.
Solution
Solution of Exercise 32.6.
Under 30: 953 men, slope (standard error ). Over 40: 678 men, slope (). The difference, , has a standard error of about : about two standard errors, suggestive but not conclusive.
Exercise 32.7 ★★
Estimate the income elasticity of energy use in 2019 by a log–log regression on the countries of Chapter 3, with its standard error.
Solution
Solution of Exercise 32.7.
183 countries; slope , standard error : more income per person goes with more energy use per person, as Chapter 3 found.
Exercise 32.8 ★★
Family wealth raises both children’s schooling and their later earnings, through contacts. Predict the direction of the bias in the slope of earnings on schooling.
Solution
Solution of Exercise 32.8.
Upward: wealth raises earnings and is positively correlated with schooling, so the slope of earnings on schooling picks up part of wealth’s effect.
Exercise 32.9 ★★
Test at whether the PSID slope equals .
Solution
Solution of Exercise 32.9.
, beyond : the slope is significantly below at .
Exercise 32.10 ★★★
Derive the OLS estimator by minimising the sum of squared residuals, and prove Proposition 32.9 in your own steps.
Solution
Solution of Exercise 32.10.
Setting the derivatives of to zero gives and . The first gives ; substituting into the second and subtracting gives , hence . Unbiasedness: write , so ; given the ’s, each , so the expectation is .
Exercise 32.11 ★★★
Show that the slope of on times the slope of on equals , and use it to explain why both slopes in Output 32.6 are below one.
Solution
Solution of Exercise 32.11.
The two slopes are and ; their product is . With the two cannot both be at least one when the variances are similar; here . Earnings in each year are partly transitory, so each year’s earnings predict the other’s with a slope below one.
Exercise 32.12 ★★★
What evidence would refute reading the slope as the effect of a year of school?
Solution
Solution of Exercise 32.12.
Twins or siblings with different schooling but the same earnings; or a natural experiment — a change in school-leaving rules that raised schooling for some cohorts — with no matching rise in their earnings; or a slope that falls to near zero once measures of ability and family background enter.
32.8 Problem: Schooling and Earnings in Brenland
Problem 32.1
Weekend problem — the Brenland return to a year of school
Brenland’s household survey (invented) records the head’s years of schooling and the household’s gross income. Use the households with positive gross income. Part III uses a simulated cohort with an ability score, written by the same script with a fixed seed: true return , ability effect .
Part I — The regression.
- How many households have positive gross income?
- Give the mean and standard deviation of schooling.
- Regress log gross income on schooling: give the slope and intercept.
- Check that the residuals sum to zero.
- Give the fitted log income at 12 and at 16 years.
- By what factor does fitted income rise from 12 to 16 years?
- Give the slope of income in dalens on schooling.
Part II — Reading, fit and precision.
- Interpret the slope of item 3.
- Give the exact percentage it implies.
- Give .
- Does a low mean that schooling matters little for income?
- Give the standard error and the statistic of the slope.
- Give a interval.
- Test whether the slope equals .
Part III — Hidden ability (simulated cohort).
- Give the slope of ability on schooling.
- Give the slope of log income on schooling alone.
- Give the slopes of schooling and ability when both enter.
- Check that the short slope minus the long one equals the ability coefficient times the slope of item 15.
- By how much does the short slope overstate the true ?
- Why is the bias upward?
- Could the survey’s slope of item 3 be biased in the same way?
Part IV — A second variable (reported, not solved).
- Add the head’s age to the regression: give the new schooling slope.
- Give the age coefficient.
- Give the correlation of schooling and age, and say why the slope barely moves.
- When would adding a variable change the slope a lot?
- State the result.
Solution
Solution of Problem 32.1.
1. 1,922.
2. Mean years, standard deviation .
3. Slope , intercept .
4. The sum is : zero up to rounding error.
5. and .
6. : higher.
7. 1,841 dalens per year of schooling.
8. A year more of the head’s schooling goes with about more household income.
9. .
10. .
11. No: it means schooling leaves most of the variation unexplained; the slope is precisely estimated (item 12).
12. ; .
13. to .
14. : rejected.
15. .
16. .
17. Schooling , ability .
18. .
19. By (from to ).
20. Ability raises income and goes with more schooling, so the short regression credits schooling with part of ability’s effect.
21. Yes, if anything that raises income is also correlated with schooling; the survey has no ability measure to check.
22. .
23. : less income per year of age, schooling held fixed.
24. : age is almost uncorrelated with schooling, so leaving it out biases the slope very little.
25. When the variable both affects income and is correlated with schooling, like ability in Part III; this is what multiple regression in the second university year handles.
26. The Brenland return to a year of the head’s schooling is (standard error point) in the survey; if it carried an ability bias of the size simulated in Part III (1.3 points), the causal return would be about .