Scott's Mixtape Substack

Scott's Mixtape Substack

Difference-in-Differences

TWFE Continuous Diff-in-Diff Decomposition: Weights Applied To Outcomes

scott cunningham's avatar
scott cunningham
Apr 22, 2026
∙ Paid

In the last couple of substacks, I walked us through the decomposition of the two-way fixed effects (TWFE) estimator when the treatment is continuous and the design is difference-in-differences. I even made a shiny app to illustrate it, which you can check out here. We learned this formula:

\(\beta^{\text{twfe}} \;=\; \int_{d_L}^{d_U} \underbrace{\frac{(l - E[D]) \cdot f_D(l)}{\text{Var}(D)}}_{w^{\text{lev}}(l)} \cdot [m(l) - m(0)]\, dl\)

This is going to be the core formula that I’m going to learn best even though it is only one of the four decompositions that the authors report in their paper (Table 1).

Notice then that the TWFE coefficient basically has four distinct pieces:

  1. integrating over doses. The TWFE is a weighted average over the support of the treatment dosage. That uses the density f_D(l) to map out support over l, the treatment dosage values.

  2. the weight. There’s three pieces to the weight. There’s the re-centering of the dose, l-E[D]. This takes a particular unit’s dosage and subtracts the mean over the entire sample. So maybe my dose is 0.1 but the mean 1, then the recentering would be 0.1-1 or -0.9. Notice there that the recentering introduces a negative value though — if you are below the mean, that is mechanically negative.

  3. variance. And last, the variance of the dose itself rescales the weight.

  4. long differenced outcomes. The last piece is m(l)-m(0), where m() is the outcome of interest.

Today what I want to do is fairly straightforward. I want to use our dataset Lu & Yu (2015), estimate two-way fixed effects, report that, and then reconstruct the same coefficient using the weighted average of the differenced m(l)-m(0), where the weights are those scaled recentered doses I just mentioned.

But first, I flipped a coin three times, and once again, it came up heads twice. As this is primarily a diff-in-diff post today, and less so a Claude Code post, I’m going to paywall it. But maybe today consider becoming a paying subscriber! But as a teaser, here’s the video of the updated shiny app so that you can see what’s below.

Scott's Mixtape Substack is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

User's avatar

Continue reading this post for free, courtesy of scott cunningham.

Or purchase a paid subscription.
© 2026 scott cunningham · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture