Skip to contents

This article explains what cdd() computes at one target age: the two extrapolants, their weights, the bias of each, the standard error, the bias-aware interval, and the breakdown curvature. It reproduces the numbers by hand for one age so that every column of the output can be traced to a calculation. The derivations behind each step are in the article that accompanies the package.

Setup at one target age

The running example is the 1992-93 shock and the outcome homosex, level 1 (“always wrong”). The George Floyd example of the replication article has one pre-shock survey, which leaves no cohort trend to fit; this article therefore uses a General Social Survey example with five pre-shock surveys. The onset is 1992 and the exposed survey is 1993, one year later (k = 1). Take the target age 45 with age half-width b = 5. The age band then contains respondents aged 40 to 50 in every survey. In the 1993 survey these respondents were born around 1948. In an earlier survey the respondents of the same ages were born earlier by the number of years between the two surveys.

Measure each survey by its distance in years from the exposed survey, which the code below calls u. The pre-shock surveys of 1987 to 1991 sit 6 to 2 years before it, so u runs from -6 to -2. At a fixed age, this distance is also a distance in birth years: respondents aged 45 in 1987 were born six years before the target cohort. The pre-shock surveys therefore show what successive cohorts answered at this age without the shock. What the design needs is the answer the target cohort would have given at this age without the shock, the counterfactual at u = 0, and the effect is the mean of the exposed respondents minus that counterfactual. The first quantity is observed. The second must be extrapolated, because no survey observes the target cohort at this age without the shock.

The code below computes the survey means in the age band.

band <- subset(gss_culture, !is.na(homosex) & age >= 40 & age <= 50)
band$y <- as.numeric(band$homosex == 1)

pre <- subset(band, year %in% 1987:1991)
by_survey <- split(pre, pre$year)
cells <- data.frame(
  year = as.numeric(names(by_survey)),
  n    = sapply(by_survey, nrow),
  ybar = sapply(by_survey, function(d) weighted.mean(d$y, d$weight)),
  wsum = sapply(by_survey, function(d) sum(d$weight)),
  row.names = NULL
)
cells$u <- cells$year - 1993

exposed <- subset(band, year == 1993)
ybar_exposed <- weighted.mean(exposed$y, exposed$weight)

cells[, c("year", "u", "n", "ybar")]
#>   year  u   n  ybar
#> 1 1987 -6 310 0.763
#> 2 1988 -5 172 0.752
#> 3 1989 -4 191 0.699
#> 4 1990 -3 167 0.788
#> 5 1991 -2 181 0.767
ybar_exposed
#> [1] 0.633

Two extrapolants

Both extrapolants estimate the counterfactual as a weighted combination of the pre-shock survey means, with weights that sum to one, and the effect estimate is the exposed mean minus that combination. They differ in the weights.

Kernel mean (order = 0). The counterfactual is a weighted average of the pre-shock means. All weights are positive. It assumes that the cohort trend is flat over the window, so a trend with a slope biases it.

Local-linear fit (order = 1). The counterfactual is the value at u = 0 of a weighted regression line fitted to the pre-shock means. It follows a linear cohort trend exactly, and only curvature biases it. The price is a larger variance, because extrapolating a fitted line amplifies the noise in the survey means.

Kernel weights

Each pre-shock survey receives a kernel weight that declines with its distance from the shock. The kernel is applied to the rank of the survey and not to its calendar year, because surveys are unevenly spaced. wave_weights() returns these weights.

wave_weights(1987:1991, kernel = "triangular")
#>  1991  1990  1989  1988  1987 
#> 0.999 0.799 0.599 0.399 0.199

The most recent pre-shock survey has the largest weight and the earliest of the H surveys has the smallest positive weight. Other choices are "rectangular", "epanechnikov", and "gaussian".

From kernel weights to extrapolation weights

Each survey’s kernel weight is multiplied by the sum of the survey weights of its respondents in the age band, which the code calls omega. For the kernel mean, a survey’s extrapolation weight is its share of the total omega. For the local-linear fit, the weights are those of a weighted least-squares line evaluated at u = 0, and the code below computes them from the weighted sums of u and of u squared.

kw <- wave_weights(cells$year, "triangular")
cells$omega <- kw[as.character(cells$year)] * cells$wsum

S0 <- sum(cells$omega)
S1 <- sum(cells$omega * cells$u)
S2 <- sum(cells$omega * cells$u^2)

cells$l_mean   <- cells$omega / S0
cells$l_linear <- cells$omega * (S2 - S1 * cells$u) / (S0 * S2 - S1^2)

round(cells[, c("year", "u", "l_mean", "l_linear")], 3)
#>   year  u l_mean l_linear
#> 1 1987 -6  0.108   -0.423
#> 2 1988 -5  0.127   -0.248
#> 3 1989 -4  0.213   -0.005
#> 4 1990 -3  0.233    0.445
#> 5 1991 -2  0.319    1.230
w_long <- rbind(
  data.frame(year = cells$year, weight = cells$l_mean,   extrapolant = "Kernel mean"),
  data.frame(year = cells$year, weight = cells$l_linear, extrapolant = "Local-linear fit")
)
ggplot(w_long, aes(factor(year), weight)) +
  geom_col(fill = "#1B2A41", width = 0.6) +
  geom_hline(yintercept = 0) +
  facet_wrap(~ extrapolant) +
  labs(x = "Pre-shock survey", y = "Weight") +
  theme_cdd()

Bar chart of the weight each pre-shock survey receives under the kernel mean and under the local-linear fit.

The kernel mean spreads positive weights over the window. The local-linear fit puts a weight above one on the most recent survey and negative weights on the earliest ones. The negative weights are what allow it to continue a slope: it adds to the most recent mean the change that the line implies between the centre of the window and u = 0. Two properties hold for the local-linear weights: they sum to one, and the weighted sum of the distances u is zero.

c(sum_l = sum(cells$l_linear), sum_l_u = sum(cells$l_linear * cells$u))
#>     sum_l   sum_l_u 
#>  1.00e+00 -1.33e-15

The estimates by hand and from cdd()

m0_mean   <- sum(cells$l_mean * cells$ybar)
m0_linear <- sum(cells$l_linear * cells$ybar)

c(kernel_mean = ybar_exposed - m0_mean, local_linear = ybar_exposed - m0_linear)
#>  kernel_mean local_linear 
#>       -0.122       -0.148
fit0 <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = 5, b = 5,
            order = 0, ages = 45, levels = 1)
fit1 <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = 5, b = 5,
            order = 1, ages = 45, levels = 1)

c(kernel_mean = fit0$ate, local_linear = fit1$ate)
#>  kernel_mean local_linear 
#>       -0.122       -0.148

The two calculations agree. cdd() works with individual respondents and not with survey means, which gives the same point estimate when there are no covariates and lets it add covariates and compute standard errors from individual residuals.

The figure shows the two extrapolations.

line <- coef(lm(ybar ~ u, data = cells, weights = omega))
ggplot(cells, aes(u, 100 * ybar)) +
  geom_segment(aes(x = -6, xend = 0, y = 100 * m0_mean, yend = 100 * m0_mean),
               linetype = "dashed", colour = "grey40") +
  geom_segment(aes(x = -6, xend = 0, y = 100 * (line[1] - 6 * line[2]), yend = 100 * line[1]),
               colour = "#1F5F9E") +
  geom_point(size = 2) +
  annotate("point", x = 0, y = 100 * m0_mean, colour = "grey40", size = 2.4) +
  annotate("point", x = 0, y = 100 * m0_linear, colour = "#1F5F9E", size = 2.4) +
  annotate("point", x = 0, y = 100 * ybar_exposed, shape = 21, fill = "white", size = 2.4) +
  annotate("text", x = 0.15, y = 100 * c(m0_mean, m0_linear, ybar_exposed), hjust = 0, size = 3,
           label = c("kernel mean", "local-linear fit", "observed")) +
  scale_x_continuous(breaks = -6:0, limits = c(-6, 1.3)) +
  labs(x = "u (survey year minus 1993)", y = "Share \"always wrong\" (percent)") +
  theme_cdd()
#> Warning in geom_segment(aes(x = -6, xend = 0, y = 100 * m0_mean, yend = 100 * : All aesthetics have length 1, but the data has 5 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing a single row.
#> Warning in geom_segment(aes(x = -6, xend = 0, y = 100 * (line[1] - 6 * line[2]), : All aesthetics have length 1, but the data has 5 rows.
#> ℹ Please consider using `annotate()` or provide this layer with data containing a single row.

Pre-shock survey means at ages 40 to 50, the kernel mean and the local-linear fit extrapolated to the exposed survey, and the observed exposed mean.

Black points are the pre-shock survey means. The dashed line is the kernel mean and the solid line is the local-linear fit, each carried to u = 0. The open point is the observed mean of the exposed respondents. The effect estimate is the vertical distance from the open point to the extrapolated point.

Bias

Neither extrapolant recovers the counterfactual exactly unless the cohort trend has a particular shape, and the two miss different things.

Kernel mean. Its leading bias is proportional to the slope of the cohort trend: the slope times the weighted mean distance of the window from the target. cdd() returns that distance as ubar. It is negative because all pre-shock surveys lie before the exposed survey. If the outcome was rising across cohorts, the kernel mean understates the counterfactual and overstates the effect, and the reverse holds for a falling trend.

Local-linear fit. The second property of its weights removes the slope term, so ubar is zero. What remains depends on curvature, that is, on how fast the slope of the cohort trend changes from one cohort to the next. If that curvature is at most M, the bias of the local-linear fit is at most M times a bias factor. The bias factor depends only on the weights and the spacing of the surveys, not on the outcome, and cdd() returns it as bb.

c(B_by_hand = 0.5 * sum(abs(cells$l_linear) * cells$u^2), bb = fit1$bb)
#> B_by_hand        bb 
#>      15.2      15.2
c(ubar_by_hand = sum(cells$l_mean * cells$u), ubar = fit0$ubar)
#> ubar_by_hand         ubar 
#>        -3.47        -3.47

The bias factor grows quickly with the distance between the window and the exposed survey and with the length of the window. A longer window lowers the variance and raises the bias factor, and this is the trade-off behind the choice of H (see Choosing the extrapolant and the window).

Standard error

The estimate is a difference between two independent pieces, the mean of the exposed respondents and the extrapolated counterfactual, so their variances add. The first is the usual variance of a weighted mean. The second sums the squared residuals of the pre-shock respondents, each multiplied by the square of the weight that respondent receives in the extrapolation. It is larger for the local-linear fit, because its weights are larger in absolute value. The column sum_l2 reports the sum of those squared weights.

rbind(kernel_mean  = unlist(as.data.frame(fit0)[, c("ate", "se", "lower", "higher", "sum_l2")]),
      local_linear = unlist(as.data.frame(fit1)[, c("ate", "se", "lower", "higher", "sum_l2")]))
#>                 ate     se  lower  higher  sum_l2
#> kernel_mean  -0.122 0.0389 -0.198 -0.0454 0.00154
#> local_linear -0.148 0.0574 -0.261 -0.0356 0.01292

lower and higher are the usual confidence interval, ate plus or minus a normal critical value times se, with the level set by conf. This interval is centred correctly only if the extrapolation is unbiased.

cdd_bootstrap() gives an alternative standard error by resampling respondents within birth cohorts. It is slower, and it is mainly useful when the composition weights from reweight add sampling variability that the formula above treats as fixed.

The bias-aware interval

The confidence interval ignores extrapolation bias. The bias-aware interval widens it by the bias bound, M times bb, on each side. If the curvature of the cohort trend is at most M, this interval covers the effect with at least the nominal probability, whatever the shape of the trend within that limit. cdd() returns it as honest_lower and honest_higher.

The bound M cannot be estimated from the data without further assumptions, so it is a sensitivity parameter. There are two ways to set it.

  • Leave M = NULL. cdd() then uses a rule-of-thumb value, reported as curv: twice the absolute quadratic coefficient of a quadratic in survey year fitted to all pre-shock surveys in the age band. This calibrates M to the curvature seen before the shock.
  • Pass a number, for example M = 0.002, to state the bound directly. The units are outcome units per year squared.
as.data.frame(fit1)[, c("age", "ate", "se", "lower", "higher", "bb", "curv",
                        "honest_lower", "honest_higher")]
#>   age    ate     se  lower  higher   bb     curv honest_lower honest_higher
#> 1  45 -0.148 0.0574 -0.261 -0.0356 15.2 0.000458       -0.268       -0.0287

fit1_M <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = 5, b = 5,
              order = 1, ages = 45, levels = 1, M = 0.001)
as.data.frame(fit1_M)[, c("age", "ate", "honest_lower", "honest_higher")]
#>   age    ate honest_lower honest_higher
#> 1  45 -0.148       -0.276       -0.0204

Two cautions apply. First, the rule-of-thumb curvature is itself an estimate from few surveys and can be noisy at a single age. Second, the bound covers the curvature bias only. For the kernel mean the leading bias is the slope term described above, which the curvature bound does not limit, so honest_lower and honest_higher from an order = 0 fit do not protect against a sloping cohort trend.

Breakdown curvature

Instead of choosing M, one can ask how large it would have to be before the bias-aware interval includes zero. This value is the breakdown curvature: the distance between the estimate and zero that the confidence interval leaves, divided by the bias factor, and zero if the confidence interval already includes zero. A conclusion that the effect is not zero survives any curvature below it. cdd_breakdown() adds it as the column M0.

fit3 <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = 5, b = 5,
            order = 1, ages = c(25, 45, 65), levels = 1)
as.data.frame(cdd_breakdown(fit3))[, c("age", "ate", "se", "bb", "curv", "M0")]
#>   age     ate     se   bb     curv      M0
#> 1  25 -0.1692 0.0595 15.2 0.001129 0.00345
#> 2  45 -0.1481 0.0574 15.2 0.000458 0.00234
#> 3  65 -0.0353 0.0693 16.1 0.000468 0.00000

Compare M0 with curv. When M0 exceeds the rule-of-thumb curvature, the bias-aware interval at that curvature excludes zero. When M0 is zero, the ordinary confidence interval already includes zero.

Covariates and composition

Two arguments adjust for differences between the exposed respondents and the pre-shock respondents other than the shock.

controls adds covariates to the fit. The counterfactual is predicted for each exposed respondent at that respondent’s covariate values, so the comparison holds the listed covariates at the distribution of the exposed sample. The extrapolation weights then also reproduce the covariate means of the exposed sample.

reweight addresses changes in the composition of a cohort across surveys, which arise from differential mortality, migration, and nonresponse. For each cohort it reweights the respondents observed in the window so that their distribution of the listed covariates matches the distribution of the same cohort pooled over the surveys before the window. Only covariates that do not change over the life course, such as sex and race, belong here.

fit_cov <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = 5, b = 5,
               order = 1, ages = c(25, 45, 65), levels = 1,
               controls = c("factor(race)", "factor(sex)", "educ"),
               reweight = c("factor(race)", "factor(sex)"))
as.data.frame(fit_cov)[, c("age", "ate", "se", "bb")]
#>   age     ate     se   bb
#> 1  25 -0.1343 0.0591 15.7
#> 2  45 -0.1482 0.0544 15.5
#> 3  65 -0.0353 0.0661 16.8

Summary of the output columns

Column Meaning
ate Mean of the exposed respondents minus the extrapolated counterfactual
se Square root of the exposed-mean variance plus the variance of the extrapolated counterfactual
lower, higher ate minus and plus the critical value times se
bb Bias factor; multiplied by M it bounds the curvature bias
curv Rule-of-thumb curvature, used as M when M = NULL
honest_lower, honest_higher Bias-aware interval: the confidence interval widened by M times bb on each side
ubar Weighted mean distance of the window from the target, zero for the local-linear fit
sum_l2 Sum of squared extrapolation weights over pre-shock respondents
slope Fitted slope of the local-linear fit, per year
sigma2 Weighted residual variance of the fit
n1, n0 Numbers of exposed and pre-shock respondents in the age band