Skip to contents

The single-year profile from cdd() has one estimate per age, each with a wide interval. Three wrappers summarize the same design at a coarser level.

  • cdd_groups() estimates the effect for age groups, either by age in the exposed survey or by age at onset.
  • cdd_popavg() estimates one effect for the whole age range.
  • cdd_design() runs all of these, with placebo dates, in one call.
library(cohortDD)
library(ggplot2)
data(ces_police)

ctl <- c("factor(sex)", "factor(educ)")

The running example is the killing of George Floyd in May 2020 and the outcome unsafe (“Do the police make you feel safe?”, from 0 mostly safe to 1 mostly unsafe) among non-Hispanic Whites in the Cooperative Election Study, the case studied by Keskintürk (2026). The onset is 2020 and the exposed surveys are 2020 (k = 0) and 2022 (k = 2). The item has one pre-shock survey, 2016, so every call uses the kernel mean with H = 1 and order = 0: each group is compared with respondents who were the same age in 2016.

How a group estimate is computed

A group estimate is one call to cdd() in which the target age is the midpoint of the group and the age half-width is half the width of the group. The group aged 30 to 44 has midpoint 37 and half-width 7, so all respondents aged 30 to 44 enter one comparison. The estimate is the effect averaged over the cohorts in the group, weighted by their numbers in the exposed survey.

Groups are described by a data frame with the columns label, mid, and hw. The default has four groups.

data.frame(label = c("20-30", "30-44", "45-59", "60-74"),
           mid   = c(25, 37, 52, 67),
           hw    = c(5, 7, 7, 7))
#>   label mid hw
#> 1 20-30  25  5
#> 2 30-44  37  7
#> 3 45-59  52  7
#> 4 60-74  67  7

Because each group sets its own age band, cdd_groups() and cdd_popavg() ignore the arguments b and ages. All other arguments of cdd(), such as H, order, levels, controls, and reweight, are passed through.

Age groups in one exposed survey

With align = "interview", groups are defined by age in the exposed survey. This is the grouped version of the age profile.

g20 <- cdd_groups(ces_police, "unsafe", onset = 2020, wave = 2020, H = 1,
                  order = 0, continuous = TRUE, align = "interview", controls = ctl)
g20[, c("group", "wave", "age", "cohort", "ate", "se", "lower", "higher", "n1")]
#>   group wave age cohort      ate      se   lower   higher    n1
#> 1 20-30 2020  25   1995  0.09715 0.00834  0.0808  0.11350  7079
#> 2 30-44 2020  37   1983  0.07276 0.00570  0.0616  0.08393 10073
#> 3 45-59 2020  52   1968 -0.00631 0.00429 -0.0147  0.00210 10871
#> 4 60-74 2020  67   1953 -0.00912 0.00390 -0.0168 -0.00148 11350

Each row is one group. age is the midpoint age, cohort is the birth year of the midpoint, and the remaining columns are as in the output of cdd(). The two groups under 45 moved toward feeling unsafe, by 0.10 and 0.07 on the 0-1 scale, and the two older groups did not.

The groups can be overlaid on the single-year profile.

fit <- cdd(ces_police, "unsafe", onset = 2020, wave = 2020, H = 1, b = 2,
           order = 0, ages = 20:70, continuous = TRUE, controls = ctl)
plot_profile(fit, groups = g20, honest = FALSE,
             ylab = "Effect on feeling unsafe (0-1 scale)")

Single-year age profile with the four age-group estimates overlaid.

Custom groups

Pass a data frame to groups to use other age ranges. The example uses the two groups of the difference-in-differences in Keskintürk (2026), respondents aged 18 to 29 in 2020 and everyone older.

two <- data.frame(label = c("18-29", "30-74"),
                  mid   = c(23.5, 52),
                  hw    = c(5.5, 22))
g_two <- cdd_groups(ces_police, "unsafe", onset = 2020, wave = 2020, H = 1,
                    order = 0, continuous = TRUE, align = "interview", controls = ctl,
                    groups = two)
g_two[, c("group", "ate", "se", "n1")]
#>   group    ate      se    n1
#> 1 18-29 0.1014 0.00843  7058
#> 2 30-74 0.0148 0.00273 32294
diff(rev(g_two$ate))   # young minus old
#> [1] 0.0866

The difference between the two group estimates, about 0.09, is the difference-in-differences. It is one contrast between two parts of the profile, and the four-group table above shows that the “old” group mixes cohorts aged 30 to 44, who moved almost as much as the young, with cohorts over 45, who did not.

Following cohorts across surveys

A group defined by age in the exposed survey contains different people in each survey: the respondents aged 20 to 30 in 2022 are not the cohorts who were 20 to 30 in 2020. To follow the same cohorts, define the groups by age at onset. With align = "onset" the labels refer to age at the onset, and the target age is advanced by k years in the survey taken k years since onset.

traj <- cdd_groups(ces_police, "unsafe", onset = 2020,
                   waves = c(2020, 2022), H = 1, order = 0,
                   continuous = TRUE, align = "onset", controls = ctl)
traj[, c("group", "wave", "k", "age", "cohort", "ate", "se")]
#>   group wave k age cohort      ate      se
#> 1 20-30 2020 0  25   1995  0.09715 0.00834
#> 2 30-44 2020 0  37   1983  0.07276 0.00570
#> 3 45-59 2020 0  52   1968 -0.00631 0.00429
#> 4 60-74 2020 0  67   1953 -0.00912 0.00390
#> 5 20-30 2022 2  27   1995  0.14302 0.00845
#> 6 30-44 2022 2  39   1983  0.10655 0.00595
#> 7 45-59 2022 2  54   1968  0.04457 0.00438
#> 8 60-74 2022 2  69   1953  0.01943 0.00398

The column cohort is constant within a group, which confirms that the same birth cohorts are followed, and age rises with k. The sequence of estimates for one group is the trajectory of that group’s effect over k.

In every row the counterfactual comes from the same pre-shock survey, 2016. What changes with wave is the distance of the extrapolation, four years for 2020 and six for 2022. The bias factor bb grows with that distance, from 8 at four years to 18 at six: with one pre-shock survey it is half the squared distance.

subset(traj, group == "20-30", select = c(wave, k, ate, se, bb))
#>   wave k    ate      se bb
#> 1 2020 0 0.0972 0.00834  8
#> 5 2022 2 0.1430 0.00845 18

plot_dynamics() draws the trajectories.

plot_dynamics(traj, focal = "20-30", ylab = "Effect on feeling unsafe (0-1 scale)")

Trajectories of the effect by years since onset for four cohort groups.

The black line with confidence bars is the group named in focal and the grey lines are the other groups. A trajectory that moves further from zero as k grows indicates a response that continued after the shock, and a flat trajectory indicates a shift that was retained without further change. Here every group is higher in 2022 than in 2020, including the two older groups that had not moved in 2020. A rise of similar size in every group is what a drift of the item at fixed age would also produce, and with one pre-shock survey the design cannot separate the two. The gap between the young and the old groups is about the same in both years (0.11 and then 0.12 between the youngest and the oldest), and that gap does not depend on the drift. The replication article sizes the drift with a related item.

Population average

cdd_popavg() pools all respondents aged lo to hi into one estimate per exposed survey. It is the number to report when a single summary of the shock is needed, and it is the natural statistic for placebo comparisons across dates.

pa <- cdd_popavg(ces_police, "unsafe", onset = 2020,
                 waves = c(2020, 2022), lo = 20, hi = 70,
                 H = 1, order = 0, continuous = TRUE, controls = ctl)
pa[, c("group", "wave", "k", "ate", "se", "lower", "higher")]
#>   group wave k    ate      se  lower higher
#> 1 20-70 2020 0 0.0352 0.00290 0.0295 0.0409
#> 2 20-70 2022 2 0.0727 0.00302 0.0668 0.0786

The population average is defined by age in the exposed survey, so the cohorts it covers shift by k years from one survey to the next. It has the smallest standard error of all the summaries because it uses every respondent in the age range. Pooling ages does not reduce the bias factor, which depends on the spacing of the surveys, so the population average is no less exposed to drift than a group estimate. Here it is 0.035 in 2020, an average of a clear response under 45 and none above.

Everything in one call: cdd_design()

cdd_design() runs the population average, the single-year profile, the age groups, the cohort groups, and the placebo versions for one outcome, and returns one data frame.

des <- cdd_design(ces_police, "unsafe", onset = 2020,
                  waves = c(2020, 2022),
                  ages = seq(20, 70, by = 5), b = 2,
                  H = 1, order = 0, continuous = TRUE, controls = ctl)
with(des, table(type, wave))
#>         wave
#> type     2020 2022
#>   cgroup    4    4
#>   group     4    4
#>   main     11   11
#>   popavg    1    1

The column type identifies the rows.

type Content Produced by
popavg Population-average effect per exposed survey cdd_popavg()
main Single-year age profile per exposed survey cdd() with ages and b
group Age groups by age in the exposed survey cdd_groups(align = "interview")
cgroup Cohort groups by age at onset cdd_groups(align = "onset")
placebo_popavg, placebo, placebo_cgroup The same quantities at each placebo date the same functions with the placebo onset

Placebo dates are given in the argument placebos, a list of pairs c(onset, wave) as in cdd_placebo(). The unsafe item has no survey before 2016, so no placebo date is available and the call above leaves placebos empty. Set profile = FALSE to skip the single-year profile, which is the slowest part.

Subsets of the result feed the plotting functions.

plot_profile(subset(des, type == "main"), facet = "wave", honest = FALSE,
             ylab = "Effect on feeling unsafe (0-1 scale)")

Age profiles in 2020 and 2022 taken from the cdd_design output.

plot_dynamics(subset(des, type == "cgroup"), focal = "30-44",
              ylab = "Effect on feeling unsafe (0-1 scale)")

Trajectories of the cohort groups taken from the cdd_design output.

subset(des, type == "popavg", select = c(type, onset, wave, k, ate, se))
#>      type onset wave k    ate      se
#> 1  popavg  2020 2020 0 0.0352 0.00290
#> 21 popavg  2020 2022 2 0.0727 0.00302

Which summary to report

  • Use the population average for the overall size of the shock and for comparisons with placebo dates.
  • Use age groups by age in the exposed survey to describe who responded at a given date.
  • Use cohort groups by age at onset to describe what happened to the same people afterwards.
  • Use the single-year profile as the detailed picture behind the group estimates, keeping in mind that neighbouring ages are not independent.

Reference

Keskintürk, T. (2026). Generational imprinting: How political events shape cohorts. Social Forces. doi:10.1093/sf/soag143