- Learn
- Business & Economics
- Economics
- Econometrics 1
- Difference-in-Differences
Pooled Cross Sections and Difference-in-Differences
IntermediateLesson 7 of 8 in Econometrics 1 Course
What you will learn
- Combine random samples drawn in different years into one regression, let the intercept shift between years and test whether the effects of the explanatory variables have changed.
- Combine cross sections from different years with year dummiesRecognize an independently pooled cross section, explain why pooling helps, and use year dummies to absorb changes over time.
- Test whether effects change over timeInteract year dummies with explanatory variables to let slopes differ between years, interpret the interaction terms and test for structural change with t and F tests.
- Combine cross sections from different years with year dummies
- Use natural experiments to evaluate a policy, compute the difference-in-differences estimate from four group means and estimate it by regression with standard errors and controls.
- Explain natural experiments and why simple comparisons misleadDescribe the counterfactual question behind policy evaluation, recognize a natural experiment, and explain why before-after and treated-control comparisons alone are biased.
- Compute the difference-in-differences estimate from group meansCalculate the difference-in-differences estimate step by step from four group means, interpret its sign and size, and connect it to the counterfactual.
- Estimate and interpret the difference-in-differences regressionWrite the difference-in-differences regression, match each coefficient to the group means, add control variables appropriately, and report standard errors and percentage effects.
- Explain natural experiments and why simple comparisons mislead
- State the assumption that makes difference-in-differences causal, recognize what violates it and judge its plausibility with pre-policy data, placebo tests and triple differences.
- State the parallel-trends assumption and what it impliesExpress parallel trends in words and symbols, show how it turns the difference-in-differences estimate into the treatment effect, and see why its plausibility depends on how the outcome is measured.
- Recognize threats that break a difference-in-differences designIdentify the situations that violate parallel trends or the other conditions of a difference-in-differences study, and explain the direction of the resulting bias.
- Check plausibility with pre-trends, placebo tests and triple differencesUse data from before the policy, placebo groups and outcomes, alternative control groups and the triple-difference estimator to judge and strengthen a difference-in-differences design.
- State the parallel-trends assumption and what it implies
- Model two-period panel data with an unobserved, time-constant effect, remove it by first differencing and use the differenced equation to evaluate programs.
- Set up two-period panel data and the unobserved effects modelDescribe the structure of two-period panel data, write the unobserved effects model and explain why pooled OLS is biased when the unobserved effect is correlated with the regressors.
- Estimate by first differencing and know its assumptionsDerive the first-differenced equation, estimate it by OLS, interpret its coefficients and check the conditions under which it is unbiased and precise.
- Evaluate programs with first-differenced panel dataApply first differencing to a program-participation dummy, show that it equals difference-in-differences with panel data, and handle controls, attrition and more than two periods.
- Set up two-period panel data and the unobserved effects model
Difference-in-Differences study guide
1Pool independent cross sections across time
Combining surveys from different years gives more observations and lets you study how economic relationships change. Begin by identifying whether the samples are independent or follow the same units. Then use year dummies to allow different starting levels and interactions to allow different slopes. The way you specify these terms determines which comparison each coefficient makes and which restrictions a stability test should impose.
1.1 Fresh samples and year effects
An independently pooled cross section combines fresh random samples from the same population in different years. A household surveyed in one year usually appears only once. Pooling increases the sample size and lets you investigate changes that a single year's survey cannot show.
Know what was sampled
A panel follows the same units; independently pooled cross sections draw each year's sample afresh. Under independent sampling, observations from different years are independent. Their distributions can still differ: the population, average outcome and error variance may change. Use heteroskedasticity-robust standard errors when a common variance is doubtful. A larger pool improves precision when the model represents the relationship across those years.
Give each year an intercept
For samples from 2015 and 2023, let equal 1 in 2023 and 0 in 2015. Fit
The 2015 intercept is ; the 2023 intercept is . The coefficient compares years holding the regressors fixed. It can absorb changes in prices, productivity or tastes that shift the expected outcome across years. It does not identify which of those forces caused the shift.
With years and an intercept, include year dummies. The omitted year is the base year. If every year has its own dummy, the dummies sum to the intercept column, creating perfect collinearity. Changing the base year changes the comparisons in the coefficient table, but leaves fitted outcomes unchanged.
Read a pooled wage equation
Suppose 1,800 workers from 2015 and 2,100 from 2023 give 3,900 observations. A fitted log-earnings model contains and controls for experience. For workers with equal education and experience, the fitted log earnings are 0.18 higher in 2023. That is 18 log points; the exact proportional comparison is
A raw increase of 0.25 in average log earnings would answer a different question. It includes changes in worker characteristics as well as the adjusted year shift. For example, a more educated later workforce can raise the raw mean even with the same education slope.
Separate nominal and real changes
Current-money earnings are nominal. To compare purchasing power, divide by the appropriate price index. For a logged outcome,
If everyone in a year uses the same index, this subtraction is a year-specific constant. With year dummies, it changes the intercept by and the year coefficient by , leaving the slopes unchanged. If the base-year index is 1, the intercept stays unchanged. A nominal year shift can therefore include inflation even when the estimated education slope is unaffected by deflation.
Key Takeaways
- Fresh samples across years are pooled cross sections; tracking the same units creates a panel.
- Year coefficients compare outcomes at fixed regressor values.
- An intercept and T years require T − 1 year dummies.
- Independent sampling permits different error variances across years.
- Deflating a log outcome with a common yearly index shifts year effects, not slopes.
1.2 Changing slopes and joint tests
A year dummy shifts the intercept. To let an explanatory variable's effect change too, multiply it by the year dummy. This interaction measures a difference between slopes, not the later slope by itself.
Build the two slopes
Consider
In 2015, , so the education slope is . In 2023, , so it is . Keep the main education term: omitting it would force the base-year slope to zero.
If the estimates are 0.070 and 0.015, the approximate return per extra year of education rises from 7.0% to 8.5%. The increase is 1.5 percentage points in these approximate returns. To test whether it changed, test . A standard error of 0.005 gives
That exceeds the large-sample two-sided 5% cutoff of about 1.96.
Interact a group dummy
The same logic applies to a dummy regressor. Estimates of −0.30 on and 0.08 on imply female-minus-male log-wage gaps of −0.30 in 2015 and −0.22 in 2023. These are gaps of 30 and 22 log points. The exact comparisons are about 25.9% and 19.7% lower wages for women with the same included characteristics. The positive interaction means the negative gap narrowed; it does not mean the later gap became positive.
Test several changes together
For regressors, fully interact the year dummy with every regressor. The unrestricted model has parameters. A slope-stability test sets the slope interactions to zero but keeps the intercept shift. A full Chow test also sets the intercept shift to zero, imposing restrictions. Choose the restrictions to match the question being asked.
Under homoskedasticity, the joint-test statistic is
The restricted model imposes the null; the unrestricted model allows both years' coefficients to differ. With , , , and , the unrestricted residual degrees of freedom are 3,892. Then
This exceeds a 5% critical value of about 2.6, rejecting stable slopes. Testing three interactions separately would answer three individual questions, not this joint one.
Choose a valid test
Fully interacting the pooled model gives the same coefficient estimates as separate regressions for the two years. Its unrestricted SSR is the sum of their SSRs. This makes differences and their standard errors convenient to obtain in one equation. The classical SSR-based F test requires a common error variance; use a heteroskedasticity-robust joint test when variances differ across years.
Key Takeaways
- An interaction with a year dummy is the change in a slope.
- The later slope adds the base-year slope and its interaction.
- A slope-stability test retains the intercept shift; a full Chow test restricts it too.
- The unrestricted two-year model has 2(k + 1) parameters.
- Joint hypotheses need joint tests.
- Use a robust joint test when the common-variance assumption is doubtful.
2Estimate policy effects with difference-in-differences
A policy effect is a comparison with a missing outcome: what treated units would have experienced without the policy. A before-after change and a single treated-control gap each leave part of that problem unresolved. Build a comparison from both groups in both periods, work out the implied counterfactual, and express the same calculation as a regression. Read its coefficient together with its units, controls and uncertainty.
2.1 Finding a credible counterfactual
Policy evaluation asks what changed because of a policy. Observing an outcome after implementation is not enough: you also need a credible estimate of what would have happened without the policy.
Name the missing outcome
Write for an outcome with treatment and for the outcome without it. A treated unit reveals after implementation, but its in that same period is unobserved. That missing outcome is the counterfactual. The average treatment effect on the treated, or ATT, averages over treated units after the policy. It is an average for those units and that period.
A natural experiment occurs when an event outside the researcher's control changes conditions for some units but not others. A law, a new program or the siting of a facility may create a treatment group and an unaffected comparison group. Assignment is not random, so systematic starting differences remain possible.
Why a single comparison misleads
A before-after comparison within the treated group includes the policy effect and everything else that changed over time. If a recession reduces employment, the observed change mixes the policy with that recession. The comparison needs a zero untreated change to isolate the effect.
An after-only comparison between treated and control groups includes the effect and any gap that would have existed without treatment. It isolates the effect only if the two groups would otherwise have had equal after-period outcomes.
| Comparison | What can get mixed with the policy effect? |
|---|---|
| Treated after minus treated before | Other changes over time |
| Treated after minus control after | Pre-existing or other untreated group differences |
Near a planned garbage incinerator in North Andover, Massachusetts, houses within about 4.8 km sold for 30,688 dollars less than farther houses in 1981, measured in 1978 prices. But their 1978 gap was already 18,824 dollars. Rumors began after 1978 and construction started in 1981. Assigning the entire later gap to the incinerator would include a large earlier difference.
Construct four comparison cells
Use data for both groups before and after the event. The cells are control-before, control-after, treated-before and treated-after. Repeated cross sections can fill them using fresh samples; panels can fill them by revisiting the same units.
Card and Krueger studied New Jersey's April 1, 1992 minimum wage increase from $4.25 to $5.05 per hour. Eastern Pennsylvania kept $4.25. They surveyed 410 fast-food restaurants in February–March and November–December 1992. The same restaurants were followed, making this a panel example. Pennsylvania supplied a comparison exposed to similar regional conditions without the wage increase.
Choose a control group whose untreated change is informative about the treatment group's missing change. Equal starting means are unnecessary. Similar starting levels alone are also insufficient: two equally productive regions may face very different subsequent shocks.
Key Takeaways
- The counterfactual is the treated group’s outcome without treatment in the after period.
- The ATT averages treatment effects over treated units.
- Before-after comparisons include other time changes; after-only comparisons include untreated group gaps.
- A useful control supplies the treated group’s missing untreated change.
2.2 From four means to a policy estimate
Difference-in-differences (DiD) uses four means to remove a fixed group gap and a shared time change. Calculate changes in a consistent direction: after minus before within each group, then treated minus control.
Work through the two changes
Let denote a sample mean. The estimator is
In the Card–Krueger study, employment is measured in full-time-equivalent (FTE) workers per restaurant, counting a part-time worker as half a full-time worker.
| Group | Before | After | Change |
|---|---|---|---|
| New Jersey | 20.44 | 21.03 | +0.59 |
| Pennsylvania | 23.33 | 21.17 | −2.16 |
First find New Jersey's change: . Next find Pennsylvania's: . Subtract the comparison change:
Employment rose by an estimated 2.75 FTE workers per restaurant relative to the comparison path. The raw New Jersey gain of 0.59 leaves out the decline observed in Pennsylvania.
See the counterfactual
Under parallel untreated trends, New Jersey without the increase would have shared Pennsylvania's change. Add that change to New Jersey's baseline:
The observed after-period mean is 21.03, so its distance above the counterfactual is . The treatment group can remain below the control group's level and still have a positive estimated treatment effect.
You can instead subtract group gaps. The treated-minus-control gap changes from before to after. Its change is again . Mixing directions between the two periods would destroy this equivalence.
Interpret the published result
The paper reports 2.76 using unrounded data, with a standard error of 1.36. The resulting t statistic is about 2.03, and the estimate is about 13% of New Jersey's starting employment level. The positive result challenged the simple competitive labor-market prediction of lower employment after a higher minimum wage. Survey measurement and later payroll-based evidence became part of the debate.
Keep the outcome's units
A city introducing time-of-use electricity prices sees household use fall from 310 to 280 kWh per month. A comparison city falls from 300 to 295. The treated change is −30 and the control change is −5:
The estimated reduction is 25 kWh per household per month relative to the untreated path, assuming the design's causal conditions hold. A negative effect is a reduction in the measured outcome; whether that is desirable depends on what the outcome measures.
Key Takeaways
- DiD subtracts the control change from the treated change.
- The counterfactual equals the treated baseline plus the control change.
- Changing group gaps gives the same estimate when subtraction directions are consistent.
- Report the estimate in the outcome’s units and for the treated population.
- Rounded means can give a slightly different result from unrounded data.
2.3 DiD in a regression
A DiD regression reproduces the four-cell comparison and provides a standard error. It also allows controls, but the coefficient still needs a credible comparison design to receive a causal interpretation.
Match coefficients to cells
Let equal 1 after the policy and equal 1 for the affected group. Estimate
Substitute each pair of dummy values:
| Cell | Fitted mean |
|---|---|
| Control before | |
| Control after | |
| Treated before | |
| Treated after |
The interaction is DiD. The group main effect is the baseline gap; the time main effect is the control group's change. Keep both main effects so the interaction measures the additional treated change.
For the rounded restaurant means, the estimates are , , and . The treated-after prediction is . Without controls, OLS fits each cell mean exactly, so its interaction equals the raw DiD.
Add controls with a purpose
Add for suitable observed characteristics. Controls can improve precision and adjust for different sample composition across repeated cross sections. They should describe factors the policy cannot change. Controlling for a variable changed by treatment can remove part of the effect you want to measure. Assess that causal role before adding a convenient predictor.
In the incinerator example, the real-price DiD without controls is about −11,864 dollars. With a logged price outcome, the uncontrolled interaction is about −0.063 and statistically insignificant; after house controls it is about −0.132 and significant at 5%. The houses sold near the site changed across samples, so adjusting for their characteristics matters. With controls, the interaction need not equal the four raw means' DiD.
Read logs and uncertainty
For a log coefficient , the approximate proportional effect is percent. Transforming the fitted log comparison gives percent: −0.132 corresponds to about 12.4% lower fitted prices, compared with the 13.2% approximation. This is a multiplicative comparison on the log-model scale; interpreting it as a change in the arithmetic mean price also needs an appropriate retransformation of the errors. A coefficient of −0.10 similarly gives about 9.5% lower fitted values.
Test a zero interaction with its standard error and report a confidence interval. Heteroskedasticity-robust errors address unequal observation-level variances. When a policy varies by state or city, shared shocks create within-group dependence, so inference must allow for it. Many individual observations in just one treated and one control location cannot separate the policy from a treated-location after-period shock.
Fit the same model in software
These commands include both main effects and the interaction:
fit <- lm(y ~ treat * after, data = df)
regress y i.treat##i.after, vce(robust)
import statsmodels.formula.api as smf
fit = smf.ols("y ~ treat * after", data=df).fit(cov_type="HC1")
R's lm fits the coefficients; its default printed standard errors are conventional. The Stata and Python commands request heteroskedasticity-robust errors. Those requests do not address within-location correlation. Identify the interaction by its variable names, and read the coefficient together with the design and the uncertainty estimate.
Key Takeaways
- The after × treat coefficient is DiD; both main effects remain in the model.
- Without controls, the interaction equals the four-means DiD.
- Controls should not absorb changes caused by treatment.
- A log coefficient transforms through 100(eᵇ − 1) for a proportional comparison.
- Unequal variances and shared group shocks require different standard-error adjustments.
- More individuals do not replace independent policy-level comparisons.
3Assess the parallel-trends assumption
Difference-in-differences becomes a causal comparison through an assumption about the untreated path. Learning to calculate the estimator is only the first part of evaluating a policy. Examine what must be true of the comparison group, how temporary shocks or changing samples can undermine the result, and what earlier outcomes can reveal. A third comparison can remove additional trends, but it also brings a specific assumption to assess.
3.1 The untreated change assumption
Parallel trends states that, without treatment, the treated group's average outcome would have changed by the same amount as the control group's. The assumption supplies the untreated change that cannot be observed for treated units after the policy.
State what must be parallel
In potential-outcome notation,
The groups may start at different levels. A permanent gap is compatible with parallel trends because DiD removes that gap. A shared recession is also compatible if it produces the same untreated change in both groups. A recession that affects the treated group more strongly creates a trend difference.
This concerns the path without the policy, not the observed path after it. If a successful policy makes treated outcomes rise faster, the observed lines should separate. Requiring the observed after-period lines to stay parallel would rule out the very treatment effect being estimated.
Separate effect from trend bias
The treated group's observed change is its treatment effect plus its untreated change. Subtracting the control change gives
Under parallel trends, the term in parentheses is zero. If the treated group would have grown 3 units more even without treatment and the true effect is 2, DiD is . The extra 3 is bias from the untreated trend gap. A negative trend gap would pull the estimate downward instead.
Draw the missing path
On a graph of mean outcomes over time, start a dashed counterfactual at the treated group's before mean. Move it by the control group's observed change. The vertical distance from that dashed after point to the treated group's actual after mean is DiD. The dashed path is inferred, not an additional set of observed treated outcomes.
The treated group's untreated after mean is missing, so the assumption cannot be directly checked for the policy period. Earlier observations can support its plausibility, while the possibility of a new group-specific shock still needs substantive investigation.
Choose levels or logs deliberately
Parallel changes in units and parallel proportional changes are different assumptions. If representative outcomes go from 100 to 110 in one group and 50 to 60 in another, both rise by 10. Their log changes differ:
For positive representative group levels that start unequal, a common nonzero additive change cannot also be a common proportional change. Choose the scale using the economic question and evidence about untreated paths. For individual-level data, average the logged outcomes when evaluating mean-log trends; taking the log of each arithmetic group mean can answer a different question.
Key Takeaways
- Parallel trends concerns untreated average changes, not equal starting levels.
- DiD equals ATT plus the untreated trend difference.
- Observed post-policy divergence can be the treatment effect.
- Pre-policy evidence cannot reveal the treated group’s missing untreated after outcome.
- Parallel trends in levels and in logs are different assumptions.
3.2 How the comparison can fail
A DiD coefficient combines every force that changes the treated-minus-control gap. To interpret it causally, investigate why that gap might have moved even without the policy and whether the baseline or control group was already affected.
Different trends and temporary shocks
A treated region may have faster underlying employment growth because its population is growing more quickly. DiD then assigns some of that growth to the policy, biasing the estimated employment effect upward. Slower untreated growth biases it downward. Geographic closeness is helpful only if it makes the relevant changes comparable.
Selection on temporary shocks causes another problem. People may join job training after an unusually low-earnings year. This pre-enrollment decline is the Ashenfelter dip. Even without training, part of the temporary decline would reverse. Using the dip as the baseline makes the recovery look like a program effect. A permanent low earnings level can be differenced away; a temporary shock and subsequent rebound cannot.
An affected baseline or comparison group
Anticipation means units react before formal implementation. Firms might change hiring when a policy is announced. The New Jersey increase was legislated in 1990, so adjustment could precede the 1992 before survey. A baseline before announcement reduces the risk of measuring only the remaining adjustment.
Spillovers occur when the policy changes control outcomes too. Cross-border commuting or customer movement can transmit a wage policy's effects to another state. If a policy raises the control outcome, subtracting that increase pushes the measured effect down. If it lowers the control outcome, subtraction pushes the estimate up. The direction follows the spillover's sign, not the label "spillover".
Other events and different samples
A separate tax change introduced only in the treated state at the same time enters the same after-by-treatment cell as the policy of interest. A simple two-by-two comparison cannot distinguish their effects. More restaurants within the two states do not create a separate policy comparison.
With pooled cross sections, the sampled units can also change. Suppose higher-income households move into a treated area after a transport improvement. An increase in average earnings may partly reflect the newcomers. Controls for characteristics unaffected by the policy can help compare more similar samples. A characteristic changed by the policy may instead be a channel through which the policy works, so controlling for it changes the question.
Keep two validity questions separate
Internal validity asks whether the comparison identifies the effect for the treated population and period studied. The threats above concern that question. External validity asks whether the result carries to other settings, populations or policy sizes. A well-identified effect in 1992 fast-food restaurants need not be the effect of a much larger wage change in another industry. A precise estimate can have weak internal validity, and a credible local estimate can have limited external reach.
Key Takeaways
- An untreated trend advantage biases DiD upward; a disadvantage biases it downward.
- A temporary dip followed by recovery can mimic a program effect.
- Anticipation affects the baseline; spillovers affect the comparison path.
- A simultaneous treated-only event is mixed with the policy in a two-by-two design.
- Composition changes alter who contributes to group means.
- Internal validity concerns the studied effect; external validity concerns transfer.
3.3 Evidence about the comparison path
A credible DiD analysis assembles evidence about the comparison path. Earlier outcomes, unaffected groups and other control groups can reveal weaknesses that a single before-after table hides.
Examine pre-policy changes
Plot several pre-policy means for each group on the same time axis. Treated means of 50, 52 and 54 and control means of 40, 42 and 44 show equal increases of 2 per year despite a gap of 10. Diverging earlier lines make a common untreated future change less plausible.
A fake-date placebo places an imaginary policy between two pre-policy years. Here its DiD is . If the treated mean instead rose from 50 to 54 while the control rose from 40 to 42, the placebo would be 2. That result would reveal differential movement before the actual policy.
A small pre-trend estimate with a wide confidence interval leaves important trend gaps possible. Also, a shock beginning exactly with the policy will escape a pre-period check. Interpret the evidence together with what was happening in each location.
Change the comparison
A placebo group should be unaffected by the policy. In a minimum wage study, restaurants already paying well above the new minimum provide a useful check if the policy has no relevant effect on them. A large apparent effect there points toward other changes. A placebo outcome is one the policy cannot plausibly affect; a change in it can likewise signal a competing explanation.
Try alternative control groups that have a substantive reason to represent the untreated path. Similar estimates across reasonable controls reduce concern about one comparison group's unusual trend.
Add a third difference
Triple differences (DDD) adds an unaffected subgroup inside each location. Suppose a health policy in state B applies to people aged 65 and older. Compare the change for older versus younger people in B, then subtract the same age-group change gap in untreated state A.
| State | Older change | Younger change | Older minus younger |
|---|---|---|---|
| B | +8 | +3 | +5 |
| A | +4 | +2 | +2 |
The estimate is units. Subtracting the younger change removes a shared state change; subtracting the age gap in A removes the age-specific change common across states.
DDD requires the older-minus-younger untreated trend gap to be the same in both states. It allows location-specific and age-specific changes that add together. A shock affecting only older people in B still has the same pattern as treatment and remains a problem.
The regression includes the time, state and age dummies, every pairwise interaction, and . Its triple-interaction coefficient is DDD. Dropping a lower-order term forces an unrelated difference to zero and can contaminate that coefficient.
Key Takeaways
- Compare pre-policy changes even when group levels differ.
- Fake dates, unaffected groups and unaffected outcomes probe different weaknesses.
- A passing check supports the design while leaving policy-period shocks unresolved.
- DDD subtracts one subgroup DiD from the corresponding DiD in another location.
- DDD needs a common untreated subgroup trend gap across locations.
- The DDD regression retains all main and pairwise terms.
4Remove unobserved effects with two-period panel data
Following the same units twice gives a direct way to handle permanent differences that are hard to measure. Separate those stable factors from temporary shocks, then subtract the earlier equation from the later one. First differencing changes the information used to estimate a slope and removes some regressors entirely. Its program-evaluation form connects to DiD, while feedback, missing units and changing controls still need attention.
4.1 Stable differences within a panel
Two-period panel data observe the same units twice. Revisiting each person, firm or city makes it possible to compare its outcome with its own earlier outcome, removing permanent unit differences from the change.
Organize units and periods
A balanced panel has observations for every unit in both periods. In long format, each unit-period pair has its own row: units create rows. A unit identifier and period variable tell you which rows belong together. In wide format, each unit has one row with separate outcome and regressor columns for the two periods.
Independently pooled cross sections do not supply these pairs. Their new samples allow changes in population means, but you cannot calculate a person's change by subtracting another sampled person's earlier value.
Split the unobserved factors
Write the two-period unobserved effects model as
Here is 0 in the first period and 1 in the second. The effect differs across units but stays constant within each unit. It can represent permanent geography, stable managerial quality or a worker's ability. The idiosyncratic error varies across units and periods, such as a temporary disruption to one firm's production.
The time dummy captures a common shift between periods. It cannot absorb a separate permanent factor for every unit. Likewise, a permanent unit effect cannot absorb a shock that changes differently across units over time.
Understand heterogeneity bias
Pooled OLS puts the two periods into one regression and leaves the composite error . If is correlated with the regressors, that correlation causes omitted variable bias and inconsistency. This is heterogeneity bias. The issue is correlation, not simply how large permanent differences are.
Three cities illustrate the risk. Their unemployment percentages and crimes per 1,000 residents are A: (4, 50) then (6, 54); B: (8, 30) then (9, 32); C: (10, 20) then (12, 24). Within each city, more unemployment accompanies more crime. Across cities, however, the lower-unemployment cities have higher crime for permanent reasons. Pooled OLS with a second-period dummy gives a slope of −5.0. That negative slope blends the across-city differences with the within-city relationship.
Distinguish bias from dependence
Even if the permanent effect is uncorrelated with the regressors, it appears in both observations for a unit. The two composite errors can therefore be correlated. Treating the rows as independent gives an inappropriate standard-error calculation. Inference must allow correlation within units.
Correcting that dependence changes uncertainty estimates; it does not remove the omitted-variable correlation that caused heterogeneity bias. A model needs an identification strategy for the permanent factors as well as an appropriate calculation of its uncertainty.
Key Takeaways
- A two-period panel pairs each unit with itself across time.
- The unobserved effect is constant within a unit; the idiosyncratic error changes.
- Correlation between permanent effects and regressors causes heterogeneity bias.
- Within-unit error dependence concerns standard errors even without heterogeneity bias.
4.2 Regress changes on changes
First differencing (FD) subtracts each unit's first equation from its second. Because its unobserved effect is the same in both periods, that factor cancels without needing to be measured.
Derive the change equation
Subtract the levels equations term by term. The common constant cancels; the second-period dummy changes by 1; . Thus
where each delta means period 2 minus period 1 for the same unit. Keep an intercept: it estimates , the common time shift. The slope still estimates the original relationship between the regressor and outcome, now from variation in changes across units.
For the three cities, unemployment changes are 2, 1 and 2 percentage points, and crime changes are 4, 2 and 4 per 1,000 residents. Their FD regression is . The slope is positive, unlike the pooled slope of −5.0 distorted by permanent city differences.
Calculate OLS on changes
For five other cities, let unemployment changes be (−1, 0, 1, 2, 3) and crime changes be (−1, 3, 2, 6, 7). The means are 1 and 3.4. OLS uses deviations from these means, just as in a levels regression. The cross-product sum is 19 and the squared regressor-deviation sum is 10:
The predicted crime change is 1.5 at zero unemployment change. An additional percentage point of unemployment change adds 1.9 crimes per 1,000 to the fitted change.
Check what differencing leaves behind
Unbiasedness requires . Strict exogeneity is a sufficient condition: each period's idiosyncratic error has mean zero given regressors in both periods and the unit effect. Merely zero correlation between changes in the regressor and error supports consistency under the usual sampling conditions, but is weaker than the conditional-mean requirement for unbiasedness.
Feedback can violate strict exogeneity. If a crime shock prompts more police hiring next period, the future regressor responds to an earlier error. Differencing removes permanent city traits, but leaves that connection between changes. A lagged dependent variable also creates a problem: the earlier outcome contains the earlier error, which enters the differenced error with a minus sign.
Time-constant regressors, such as birthplace or distance to the coast, also cancel. Their separate levels effects cannot be estimated by FD. Their interaction with the second-period dummy can remain: its change equals the time-constant characteristic, allowing its effect to change between periods.
Check information and implementation
Changes in a regressor must vary across units. Little variation makes slope estimates imprecise; differencing can also increase the importance of measurement error and worsen attenuation bias. Use usual OLS standard errors if differenced errors are homoskedastic and independent across units, and robust errors if their variances differ.
In Stata, code period as 1 and 2:
xtset city period
regress D.crime D.unem, vce(robust)
For actual years 2015 and 2023, xtset city year, delta(8) declares the interval; a default one-year interval would yield missing differences. In R, compute within-city changes or use plm(crime ~ unem, data = pdata, model = "fd") with a correctly indexed panel. In Python, sort before differencing:
ordered = df.sort_values(["city", "period"])
d = ordered.groupby("city")[["crime", "unem"]].diff().dropna()
fit = smf.ols("crime ~ unem", data=d).fit(cov_type="HC1")
The columns in d now hold changes. Grouping prevents the last row of one city from becoming the baseline for another.
Key Takeaways
- FD removes every additive factor constant within a unit.
- The differenced intercept estimates the common time shift.
- Strict exogeneity is sufficient for the conditional-mean condition behind FD unbiasedness.
- Time-constant regressors disappear unless entered through a time-varying interaction.
- Weak change variation and measurement error can make FD less useful.
- Sort and difference within units, using the correct time interval.
4.3 Program effects from panel changes
A program-participation dummy can be first-differenced just like any other regressor. When nobody participates initially, the resulting regression compares the outcome changes of later participants and nonparticipants.
Connect FD with DiD
Start with
Subtract the first period:
If everyone starts untreated, is 1 for new participants and 0 for nonparticipants. With no controls, the OLS slope is the participants' mean change minus the nonparticipants' mean change: panel DiD. The intercept is the mean change among nonparticipants.
Firms receiving a training grant reduce defective items per 100 produced from 4.6 to 3.5, a change of −1.1. Firms without grants move from 3.9 to 3.7, a change of −0.2. The estimate is defective items per 100. It compares the treated change with the untreated path, not with zero change. If the outcome is log scrap rate and the coefficient is −0.25, the corresponding fitted proportional comparison is about 22.1% lower.
What the panel contributes
Both repeated-cross-section and panel DiD permit permanent group differences under their identifying conditions. A panel additionally compares each unit with itself and removes its own . Participation may depend on permanent characteristics, such as stable management quality, while the FD estimator remains unbiased if its remaining shocks meet the conditional-mean condition. Following the same units also avoids turnover in sample membership in a balanced panel.
Temporary selection remains a threat. If firms seek grants just after unusually high scrap rates, those rates may partly recover anyway. The change in the error then correlates with the change in participation. A panel does not remove this recovery; parallel untreated changes still underpin the program comparison.
Controls and participation changes
Time-varying controls enter as changes:
A change in sales or employment may be informative, but do not adjust away a change caused by the program when estimating its total effect. If units can enter or exit treatment, participation changes can be −1, 0 or 1. FD still applies, although a zero change can now describe either continuing participants or continuing nonparticipants.
Track missing units and additional periods
Attrition means units drop out between waves. Losing firms with poor outcomes can bias the observed comparison. Report losses, compare initial characteristics of retained and missing units, and establish whether missingness represents closure or a failure to collect data. A closed firm's employment is zero; an unanswered survey does not establish zero employment.
Card and Krueger followed the same restaurants. Their balanced-sample changes were +0.47 FTE in New Jersey and −2.28 in Pennsylvania, giving 2.75 with a standard error of 1.34. They retained permanently closed restaurants with employment set to zero.
With more than two periods, difference adjacent observations within each unit and include period dummies in the differenced equation. Adjacent error changes share a period's error, so inference must allow within-unit correlation over time.
Key Takeaways
- With no initial participants, FD on participation changes reproduces panel DiD.
- A panel removes permanent unit differences but leaves selection on temporary shocks.
- Time-varying controls enter as changes and should not absorb treatment channels.
- Treatment entry, no change and exit produce participation changes of 1, 0 and −1.
- Outcome-related attrition can bias comparisons.
- Multi-period differencing creates repeated changes within each unit.
Difference-in-Differences examples
1Pool surveys and let effects change
13 steps
- 1IntroductionWhat changes between surveys?
Suppose you have worker surveys from two years, each drawn fresh: pooled cross sections. You want to know whether pay changed for comparable workers and whether education became more strongly associated with pay. Those are separate questions: the first concerns a shift in level (a year dummy), and the second a shift in a slope (a year interaction). Start with how the samples were drawn, then build a regression that can express both comparisons.
- 2ExplanationIdentify the sample structure
Fresh independent samples in each year form pooled cross sections. A panel follows the same units over time. The distinction determines whether a unit can be paired with its own earlier observation.
Pooling can increase precision when the relationship is stable. Independence across samples does not require identical error variances; robust standard errors handle possible heteroskedasticity.
- 3ExplanationChoose a base year
Let be 1 for 2023 and 0 for 2015. A pooled model is
The omitted year is 2015. Its intercept is ; the 2023 intercept is . The year coefficient compares outcomes at the same x. With more years, omit one dummy when keeping an intercept, so the year indicators do not duplicate the constant column.
- 4ExampleRead the adjusted year shift
Pooling 1,800 workers in 2015 and 2,100 in 2023 gives 3,900 observations. A fitted log-earnings equation contains and controls for education and experience.
At fixed education and experience, the log difference is 0.18. The fitted proportional comparison is
A raw mean-log increase of 0.25 can be larger because worker characteristics also changed.
- 5ChallengeSeparate the raw and adjusted changes
A new four-year survey has fresh samples each year. Its raw mean-log income change from the base to the last year is 0.16, and the final year-dummy coefficient is 0.09. With an intercept, how many year dummies are needed, and which figure compares otherwise similar observations?
---reveal---
Use three year dummies. The coefficient 0.09 is the comparison holding included regressors fixed. The raw 0.16 also reflects changed sample characteristics.
- 6Key InsightDeflating logs changes year effects
If every nominal outcome in a year is divided by the same price index, the logged outcome loses the constant . Year dummies absorb this subtraction, leaving regressor slopes unchanged.
The base intercept shifts by , and each year coefficient by . When the base index is 1, the intercept stays unchanged. A nominal shift therefore need not represent a purchasing-power gain.
- 7ExplanationGive education a changing slope
Add the product of the year indicator and education:
In 2015 the education slope is . In 2023 it is . The interaction measures their difference. Keep the education main effect so the base-year slope is estimated instead of forced to zero.
- 8ExampleTest a slope change
Estimates of 0.070 for education and 0.015 for its year interaction give approximate returns of 7.0% and 8.5%. To test whether the return changed, use the interaction’s own standard error.
If that error is 0.005,
This exceeds the large-sample two-sided 5% cutoff of about 1.96. The test concerns a change in the education slope, not whether the later slope equals zero.
- 9ChallengeRead a narrowing group gap
A log-pay model estimates −0.24 for a group dummy and +0.06 for its later-year interaction. What is the later log-pay gap, and has its sign changed?
---reveal---
The later gap is . It remains negative but is smaller in magnitude. The positive interaction describes a narrowing gap; it does not replace the baseline coefficient or make the group’s later pay higher.
- 10ExplanationDefine the joint null
Fully interacting k regressors across two years estimates parameters. Testing only the k slope interactions asks whether slopes stayed the same, while retaining a different time intercept.
The full Chow test also restricts the intercept shift to zero, giving k + 1 restrictions. These nulls answer different questions. Several separate t tests are not a substitute for the requested joint test.
- 11ExampleCalculate the slope-stability F statistic
With 3,900 observations and three regressors, the unrestricted model has eight parameters and 3,892 residual degrees of freedom. For slope stability, q = 3. Restricted and unrestricted SSRs are 812.4 and 806.1:
The 5% critical value is about 2.6, so the equal-slopes null is rejected under the classical common-variance assumptions.
- 12ChallengeChoose the right stability test
A later-year intercept shift is expected, but you want to know whether three slopes changed. Residual variability is substantially larger in the later year. What restrictions and uncertainty calculation fit that question?
---reveal---
Jointly set the three slope interactions to zero while retaining the year dummy. Use a heteroskedasticity-robust joint test. Restricting the year dummy would also test intercept stability, and the classical SSR-based F test assumes a common variance.
- 13RecapRead the model as comparisons
Identify fresh samples versus repeated units before fitting a pooled model. Read a year dummy as an adjusted level comparison and a year interaction as a change in slope. For the later slope, add its two components. State the joint restrictions before choosing a stability test, and match its standard errors to the error structure.
2Build DiD from its missing outcome
18 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionAsk what would have happened
- 2ExplanationIdentify the counterfactual
- 3ExampleUse a policy comparison
- 4ConnectionWhy one difference is insufficient
- 5ChallengeChoose a useful untreated path
- 6ExplanationKeep four cells and two directions
- 7ExampleCalculate the treated change
- 8ExampleBuild the untreated after outcome
- 9ExampleRead the effect and its uncertainty
- 10ChallengeEstimate a relative reduction
- 11ExplanationTranslate cells into coefficients
- 12ExampleRebuild the treated-after mean
- 13TipControl for causes, not treatment channels
- 14ExplanationConvert a log comparison
- 15TipFit main effects and interaction
- 16ChallengeFind the effect in a new model
- 17ChallengeSeparate a precise mean from a credible cause
- 18RecapReport the comparison you estimated
3Judge the untreated comparison
16 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionA calculation needs a design
- 2ExplanationState parallel trends
- 3ExampleAccount for trend bias
- 4ConnectionChoose the outcome scale
- 5ChallengeDistinguish a gap from a trend
- 6ExplanationDistinguish permanent differences from temporary selection
- 7ExampleAn announcement can affect the baseline
- 8Key InsightTrack spillover direction
- 9ExplanationCheck events and sample membership
- 10ChallengeExplain the direction of bias
- 11ExampleTry a fake policy date
- 12TipProbe the comparison in several ways
- 13ExampleCalculate the third difference
- 14ExplanationState the DDD assumption
- 15ChallengeChoose between comparisons
- 16RecapMake the remaining assumption explicit
4Remove permanent effects with changes
20 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionCompare a unit with itself
- 2ExplanationBuild unit-period pairs
- 3ExplanationSeparate stable and temporary factors
- 4ExampleSee how pooling can reverse a slope
- 5ChallengeSeparate bias and dependence
- 6ExplanationSubtract the equations
- 7ExampleFit the cities’ changes
- 8ExampleEstimate a less exact relationship
- 9ExplanationCheck the error-change condition
- 10Key InsightFind usable change variation
- 11ChallengeFit a change model with an intercept
- 12TipDifference the intended pairs
- 13ConnectionDifference participation too
- 14ExampleCalculate a grant effect
- 15TipCheck why units enter and disappear
- 16ChallengeKeep a closed firm in the comparison
- 17ExplanationInclude suitable controls as changes
- 18ExplanationDifference additional periods
- 19ChallengeExplain what the panel has solved
- 20RecapUse changes with their remaining assumptions
Difference-in-Differences practice questions
Set 1: Build the comparison10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
A balanced panel records firms’ input and output as follows. An FD regression includes an intercept. What output change does it predict for an input increase of 3?
| Firm | Before (x, y) | After (x, y) |
|---|---|---|
| L | (1, 8) | (3, 13) |
| M | (2, 10) | (3, 13) |
| N | (4, 11) | (4, 12) |
Show answerHide answer
Set 2: Interpret models and test assumptions10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
xtset city year, Stata reports missing D.output values for both years despite complete output data. How should the researcher declare these two-wave data while retaining calendar years?Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Separate estimates from causal claims10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Evaluate complete policy comparisons10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Adjacent-period difference
Alternative control group
Anticipation
Ashenfelter dip
Attenuation bias
Attrition
Average treatment effect on the treated
B
Balanced panel
Base year
C
Change in the group gap
Chow test
Composite error
Composition change
Control group
Control variable
Counterfactual
D
DiD interaction coefficient
Difference-in-differences
E
External validity
F
First differencing
Full-time-equivalent employment
G
Group mean
H
Heterogeneity bias
I
Idiosyncratic error
Independently pooled cross section
Internal validity
L
Log-point change
N
Natural experiment
Nominal outcome
P
Panel DiD
Parallel trends
Parallel trends in levels
Parallel trends in logs
Participation change
Placebo date
Placebo group
Placebo outcome
Post-treatment control
Potential outcome
Pre-policy trend
R
Real outcome
Restricted model
S
Selection on temporary shocks
Simultaneous event
Slope stability
Spillover
Strict exogeneity
T
Time-constant regressor
Triple differences
Two-period panel
U
Unobserved effect
Unrestricted model
Untreated trend gap
W
Within-group error correlation
Within-unit variation
Y
Year dummy
Year–regressor interaction
Z
Zero conditional mean in differences
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.