经济学 · 第 5 册 · 本科三年级

University Economics — Year 3

本书暂未推出简体中文版。现有版本:English。

University Economics — Year 3 · 本科三年级

2Panel Data

Richer countries emit more carbon dioxide per person. Across 200 countries, a country whose income per person is one log point higher emits, on average, 2.7 more tonnes per person. Follow each country over time instead, and the slope shrinks to about one tonne. Both numbers come from the same 6,419 observations. The first compares countries with each other; the second compares each country with itself in other years. They differ because countries differ in many fixed ways — coal under the ground, a cold winter, a car-built city — that go with both their income and their emissions. A data set that follows the same units over time can take those fixed differences out, without measuring them. This chapter is about how, at what price, and what the method cannot remove.

Carbon dioxide emissions per person against income per person, 1990–2022, 200 countries. Left: across countries, each dot a country’s average over the years (GDP per person in constant 2015 dollars, log scale). Right: inside countries, each dot the mean of one twentieth of the 6,419 country-years, after removing each country’s own averages. Lines: least-squares fits. Palau, at 104 tonnes, lies above the left panel’s scale.
Carbon dioxide emissions per person against income per person, 1990–2022, 200 countries. Left: across countries, each dot a country’s average over the years (GDP per person in constant 2015 dollars, log scale). Right: inside countries, each dot the mean of one twentieth of the 6,419 country-years, after removing each country’s own averages. Lines: least-squares fits. Palau, at 104 tonnes, lies above the left panel’s scale. Source: World Bank, World Development Indicators (EN.GHG.CO2.PC.CE.AR5, tonnes of CO2_2 per person; NY.GDP.PCAP.KD); our computation

The left panel is the familiar cross-section. The rich oil producers sit high above the line, and several rich countries with nuclear or hydroelectric power sit below it. The right panel removes every country’s average income and average emissions, so that a country only ever meets itself: a year in which it was ten per cent richer than its own average is compared with its own average emissions. That slope, 1.0, is less than half of the slope across countries, 2.7. Note the horizontal scale of the right panel. Almost all the variation in income is between countries. What is left inside them is a band of a few tenths of a log point, and the within slope is estimated from that narrow band alone.

You already know

The Year 1 volume introduced panel data as a data shape: the same units observed at several dates. The Year 2 volume proved the Frisch–Waugh–Lovell theorem (the coefficient on xx in a regression on xx and WW is the slope of yy on the part of xx that WW does not predict), derived omitted-variable bias, and defined cluster-robust standard errors and the Moulton factor. Chapter 1 met an endogenous regressor and one cure, the instrument.

Notation 2.1 (Symbols of this chapter)

A unit (a country, a firm) is i=1,…,ni = 1, \dots, n and a period t=1,…,Tt = 1, \dots, T; here TT is the length of the panel, not taxes. The unit effect is aia_i and a period effect μt\mu_t. A bar over a variable is its mean over the periods of one unit, xˉi=1T∑txit\bar x_i = \frac1T \sum_t x_{it}, and a double dot the deviation from it, x¨it=xit−xˉi\ddot x_{it} = x_{it} - \bar x_i.

2.1 The same units over time

The model of this chapter is

yit=βxit+ai+uit,E[uit∣xi1,…,xiT,ai]=0.(2.1)y_{it} = \beta x_{it} + a_i + u_{it}, \qquad \E[u_{it} \mid x_{i1}, \dots, x_{iT}, a_i] = 0.\tag{2.1}

The unit effect aia_i collects everything about unit ii that does not change over the panel and affects yy. It is not observed. It may be correlated with xx, and in most applications it is: the reason to use a panel is that it is. The condition on uitu_{it}, called strict exogeneity, says that the remaining error is unrelated to the regressor in every period, past and future.

Definition 2.2 (Pooled regression)

The pooled regression is the OLS regression of yity_{it} on xitx_{it} (and a constant) over all nTnT observations, ignoring which unit each comes from.

The pooled regression leaves aia_i in its error. By the omitted-variable formula, its slope converges to β+Cov⁡(xit,ai)/Var⁡(xit)\beta + \Cov(x_{it}, a_i)/\Var(x_{it}). The figure below shows the pattern with three units: within each unit the relation has slope β\beta, but the units with high xx also have high aia_i, and the pooled line, steeper than any of them, joins the clouds.

Three units with the same slope and different intercepts a_i. The units with larger x have larger a_i, so the pooled line (dashed) is steeper than the slope inside every unit.
Three units with the same slope and different intercepts aia_i. The units with larger xx have larger aia_i, so the pooled line (dashed) is steeper than the slope inside every unit.

2.2 Fixed effects

Definition 2.3 (Unit fixed effect, within estimator)

In model (2.1), treating aia_i as a parameter to be estimated for each unit makes it a unit fixed effect. The within estimator (or fixed-effects estimator) of β\beta is the OLS slope of the deviations y¨it\ddot y_{it} on the deviations x¨it\ddot x_{it}:

β^FE=∑i∑tx¨it y¨it∑i∑tx¨it2.\hat\beta_{\mathrm{FE}} = \frac{\sum_i \sum_t \ddot x_{it}\, \ddot y_{it}}{\sum_i \sum_t \ddot x_{it}^2}.

Averaging model (2.1) over tt gives yˉi=βxˉi+ai+uˉi\bar y_i = \beta \bar x_i + a_i + \bar u_i; subtracting it from the model removes aia_i: y¨it=βx¨it+u¨it\ddot y_{it} = \beta \ddot x_{it} + \ddot u_{it}. Under strict exogeneity, u¨it\ddot u_{it}, which contains uˉi\bar u_i and hence the errors of every period, is uncorrelated with x¨it\ddot x_{it}, and the within estimator is consistent as nn grows. Whatever aia_i is, and however it is related to xx, it is gone.

Proposition 2.4 (Within estimator and unit dummies)

The within estimator equals the coefficient on xitx_{it} in the OLS regression of yity_{it} on xitx_{it} and nn unit dummies dit(1),…,dit(n)d^{(1)}_{it}, \dots, d^{(n)}_{it}, where dit(j)=1d^{(j)}_{it} = 1 if i=ji = j.

Proof. By the Frisch–Waugh–Lovell theorem, the coefficient on xx is the slope of yy on the residual of xx after a regression of xx on the dummies. Regressing on the dummies fits one constant per unit, and the least-squares constant for unit ii is the unit’s mean, xˉi\bar x_i. The residual is xit−xˉi=x¨itx_{it} - \bar x_i = \ddot x_{it}. The theorem also allows yy to be replaced by its own residual, y¨it\ddot y_{it}, so the coefficient is ∑x¨ity¨it/∑x¨it2\sum \ddot x_{it} \ddot y_{it} / \sum \ddot x_{it}^2. ∎

The dummies give the same slope with nn more parameters; the within transform gives it without them. Either way, the degrees of freedom of the residual variance are nT−n−1nT - n - 1, a point that software using the transform must handle.

Definition 2.5 (First-difference estimator)

The first-difference estimator of β\beta is the OLS slope of Δyit=yit−yi,t−1\Delta y_{it} = y_{it} - y_{i,t-1} on Δxit=xit−xi,t−1\Delta x_{it} = x_{it} - x_{i,t-1}, for t=2,…,Tt = 2, \dots, T.

Differencing also removes aia_i. With two periods the two estimators are identical (Exercise 2.10). With more, they weight the data differently and are both consistent under strict exogeneity; they differ when the errors are serially correlated, when xx is measured with error, and when the model is wrong. A gap between them is a warning worth reading.

Definition 2.6 (Two-way fixed effects)

The two-way fixed effects model adds a period effect to model (2.1): yit=βxit+ai+μt+uity_{it} = \beta x_{it} + a_i + \mu_t + u_{it}. It is estimated with unit and period dummies, or, in a balanced panel, by the slope of yit−yˉi−yˉt+yˉy_{it} - \bar y_i - \bar y_t + \bar y on the same transform of xx.

Listing 2.1 computes the slopes behind the opening chart.

"""Carbon dioxide and income: pooled, between, within and two-way slopes."""
import numpy as np
import statsmodels.formula.api as smf
from econdata import wdi

co2 = wdi("EN.GHG.CO2.PC.CE.AR5", since=1990, until=2022, countries_only=True)
gdp = wdi("NY.GDP.PCAP.KD", since=1990, until=2022, countries_only=True)
d = co2.merge(gdp, on=["iso3", "year"], suffixes=("_co2", "_gdp"))
d = d.rename(columns={"value_co2": "co2"}).dropna(subset=["co2", "value_gdp"])
d["ly"] = np.log(d.value_gdp)
print(f"countries {d.iso3.nunique()}, country-years {len(d)}")

pooled = smf.ols("co2 ~ ly", d).fit().params["ly"]
means = d.groupby("iso3")[["co2", "ly"]].mean()
between = smf.ols("co2 ~ ly", means).fit().params["ly"]
w = d[["co2", "ly"]] - d.groupby("iso3")[["co2", "ly"]].transform("mean")
within = (w.ly @ w.co2) / (w.ly @ w.ly)
dummies = smf.ols("co2 ~ ly + C(iso3)", d).fit().params["ly"]
twoway = smf.ols("co2 ~ ly + C(iso3) + C(year)", d).fit().params["ly"]

for name, b in [("pooled", pooled), ("between", between), ("within", within),
                ("country dummies", dummies), ("country and year", twoway)]:
    print(f"{name:18s}{b:8.3f}")
share = (w.ly @ w.ly) / ((d.ly - d.ly.mean()) @ (d.ly - d.ly.mean()))
Listing 2.1. Pooled, between, within, dummies and two-way slopes, on the World Development Indicators. code/bachelor-3/02-panel-data/listings/pooled_vs_within.py
$ python pooled_vs_within.py
countries 200, country-years 6419
pooled               2.756
between              2.716
within               0.999
country dummies      0.999
country and year     2.068
share of the variance of log income that is within: 0.036
Output 2.1. Tonnes of CO2_2 per person per log point of income.

The pooled and between slopes are close, 2.756 and 2.716, because most of the variation is between countries; only 3.6 % of the variance of log income is within. The within slope and the slope with 200 country dummies agree to every printed digit, 0.999, as Proposition 2.4 requires. Adding year effects doubles it, to 2.068. The year effects take out what all countries share in a year: world income rose over the period while some large rich emitters cut their emissions per person, so a common time path pulled the one-way within slope down. Which slope answers which question is the subject of Section 2.4.

Model — The fixed-effects model

Assumes. Each unit has a constant unobserved level aia_i, possibly correlated with xx; the slope β\beta is the same for all units; the remaining error is unrelated to the regressor in every period (strict exogeneity).

Predicts. The within and first-difference estimators agree, up to sampling error; adding variables that are fixed for each unit changes nothing; regressing yy on future values of xx gives nothing once current xx is in.

Tested. Not once for all: its predictions are checked in each application, by comparing within, first-difference and two-way estimates and by the lead test of Exercise 2.12. One of its working assumptions has been tested on real data and failed: errors independent over time. In state panels of female wages, placebo laws came out significant far more often than 5 % (Section 2.5; Bertrand, Duflo and Mullainathan 2004).

Breaks. When the confounder changes over time (a new manager, a policy that moves with the business cycle); when today’s xx responds to yesterday’s uu (feedback, as in a dynamic panel, Section 2.6); when the slope differs across units, in which case the within estimator is a weighted average of unit slopes, weighted by each unit’s variance of xx.

2.3 Random effects

The fixed-effects estimator throws away the between variation, which is most of the data. If aia_i were known to be uncorrelated with xx, nothing would need throwing away: the pooled regression would be consistent, but its errors ai+uita_i + u_{it} would be correlated within each unit, and a better estimator would use that structure.

Definition 2.7 (Random-effects estimator)

In model (2.1), suppose aia_i has variance σa2\sigma_a^2, uitu_{it} has variance σu2\sigma_u^2, and both are uncorrelated with each other and with xx. The random-effects estimator is the OLS slope after quasi-demeaning, yit−θyˉiy_{it} - \theta \bar y_i on xit−θxˉix_{it} - \theta \bar x_i (with a constant), where θ=1−σu2/(σu2+Tσa2)\theta = 1 - \sqrt{\sigma_u^2/(\sigma_u^2 + T\sigma_a^2)}, the variances being replaced by estimates.

The weight θ\theta runs from 0, when there is no unit effect and random effects is the pooled regression, to 1, when the unit effect dominates and random effects is the within estimator. It is the generalised least squares estimator for this error structure.

Proof. Admitted at this level. ∎

The proof that quasi-demeaning makes the composite errors uncorrelated with equal variances is a computation with the T×TT \times T covariance matrix σu2I+σa211′\sigma_u^2 I + \sigma_a^2 \mathbf 1 \mathbf 1', found in graduate texts on panel econometrics.

Proposition 2.8 (When random effects is consistent)

Under strict exogeneity of uu, and with θ<1\theta < 1, the random-effects estimator is consistent if Cov⁡(ai,xit)=0\Cov(a_i, x_{it}) = 0 and in general inconsistent otherwise.

Proof. After quasi-demeaning, the error of the transformed model is (1−θ)ai+uit−θuˉi(1 - \theta)a_i + u_{it} - \theta \bar u_i. The terms in uu are uncorrelated with the transformed regressor xit−θxˉix_{it} - \theta \bar x_i by strict exogeneity. The term (1−θ)ai(1 - \theta)a_i is uncorrelated with it if and only if Cov⁡(ai,xit−θxˉi)=0\Cov(a_i, x_{it} - \theta \bar x_i) = 0, which holds when aia_i is uncorrelated with xx in every period. When it is not, the transformed error is correlated with the transformed regressor and the omitted-variable formula gives a bias proportional to 1−θ1 - \theta. ∎

"""Random effects against fixed effects, when the unit effect is and is not
correlated with the regressor (a simulated panel, true slope 1)."""
import numpy as np

rng = np.random.default_rng(3)
n, t = 500, 6


def estimates(link):
    a = rng.normal(0, 1, n)                        # unit effect
    x = link * a[:, None] + rng.normal(0, 1, (n, t))
    y = 1.0 * x + a[:, None] + rng.normal(0, 1, (n, t))
    xw = x - x.mean(1, keepdims=True)              # within transform
    yw = y - y.mean(1, keepdims=True)
    fe = (xw * yw).sum() / (xw * xw).sum()
    e = yw - fe * xw
    s2_u = (e * e).sum() / (n * (t - 1) - 1)       # variance of u
    xb, yb = x.mean(1), y.mean(1)
    bb = np.cov(xb, yb)[0, 1] / np.var(xb, ddof=1)
    s2_bar = np.var(yb - bb * xb, ddof=2)          # variance of a + mean u
    theta = 1 - np.sqrt(s2_u / (t * s2_bar))
    xq = x - theta * x.mean(1, keepdims=True)      # quasi-demeaning
    yq = y - theta * y.mean(1, keepdims=True)
    xq, yq = xq - xq.mean(), yq - yq.mean()
    re = (xq * yq).sum() / (xq * xq).sum()
    return fe, re, theta


print("corr(a, x)   FE      RE      theta")
for link in (0.0, 0.5):
    fe, re, theta = estimates(link)
    corr = link / np.sqrt(link**2 + 1)
    print(f"{corr:8.2f}   {fe:.3f}   {re:.3f}   {theta:.3f}")
Listing 2.2. Random against fixed effects, with and without a correlated unit effect. code/bachelor-3/02-panel-data/listings/random_effects.py
$ python random_effects.py
corr(a, x)   FE      RE      theta
    0.00   0.996   0.999   0.610
    0.45   1.003   1.149   0.467
Output 2.2. True slope 1 in both panels.

With the unit effect unrelated to xx, both estimators find the truth, 0.996 and 0.999. When the correlation is 0.45, the fixed-effects estimate stays at 1.003 and random effects moves to 1.149. The comparison is the logic of the Hausman test: under the null that aia_i is unrelated to xx the two estimates converge to the same value, and a large gap rejects random effects. In observational economics the null rarely survives. A useful compromise, due to Mundlak (1978), adds the unit means xˉi\bar x_i to a random-effects regression; the coefficient on xitx_{it} is then exactly the within estimate, and the coefficient on xˉi\bar x_i measures how far between and within disagree.

2.4 What variation identifies the coefficient

Definition 2.9 (Identifying variation)

The identifying variation of an estimator is the part of the variation of the regressor that the estimator uses: the variation left in xx after the fixed effects and controls are removed, which by the Frisch–Waugh–Lovell theorem is all the slope depends on.

The definition turns a statistical fact into a question about the world. The within slope of the opening chart uses only the 3.6 % of income variation that happens inside countries over three decades: booms, recessions, and three decades of growth. Its comparison is between a country in a good year and the same country in a bad one, and a bad year’s emissions fall for reasons that have to do with the energy used in a recession, not with the slow change in technology that the between slope reflects. The two slopes answer different questions, and neither is the long-run effect of becoming richer on emissions.

How it is measured — What a fixed effect absorbs

A unit fixed effect absorbs every variable that is constant within the unit over the panel: geography, climate, legal origin, the energy endowment, a firm’s founding year. Their coefficients cannot be estimated with unit effects, and a regression that reports one is reporting noise or a collinearity the software resolved silently. A period effect absorbs everything common to all units in a period: world prices, global recessions, a change in a survey’s method. What is left — the identifying variation — is often small: 3.6 % of the variance of log income in the opening chart. Two consequences follow. Measurement error, which is mostly within-unit noise, becomes a larger share of what is left, so attenuation bias is worse in the within estimate than in the pooled one. And the standard errors of a fixed-effects estimate are larger, honestly, because there is less information.

2.5 Errors that move together: clustering in panels

In a panel, a unit’s errors are rarely independent from one year to the next. A firm that has a good year tends to have a good next year, and a state’s wage level drifts slowly. When the regressor is also persistent — a law that switches on and stays on — the observations of one unit carry much less information than their number suggests. Classical and heteroskedasticity-robust standard errors both assume independent observations; cluster-robust standard errors, clustered by unit, allow any correlation within a unit and none across units.

On the record — Placebo laws

Bertrand, Duflo and Mullainathan (2004) took state-level data on women’s wages from the Current Population Survey, about twenty years of it, and assigned laws at random to states and dates. The laws were fictitious and could have no effect. Estimated with state and year effects and conventional standard errors, up to 45 % of these placebo laws had an “effect” significant at 5 %. Clustering the standard errors by state, or collapsing each state’s data into a before and an after period, brought the rejection rate close to the nominal 5 % when the number of states was large. The paper changed the default: in a panel, cluster at the level at which the treatment is assigned.

Listing 2.3 repeats the experiment on simulated data with 50 states, 20 years and errors whose persistence is 0.8.

"""Placebo laws: 50 states, 20 years, errors that persist within a state.
How often does a law with no effect look significant at 5 %?"""
import numpy as np
from paneltools import ols_cluster

rng = np.random.default_rng(8)
states, years, reps, rho = 50, 20, 500, 0.8
unit = np.repeat(np.arange(states), years)
reject = {"se_iid": 0, "se_hc1": 0, "se_cluster": 0}


def two_way(m):
    """Remove state and year means (exact for a balanced panel)."""
    return m - m.mean(1, keepdims=True) - m.mean(0) + m.mean()


for _ in range(reps):
    e = np.zeros((states, years))
    e[:, 0] = rng.normal(size=states)
    for s in range(1, years):                       # AR(1) inside each state
        e[:, s] = rho * e[:, s - 1] + np.sqrt(1 - rho**2) * rng.normal(size=states)
    treated = rng.permutation(states) < states // 2
    start = rng.integers(5, 16)
    law = (treated[:, None] & (np.arange(years) >= start)).astype(float)
    y, x = two_way(e).ravel(), two_way(law).ravel()
    r = ols_cluster(y, x, unit)
    for k in reject:
        reject[k] += abs(r["beta"][0] / r[k][0]) > 1.96
for k, v in reject.items():
    print(f"{k:11s} rejects the true zero in {v / reps:.3f} of the samples")
Listing 2.3. Placebo laws on a simulated panel; ols_cluster returns the three kinds of standard error. code/bachelor-3/02-panel-data/listings/cluster_sim.py
$ python cluster_sim.py
se_iid      rejects the true zero in 0.396 of the samples
se_hc1      rejects the true zero in 0.392 of the samples
se_cluster  rejects the true zero in 0.066 of the samples
Output 2.3. 500 placebo laws.

Conventional and robust standard errors reject the true zero in about 40 % of the samples; clustered errors in 6.6 %. (The listing divides by n−1n - 1 rather than by the n−70n - 70 degrees of freedom left after the state and year means are removed, which makes the conventional and robust errors about 3.5 % too small and flatters their rejection rates a little; the clustered rate is barely affected.) Clustering is not free: it needs many clusters, since its justification is asymptotic in the number of clusters. With fewer than about thirty or forty, clustered standard errors are themselves too small, and methods that resample whole clusters are used instead.

2.6 Dynamic panels

Many economic variables depend on their own past: this year’s employment on last year’s, this year’s income on last year’s. The natural model is

yit=ρ yi,t−1+ai+uit,∣ρ∣<1.y_{it} = \rho\, y_{i,t-1} + a_i + u_{it}, \qquad |\rho| < 1.

Here strict exogeneity cannot hold: the regressor yi,t−1y_{i,t-1} depends on ui,t−1u_{i,t-1}, which sits inside uˉi\bar u_i, which sits inside the demeaned error.

Definition 2.10 (Dynamic panel bias)

The dynamic panel bias (Nickell bias) is the inconsistency, as nn grows with TT fixed, of the within estimator of ρ\rho in a model with a lagged dependent variable and unit effects.

For large TT the bias is approximately −(1+ρ)/(T−1)-(1 + \rho)/(T - 1) (Nickell 1981).

Proof. Admitted at this level. ∎

The exact expression is a ratio of two sums of geometric series; its derivation, and the approximation, are in Nickell’s paper. The chart shows a simulation.

The within estimate of persistence in a dynamic panel with unit effects, against the number of periods (true = 0.5; 500 units; mean of 200 simulated panels). Dashed: the approximation - (1+ )/(T-1).
The within estimate of persistence in a dynamic panel with unit effects, against the number of periods (true ρ=0.5\rho = 0.5; 500 units; mean of 200 simulated panels). Dashed: the approximation ρ−(1+ρ)/(T−1)\rho - (1+\rho)/(T-1). Source: simulated data, the chapter’s seeded script

With five periods the estimate is 0.168 instead of 0.5; with thirty, 0.448.

In a panel of countries over decades the bias is small; in a panel of firms over five years it is most of the estimate. The cure is the tool of Chapter 1. In first differences, Δyi,t−1\Delta y_{i,t-1} is correlated with Δuit\Delta u_{it} through ui,t−1u_{i,t-1}, but yi,t−2y_{i,t-2}, dated before that error, is not: under no serial correlation in uu, the level two periods back is a valid instrument for the lagged difference. Estimators built on this idea, using every earlier level as an instrument, are standard in dynamic panels, and so are their weak-instrument problems when ρ\rho is close to one.

2.7 Exercises

Exercise 2.1 ★

Read the opening chart.

  1. State the between and within slopes in tonnes per person per log point, and say which comparison each one makes.
  2. Give two characteristics of a country that are roughly fixed over three decades and raise both its income and its emissions.
  3. The right panel’s horizontal axis runs from −0.8-0.8 to 0.80.8. Why is it so much narrower than the left panel’s range of log incomes?
Solution

Solution of Exercise 2.1.

  1. Between: 2.7 tonnes per log point, comparing countries’ averages with each other. Within: 1.0, comparing each country’s years with its own average.
  2. An endowment of coal, oil or gas, which makes energy cheap and exports valuable; a cold climate, which raises both heating and, through the industries it favours, income. A large car-based territory also fits.
  3. Most of the variation in income is between countries: incomes differ by a factor of a hundred across countries, but one country’s income moves by a few tenths of a log point around its own average over three decades.

Exercise 2.2 ★

Unit A has (x,y)=(1,2),(2,4),(3,5)(x, y) = (1, 2), (2, 4), (3, 5) in three years, and unit B has (4,9),(5,10),(6,12)(4, 9), (5, 10), (6, 12).

  1. Compute the pooled slope.
  2. Compute the deviations from each unit’s means and the within slope.
  3. Draw the six points and explain the difference.
Solution

Solution of Exercise 2.2.

  1. xˉ=3.5\bar x = 3.5 and yˉ=7\bar y = 7. The cross-products sum to 12.5+4.5+1+1+4.5+12.5=3612.5 + 4.5 + 1 + 1 + 4.5 + 12.5 = 36 and the squares of x−xˉx - \bar x to 17.517.5: the pooled slope is 36/17.5=2.05736/17.5 = 2.057.
  2. Unit A: xˉA=2\bar x_A = 2, yˉA=11/3\bar y_A = 11/3; deviations x¨=(−1,0,1)\ddot x = (-1, 0, 1), y¨=(−5/3,1/3,4/3)\ddot y = (-5/3, 1/3, 4/3). Unit B: xˉB=5\bar x_B = 5, yˉB=31/3\bar y_B = 31/3; x¨=(−1,0,1)\ddot x = (-1, 0, 1), y¨=(−4/3,−1/3,5/3)\ddot y = (-4/3, -1/3, 5/3). Then ∑x¨y¨=5/3+4/3+4/3+5/3=6\sum \ddot x \ddot y = 5/3 + 4/3 + 4/3 + 5/3 = 6 and ∑x¨2=4\sum \ddot x^2 = 4: the within slope is 1.51.5.
  3. The two clouds each rise by about 1.5 per unit of xx, but B’s lies higher and further right, so a single line through all six points (2.057) is steeper than either.

Exercise 2.3 ★

For the data of Exercise 2.2, compute the first differences and the first-difference slope, without a constant. Why can the slope not be estimated with a constant in these data?

Solution

Solution of Exercise 2.3.

Unit A: Δx=(1,1)\Delta x = (1, 1), Δy=(2,1)\Delta y = (2, 1); unit B: Δx=(1,1)\Delta x = (1, 1), Δy=(1,2)\Delta y = (1, 2). The slope without a constant is ∑ΔxΔy/∑Δx2=(2+1+1+2)/4=1.5\sum \Delta x \Delta y / \sum \Delta x^2 = (2 + 1 + 1 + 2)/4 = 1.5. Every Δx\Delta x equals 1, so Δx\Delta x is collinear with a constant: a regression with a constant cannot separate the slope from the intercept.

Exercise 2.4 ★

The fixed-effects model assumes that the unit effect is constant over the panel. Describe two results, from data you could compute with the opening chart’s panel, that would show it is not.

Solution

Solution of Exercise 2.4.

First, split the panel into 1990–2005 and 2006–2022 and estimate the within slope in each; with constant unit effects and a constant slope, the two agree up to sampling error. Second, compare the within and first-difference estimates: if a slowly changing unit effect (a drift in each country’s energy mix) were left in the error, the two would weight it differently and disagree. A third check: the residuals of the within regression should show no trend inside countries.

Exercise 2.5 ★★

Using the panel of Listing 2.1 and the helpers twoway_demean and ols_cluster, estimate the within slope with country effects only and with country and year effects, each with conventional and country-clustered standard errors.

  1. Report the four standard errors and the ratio of clustered to conventional.
  2. By how much did the cross-country mean of log income rise between 1990 and 2022? Use it to explain why the year effects change the slope.
Solution

Solution of Exercise 2.5.

The tested solution is ex05_year_effects.py, in the chapter’s exercises/ folder.

  1. Country effects: slope 0.999, conventional s.e. 0.122, clustered 0.265, ratio 2.17. Country and year effects: 2.068, 0.164 and 0.450, ratio 2.74.
  2. The cross-country mean of log income rose by 0.576. A common rise in income, with emissions per person in several large rich countries falling over the same years, makes the year-to-year co-movement shared by all countries negative or weak; the year effects remove it, and what remains, each country’s movement relative to the world’s that year, has a steeper slope.

Exercise 2.6 ★★

Suppose that, among countries, the richer ones have cleaner technologies for reasons that do not change over the panel, so Cov⁡(xˉi,ai)<0\Cov(\bar x_i, a_i) < 0 in a regression of emissions on log income.

  1. In which direction is the between slope biased?
  2. The opening chart’s between slope exceeds its within slope. Is that consistent with this story alone? What else must be at work?
Solution

Solution of Exercise 2.6.

  1. Downward: the omitted unit effect is negatively correlated with income, so the between slope is below the true slope.
  2. No. On this story alone, the between slope would be smaller than an unbiased within slope, yet the chart shows it larger. Some fixed characteristics that raise income must also raise emissions (fossil endowments, climate) and outweigh the clean-technology effect; or the within slope is itself small for other reasons, such as measurement error or the short-run nature of within variation.

Exercise 2.7 ★★

In Exercise 2.5, the within slope has a conventional standard error of 0.122 and a clustered one of 0.265.

  1. Compute the ratio of the two variances (the design effect).
  2. Dividing the 6,419 country-years by the design effect gives an “effective” number of independent observations. Compute it.
  3. Give a 95 % confidence interval for the within slope with each standard error.
Solution

Solution of Exercise 2.7.

  1. (0.265/0.122)2=2.1722=4.72(0.265/0.122)^2 = 2.172^2 = 4.72.
  2. 6,419/4.72≈1,3606{,}419/4.72 \approx 1{,}360 effective observations.
  3. Conventional: 0.999±1.96×0.122=0.999±0.2390.999 \pm 1.96 \times 0.122 = 0.999 \pm 0.239, from 0.760 to 1.238. Clustered: 0.999±0.5190.999 \pm 0.519, from 0.480 to 1.518.

Exercise 2.8 ★★

In Output 2.2, the gap between random and fixed effects is 0.003 in the first panel and 0.146 in the second.

  1. Which estimate moves when the unit effect becomes correlated with xx, and why does the other not?
  2. The weight θ\theta is 0.610 in the first panel. Compute σu2/(σu2+Tσa2)\sigma_u^2/(\sigma_u^2 + T\sigma_a^2) and compare it with the true value when σu2=σa2=1\sigma_u^2 = \sigma_a^2 = 1 and T=6T = 6.
Solution

Solution of Exercise 2.8.

  1. Random effects moves; fixed effects does not. The within transform removes aia_i entirely, so its correlation with xx cannot reach the estimate. Random effects removes only the share θ\theta of each unit’s mean and leaves (1−θ)ai(1 - \theta)a_i in the error (Proposition 2.8).
  2. (1−0.610)2=0.152(1 - 0.610)^2 = 0.152. The true value is 1/(1+6)=0.1431/(1 + 6) = 0.143, so the true θ\theta is 1−0.143=0.6221 - \sqrt{0.143} = 0.622; the estimate, 0.610, is close.

Exercise 2.9 ★★

Repeat Listing 2.1 with the total fertility rate (SP.DYN.TFRT.IN) in place of emissions, for 1990–2022.

  1. Report the between and within slopes.
  2. Unlike emissions, the two slopes are close. What does that suggest about the fixed differences between countries, for this variable?
Solution

Solution of Exercise 2.9.

The tested solution is ex09_fertility.py, in the chapter’s exercises/ folder.

  1. Over 213 countries: between −0.778-0.778, within −0.837-0.837 births per woman per log point of income.
  2. The fixed differences between countries are not strongly correlated with income in a way that also moves fertility; whatever the fixed effects absorb does not change the slope much. The two slopes can still both be far from a causal effect: income and fertility move together inside countries for reasons, such as women’s schooling, that change over time.

Exercise 2.10 ★★★

Prove that with T=2T = 2 the within estimator and the first-difference estimator (without a constant) are equal.

Solution

Solution of Exercise 2.10.

With T=2T = 2, xˉi=(xi1+xi2)/2\bar x_i = (x_{i1} + x_{i2})/2, so x¨i1=−Δxi/2\ddot x_{i1} = -\Delta x_i/2 and x¨i2=Δxi/2\ddot x_{i2} = \Delta x_i/2, with Δxi=xi2−xi1\Delta x_i = x_{i2} - x_{i1}; the same holds for yy. Then

∑i∑tx¨ity¨it=∑i2⋅ΔxiΔyi4=12∑iΔxiΔyi,∑i∑tx¨it2=12∑iΔxi2,\sum_i\sum_t \ddot x_{it}\ddot y_{it} = \sum_i 2 \cdot \frac{\Delta x_i \Delta y_i}{4} = \frac12 \sum_i \Delta x_i\Delta y_i, \qquad \sum_i\sum_t \ddot x_{it}^2 = \frac12 \sum_i \Delta x_i^2,

and the ratio is ∑iΔxiΔyi/∑iΔxi2\sum_i \Delta x_i \Delta y_i / \sum_i \Delta x_i^2, the first-difference estimator without a constant.

Exercise 2.11 ★★★

Simulate the dynamic panel of Section 2.6 with ρ=0.5\rho = 0.5 and 500 units, for T=5T = 5, 10 and 20.

  1. Report the mean within estimate over 200 panels and its bias.
  2. Compare the bias with −(1+ρ)/(T−1)-(1 + \rho)/(T - 1). For which TT is the approximation good?
Solution

Solution of Exercise 2.11.

The tested solution is ex11_nickell.py, in the chapter’s exercises/ folder.

  1. Mean estimates 0.168, 0.337 and 0.421 for T=5T = 5, 10 and 20; biases −0.332-0.332, −0.163-0.163 and −0.079-0.079.
  2. The approximation gives −0.375-0.375, −0.167-0.167 and −0.079-0.079. It is good from T=10T = 10 on and overstates the bias at T=5T = 5, as an approximation for large TT may.

Exercise 2.12 ★★★

Strict exogeneity can fail through feedback: a shock to yy this year changes xx next year.

  1. Show that under feedback, x¨it\ddot x_{it} is correlated with u¨it\ddot u_{it} even when xitx_{it} is uncorrelated with uitu_{it}.
  2. Propose a test: add the lead xi,t+1x_{i,t+1} to the within regression. Under strict exogeneity, what should its coefficient be? Under feedback, what sign do you expect if uu raises future xx?
Solution

Solution of Exercise 2.12.

  1. u¨it=uit−uˉi\ddot u_{it} = u_{it} - \bar u_i contains uisu_{is} for every ss, including s<ts < t. Under feedback, xitx_{it} depends on ui,t−1u_{i,t-1}, so Cov⁡(xit,uˉi)≠0\Cov(x_{it}, \bar u_i) \neq 0 and hence Cov⁡(x¨it,u¨it)≠0\Cov(\ddot x_{it}, \ddot u_{it}) \neq 0, even if Cov⁡(xit,uit)=0\Cov(x_{it}, u_{it}) = 0.
  2. Under strict exogeneity, xi,t+1x_{i,t+1} is unrelated to uitu_{it} and its coefficient is zero. If a positive shock this year raises xx next year, the lead is positively correlated with uitu_{it}: its coefficient is positive.

2.8 Problem: Fifteen Years of Brenland’s Firms

Problem 2.1

Weekend problem — fifteen years of Brenland’s firms

Brenland (invented) keeps a register of 300 manufacturing firms, observed every year from 2011 to 2025: 4,500 firm-years. For each firm-year it records the logarithm of output yity_{it} and of capital kitk_{it}. The quality of a firm’s management, mim_i, is not recorded; it raises output with a coefficient of 0.5 per standard deviation and is the same in every year. In 2018 a training subsidy was given to 100 firms, chosen by a panel that judged, among other things, how well they were run; sit=1s_{it} = 1 for those firms from 2018 on. The table gives the estimates of a statistician, with standard errors computed twice: as if all firm-years were independent, and clustered by firm. In the register, the variance of kitk_{it} is 0.8675 and its covariance with mim_i is 0.9512.

Here “within” uses firm effects, “two-way” firm and year effects, and “first difference” regresses Δy\Delta y on Δk\Delta k.

Part I — the pooled regression.

  1. Interpret the pooled coefficient on kk in words, as an elasticity.
  2. Use the omitted-variable formula and the register’s variance and covariance to predict the probability limit of the pooled slope, if the true elasticity is 0.30.
  3. Compare your prediction with the pooled estimate.
  4. Why can the statistician not simply add management quality to the regression?
  5. If better-run firms used less capital, in which direction would the pooled estimate be biased?
  6. Compute the ratio of the clustered to the iid standard error of the pooled slope. Is a precise standard error a reason to trust the estimate?

Part II — within and first differences.

  1. Interpret the within estimate, and say which comparisons it makes.
  2. The within and first-difference estimates differ by about 0.05. Give two reasons why they may differ.
  3. The two-way estimate is closer to 0.30 than the within estimate. What does the year effect remove?
  4. Give a 95 % confidence interval for the two-way coefficient on kk with the clustered standard error.
  5. What part of the variation in capital identifies the two-way estimate?
  6. A consultant advised some firms from 2015 and, she says, raised both their capital and their output. Would the two-way estimate still be consistent? Explain.

Part III — the training subsidy.

  1. Why is the pooled estimate of the subsidy’s effect likely to be biased upward?
  2. Compare the pooled and two-way estimates of the subsidy’s effect.
  3. Convert the two-way estimate into a percentage change in output.
  4. With firm and year effects, which comparison identifies the subsidy’s effect?
  5. What must be true of the treated and untreated firms’ output paths for that comparison to give the effect of the subsidy?
  6. How would you use the years 2011–2017 to check that assumption?
  7. Suppose the panel had picked firms whose output had just fallen. In which direction would the two-way estimate be biased?

Part IV — the standard errors.

  1. Compute the ratio of the clustered to the iid standard error of the two-way subsidy estimate, and its square.
  2. Give 95 % confidence intervals for the subsidy’s effect with each standard error.
  3. Why is the iid standard error too small here? Name the two features of the data that combine.
  4. If the design effect (your square from Question 20) is 1+(T−1)ρ1 + (T - 1)\rho with T=15T = 15, what correlation ρ\rho does it imply?
  5. How many independent firm-years is the panel worth for this coefficient?
  6. State the two results of this problem, each with its clustered 95 % interval.
Solution

Solution of Problem 2.1.

1. Across firm-years, 1 % more capital goes with 0.87 % more output.

2. 0.30+0.5×0.9512/0.8675=0.30+0.5×1.0965=0.30+0.548=0.8480.30 + 0.5 \times 0.9512/0.8675 = 0.30 + 0.5 \times 1.0965 = 0.30 + 0.548 = 0.848.

3. The pooled estimate is 0.868, close to the prediction; the rest comes from the subsidy and the year shocks, also left in the pooled error.

4. It is not recorded. Any measure of it — a survey score, a manager’s degree — would be partial and noisy, and the omitted part would remain.

5. Downward: the covariance of capital with management would be negative.

6. 0.0094/0.0045=2.090.0094/0.0045 = 2.09. No: the standard error measures sampling noise around the wrong number. A biased estimate can be very precise.

7. Within a firm, a year in which capital is 1 % above the firm’s own average has output 0.35 % above its average. The comparisons are between years of the same firm.

8. The errors are serially correlated, and the two estimators weight the years differently; and the year shocks common to all firms enter both differently, because capital trends upward and the within transform compares each year with the firm’s whole-period average, while differences compare adjacent years. Measurement error in capital would also hit them differently.

9. Shocks common to all firms in a year (demand, prices). Capital rises on average over time, so any common year shock that happens to line up with that trend is attributed to capital by the one-way within estimate.

10. 0.3182±1.96×0.0147=0.3182±0.02880.3182 \pm 1.96 \times 0.0147 = 0.3182 \pm 0.0288, from 0.289 to 0.347.

11. The movements of each firm’s capital around its own average, net of the movement common to all firms in that year.

12. No. The advice changes over time (it starts in 2015) and moves both capital and output; it is a time-varying confounder, which neither firm nor year effects remove.

13. The panel picked better-run firms, and management raises output. Capital in the regression captures only part of management, so the subsidy dummy picks up the rest.

14. Pooled 0.122, two-way 0.110. The pooled estimate is larger, as Question 13 predicts, but here by little, because capital already absorbs much of the management difference.

15. e0.1101−1=0.116\eu^{0.1101} - 1 = 0.116: output 11.6 % higher.

16. The change in output of subsidised firms from before 2018 to after, compared with the change of unsubsidised firms over the same years.

17. Without the subsidy, the output of treated and untreated firms would have moved in parallel after 2018: their gap could be anything, but not its change.

18. Estimate the gap between treated and untreated firms year by year for 2011–2017; it should be flat. A trend in it before 2018 would undermine the assumption.

19. Upward: output that has just fallen tends to recover by itself, and the recovery would be counted as the subsidy’s effect.

20. 0.0181/0.0110=1.6450.0181/0.0110 = 1.645; its square is 2.712.71.

21. iid: 0.1101±1.96×0.0110=0.1101±0.02160.1101 \pm 1.96 \times 0.0110 = 0.1101 \pm 0.0216, from 0.0885 to 0.1317. Clustered: 0.1101±0.03550.1101 \pm 0.0355, from 0.0746 to 0.1456.

22. The errors persist within a firm from year to year, and the regressor persists too: the subsidy is on for eight years in a row for the same firms. Together they make the firm-years of one firm far from independent.

23. 2.71=1+14ρ2.71 = 1 + 14\rho, so ρ=1.71/14=0.122\rho = 1.71/14 = 0.122.

24. 4,500/2.71≈1,6604{,}500/2.71 \approx 1{,}660 firm-years.

25. Inside firms, net of year shocks, the elasticity of output with respect to capital is 0.318, with a clustered 95 % interval of 0.289 to 0.347. The training subsidy raised output by 0.110 log points (11.6 %), with a clustered 95 % interval of 0.075 to 0.146, if treated and untreated firms would otherwise have moved in parallel.

本章定义的术语

在术语表中查看全部 1086 个术语