Skip to contents

This article walks through one complete analysis and changes one specification at a time, so that the role of each argument can be seen on the same estimate. The case is the killing of Michael Brown in Ferguson, Missouri, on August 9, 2014, and the year of protest that followed. The outcome is the share of Americans who say the country spends too little on improving the conditions of Blacks, in the General Social Survey (GSS). It is the most complete of the applications in the article that accompanies the package, with five surveys before the event, two after it, and respondents of every age.

The design in one paragraph

An event with a date reaches everyone alive at that date, so no unexposed group exists afterward. The cohort discontinuity design holds age fixed instead and compares birth cohorts. Respondents aged 30 in the first survey after the event belong to one cohort, and respondents aged 30 in each earlier survey belong to earlier cohorts who reached that age before the event. The answers of those earlier cohorts trace a trend at age 30, the design extends that trend to the exposed cohort, and the estimate is the difference between what the exposed cohort reports and what the trend predicts. Repeating the comparison at every age gives the response of every cohort.

The question and the data

gss_culture is an extract of the cumulative GSS with one row per respondent. The design needs three columns, the survey year, the age of the respondent, and a survey weight, whose default names are year, age, and weight. The item natrace is coded 1 for too little, 2 for about right, and 3 for too much, and the GSS asks it of a random part of each sample.

library(cohortDD)
data(gss_culture)

gss_culture[gss_culture$year == 2016 & !is.na(gss_culture$natrace), ][1:4,
            c("year", "age", "sex", "race", "educ", "weight", "natrace")]
#>       year age sex race educ weight natrace
#> 59242 2016  47   1    1   16  0.727       1
#> 59243 2016  61   1    1   12  0.338       1
#> 59244 2016  72   1    1   16  1.391       2
#> 59245 2016  43   2    1   12  1.248       2

The onset and the straddling survey

The 2014 GSS was in the field from March to October, so some of its interviews took place after August 9. Those respondents are neither unexposed nor a usable exposed sample, and the column post_ferguson14 flags them so that they can be dropped. The remaining 2014 interviews form the last survey before the event, and 2016 is the first survey after it. Setting onset = 2015 tells the package that every survey before 2015 is a pre-event survey.

d <- subset(gss_culture, age <= 84 & post_ferguson14 == 0)
table(d$year[!is.na(d$natrace) & d$year >= 2006 & d$year <= 2018])
#> 
#> 2006 2008 2010 2012 2014 2016 2018 
#> 1313  863  873  864  881 1267 1043

plot_design() draws the comparison for respondents of all ages pooled: the survey means, the line fitted through the pre-event surveys, its extension to the first survey after the event, and the gap between that extension and what was observed.

plot_design(subset(d, year <= 2018), "natrace", onset = 2015, wave = 2016, H = 5,
            from = 2000, level = 1, scale = 100) +
  ggplot2::labs(y = "Too little spent on Blacks (%)")

The basic call

cdd() estimates the effect at each target age. Here wave is the exposed survey, H the number of pre-event surveys, order = 1 the local-linear fit, b the age half-width, and levels = 1 selects the response too little. Covariates enter through controls, and reweight holds each cohort’s composition on characteristics that do not change over the life course fixed across surveys.

ctrl <- c("factor(race)", "factor(sex)", "educ")
comp <- c("factor(race)", "factor(sex)")

fit <- cdd(d, "natrace", onset = 2015, wave = 2016, H = 5, order = 1, b = 5,
           ages = c(25, 45, 65), levels = 1, controls = ctrl, reweight = comp)
as.data.frame(fit)[, c("age", "cohort", "ate", "se", "lower", "higher",
                       "honest_lower", "honest_higher", "n1", "n0")]
#>   age cohort   ate     se   lower higher honest_lower honest_higher  n1   n0
#> 1  25   1991 0.219 0.0573  0.1066  0.331       0.0984         0.340 277  831
#> 2  45   1971 0.140 0.0576  0.0276  0.253       0.0213         0.260 206 1033
#> 3  65   1951 0.104 0.0630 -0.0200  0.227      -0.0203         0.227 218  717

Each row is one target age. The column ate is the estimated effect as a share, lower and higher bound the 95 percent sampling interval, and honest_lower and honest_higher bound the bias-aware interval, which adds the largest error the extrapolation could make if the trend bends by no more than a stated amount. The columns n1 and n0 count the exposed and the comparison respondents.

With about 250 exposed respondents per age band these estimates are imprecise, so the sections below work mostly with one number, the effect on everyone aged 20 to 70, which cdd_popavg() returns. A small wrapper keeps the settings in one place.

est <- function(..., wave = 2016, H = 5, order = 1, controls = ctrl, reweight = comp)
  cdd_popavg(d, "natrace", onset = 2015, waves = wave, H = H, order = order,
             controls = controls, reweight = reweight, levels = 1, ...)

main <- est()
main[, c("ate", "se", "lower", "higher", "honest_lower", "honest_higher")]
#>     ate     se lower higher honest_lower honest_higher
#> 1 0.172 0.0273 0.119  0.226        0.114          0.23

The share saying too little was 17.2 points above the extrapolated trend in 2016, with a sampling interval of 11.9 to 22.6 and a bias-aware interval of 11.4 to 23.0.

The number of pre-event surveys: H

More surveys make the fitted trend more precise, and they also reach further into the past, where the trend may have been different. The first step is to see whether the estimate depends on the choice.

byH <- do.call(rbind, lapply(3:8, function(h) cbind(H = h, est(H = h))))
plot_estimates(byH, by = "H", scale = 100, ref = main,
               xlab = "Number of pre-event surveys H", ylab = "Effect (points)")

In this and the later figures the thick bar is the 95 percent sampling interval and the thin bar the bias-aware interval, and the dashed line and band mark the main estimate. The estimate moves between 14.0 and 17.3 points, and it is least precise with three surveys.

cdd_bandwidth() makes the choice from the pre-event surveys alone. For each window and each extrapolant it estimates the mean squared error, which adds the squared worst-case bias to the variance, and marks the smallest.

bw <- cdd_bandwidth(d, "natrace", onset = 2015, wave = 2016, grid = 3:8, orders = c(0, 1),
                    ages = seq(20, 70, 5), b = 5, levels = 1, controls = ctrl, reweight = comp)
bw$selected[, c("H", "order", "risk", "best")]
#>   H order    risk  best
#> 1 3     0 0.00270  TRUE
#> 2 8     1 0.00295 FALSE
plot_bandwidth(bw, scale = 100) + ggplot2::labs(y = "Root mean squared error (points)")

Because the series was nearly flat before 2014, the rule prefers the kernel mean with three surveys, and for the local-linear fit it prefers the longest window. We nonetheless keep H = 5 with the local-linear fit as the main specification, since it was fixed before looking at the exposed survey, and report the selected one beside it. A local-linear fit applied to a flat trend remains valid and only has a wider interval, whereas a specification chosen after seeing the data is not covered by the stated intervals.

The extrapolant: order

With order = 0 the counterfactual is a weighted mean of the pre-event surveys, which is precise but biased when the trend has a slope. With order = 1 it is a line through them, which removes the slope bias at the cost of a larger variance.

km5 <- est(order = 0)
km3 <- est(H = 3, order = 0)
both <- rbind(cbind(spec = "Local-linear fit, H = 5", main),
              cbind(spec = "Kernel mean, H = 5", km5),
              cbind(spec = "Kernel mean, H = 3 (selected)", km3))
both[, c("spec", "ate", "se", "lower", "higher", "honest_lower", "honest_higher")]
#>                            spec   ate     se lower higher honest_lower honest_higher
#> 1       Local-linear fit, H = 5 0.172 0.0273 0.119  0.226        0.114         0.230
#> 2            Kernel mean, H = 5 0.164 0.0204 0.124  0.204        0.122         0.207
#> 3 Kernel mean, H = 3 (selected) 0.169 0.0215 0.127  0.211        0.126         0.213

On the same five surveys the two extrapolants give 17.2 and 16.4 points, and the kernel mean that the rule selects gives 16.9. The kernel mean has the smaller standard error in each case, and the agreement among the three shows that the choice does not drive the result here.

The age band: b

Each estimate pools respondents within b years of the target age, so a larger b trades detail by age for precision. The GSS has few respondents at each single age, which is why b = 5 is used here; a survey with thousands of respondents per age can use b = 1 or b = 2.

byb <- do.call(rbind, lapply(c(2, 3, 5, 7), function(b)
  cbind(b = b, as.data.frame(cdd(d, "natrace", onset = 2015, wave = 2016, H = 5, order = 1, b = b,
                                 ages = 45, levels = 1, controls = ctrl, reweight = comp)))))
byb[, c("b", "ate", "se", "n1", "n0")]
#>   b    ate     se  n1   n0
#> 1 2 0.0804 0.0801  98  473
#> 2 3 0.0863 0.0729 134  644
#> 3 5 0.1405 0.0576 206 1033
#> 4 7 0.1177 0.0495 290 1400

At age 45 the standard error falls from 8.0 points with b = 2 to 4.9 with b = 7, as the number of exposed respondents rises from 98 to 290. The population estimate does not depend on b, because it pools all ages in one band.

Covariates and composition: controls and reweight

Successive surveys differ in who answers them, and cohorts lose members selectively as they age. controls adjusts the comparison for differences between the exposed and the comparison samples, and reweight rescales each cohort’s respondents toward the cohort’s long-run composition.

adj <- rbind(cbind(spec = "No adjustment",             est(controls = NULL, reweight = NULL)),
             cbind(spec = "Controls only",             est(reweight = NULL)),
             cbind(spec = "Controls and composition",  main))
adj[, c("spec", "ate", "se", "lower", "higher")]
#>                       spec   ate     se lower higher
#> 1            No adjustment 0.158 0.0280 0.103  0.213
#> 2            Controls only 0.160 0.0270 0.107  0.213
#> 3 Controls and composition 0.172 0.0273 0.119  0.226

Without any adjustment the estimate is 15.8 points, with controls 16.0, and with both 17.2. The adjustment moves the estimate by about a point and a half, which is small relative to the estimate itself, so the shift is not produced by a change in who was interviewed.

The curvature bound: M

The bias-aware interval depends on how sharply the trend is allowed to bend, which the package calibrates from the pre-event series unless M is supplied. cdd_breakdown() reports the curvature at which the interval would first include zero.

brk <- cdd_breakdown(main)
brk[, c("ate", "se", "curv", "M0")]
#>     ate     se     curv      M0
#> 1 0.172 0.0273 0.000173 0.00482
m10 <- est(M = 10 * main$curv)
m10[, c("ate", "honest_lower", "honest_higher")]
#>     ate honest_lower honest_higher
#> 1 0.172       0.0759         0.268

The breakdown value is 28 times the calibrated curvature. Even at ten times the calibrated value the bias-aware interval runs from 7.6 to 26.8 points, so the conclusion does not rest on the calibration.

Placebo dates

The same estimator can be applied to surveys before the event, as if each had been the first survey after one. If the design is sound, these estimates should be close to zero, in the manner of a pre-trend test. Each pair below gives a pretend onset and the survey treated as exposed.

pl <- do.call(rbind, lapply(list(c(2005, 2006), c(2011, 2012), c(2013, 2014)), function(p)
  cdd_popavg(d, "natrace", onset = p[1], waves = p[2], H = 5, order = 1, levels = 1,
             controls = ctrl, reweight = comp)))
post <- est(wave = c(2016, 2018))
pre_post <- rbind(cbind(placebo = TRUE, pl), cbind(placebo = FALSE, post))
plot_estimates(pre_post, by = "wave", open = "placebo", scale = 100, vline = 2014.6,
               xlab = "Survey treated as the first one after an event", ylab = "Estimate (points)") +
  ggplot2::scale_x_continuous(breaks = seq(2006, 2018, 2))

The estimates at 2006, 2012, and 2014 (open markers) are 2.2, 1.5, 1.8 points, and none is distinguishable from zero. The estimates at 2016 and 2018 are 17.2 and 20.9. cdd_placebo() returns the same placebo estimates age by age.

Cohort groups and the population average

cdd_groups() estimates the effect for groups of cohorts defined by their age when the event began, and follows the same cohorts into later surveys.

grp <- cdd_groups(d, "natrace", onset = 2015, waves = c(2016, 2018), H = 5, order = 1,
                  levels = 1, controls = ctrl, reweight = comp)
plot_estimates(grp, by = "group", series = "wave", scale = 100, ref = main,
               xlab = "Cohort group (age in 2015)", ylab = "Effect (points)")

In 2016 the four groups moved by 18.7, 14.2, 18.8, 14.3 points from the youngest to the oldest, all inside the band of the population estimate. Adults in their sixties responded as much as adults in their twenties, a result that a comparison of the young with the old would have reported as no effect.

The age profile

Replacing the four groups with every single age gives the profile. plot_profile() draws the estimate with the sampling interval as the darker band and the bias-aware interval as the lighter one.

prof <- cdd(d, "natrace", onset = 2015, wave = 2016, H = 5, order = 1, b = 5, ages = 20:70,
            levels = 1, controls = ctrl, reweight = comp)
plot_profile(prof, scale = 100, ylab = "Effect (points)")

Neighboring estimates share most of their respondents, so the bends in the line are within what sampling error produces. The figure supports a statement about the level of the response at every age and not about its shape.

Later surveys

The 2018 survey observes the same cohorts three years after the onset, and the group figure above shows it as the lighter series. The population estimate is 20.9 points, and the bias-aware interval is wider than in 2016 because the trend is extended further.

post[, c("wave", "k", "ate", "lower", "higher", "honest_lower", "honest_higher")]
#>   wave k   ate lower higher honest_lower honest_higher
#> 1 2016 1 0.172 0.119  0.226        0.114         0.230
#> 2 2018 3 0.209 0.143  0.276        0.132         0.287

An estimate at a later survey measures everything that moved the item since the last pre-event survey, and the 2018 survey also follows the 2016 election, so it is best read as the effect of the period.

What each specification did here

Specification Argument What changing it did in this case
Straddling interviews post_ferguson14 filter Makes 2014 a clean pre-event survey.
Pre-event surveys H 14.0 to 17.3 points across 3 to 8 surveys; least precise at 3.
Extrapolant order Kernel mean 16.4, local-linear 17.2 on the same surveys; smaller standard error for the mean.
Age band b No effect on the population estimate; standard error at one age falls from 8.0 to 4.9 points between 2 and 7.
Covariates controls 15.8 without, 16.0 with.
Composition weights reweight 16.0 without, 17.2 with.
Curvature bound M Interval still excludes zero at ten times the calibrated value; breakdown at 28 times.
Placebo dates onset, wave 2.2, 1.5, 1.8 points before the event against 17.2 after.
Cohort groups cdd_groups() 18.7, 14.2, 18.8, 14.3 points; no gradient by age.
Later survey wave 20.9 points in 2018, with a wider bias-aware interval.

Where to go next

The other articles take each step further: the estimator and its inference, choosing the extrapolant and the window, tests and falsification, visualization, and groups, trajectories and population averages. A second worked case, with a single pre-event survey, replicates a published difference-in-differences on attitudes toward the police after the killing of George Floyd.