Quick answer
Difference-in-differences estimates the effect of a change by subtracting the before-after change in a comparison group from the before-after change in the treated group. It is valid when both groups would have moved in parallel had nothing changed.
Formula: DiD = (Treated after − Treated before) − (Comparison after − Comparison before)
What is difference-in-differences?
Difference-in-differences (DiD, also written difference in differences or diff-in-diff) estimates the effect of a change by comparing how an outcome moved in a group that got the change with how it moved, over the same period, in a group that did not. The first difference is after minus before within each group. The second is the treated group's change minus the comparison group's change:
DiD = (treated after − treated before) − (comparison after − comparison before)
Each subtraction removes something. Differencing over time removes whatever is permanently different between the two groups, such as one market always converting better. Subtracting the comparison group's change removes whatever hit both groups at once, such as a season or a general trend. What is left is attributed to the change, provided one key assumption holds.
The design is a standard tool when a change cannot be randomized but arrives in one place and not another. A well-known application is David Card and Alan Krueger's study of the 1992 rise in New Jersey's minimum wage from $4.25 to $5.05 an hour, using fast-food restaurants in neighboring eastern Pennsylvania as the comparison. Employment in the New Jersey stores rose relative to Pennsylvania by 2.76 full-time-equivalent employees per store.
The 2×2 table: a rollout released in one country
Sample data: a new localized checkout goes live in Canada. Australia keeps the old one. The outcome is checkout completion rate (completed orders ÷ checkouts started), measured for four weeks before and four weeks after.
| Country | 4 weeks before | 4 weeks after | Change |
|---|---|---|---|
| Canada (treated) | 11,000 / 20,000 = 55.0% | 12,810 / 21,000 = 61.0% | +6.0 points |
| Australia (comparison) | 8,320 / 16,000 = 52.0% | 8,910 / 16,500 = 54.0% | +2.0 points |
| Gap, Canada − Australia | +3.0 points | +7.0 points | +4.0 points |
Three readings of the same four numbers:
- Before-and-after in Canada only: +6.0 points. This credits the checkout with whatever else raised completion in those weeks.
- After-period comparison only: 61.0% − 54.0% = 7.0 points. This credits it with the 3-point gap that existed before.
- Difference-in-differences: 6.0 − 2.0 = 4.0 points (equivalently 7.0 − 3.0).
The estimate implies a counterfactual: without the new checkout, Canada would have finished at 55.0% + 2.0 = 57.0%. It finished at 61.0%. Applied to 21,000 checkouts, 4 points is about 840 extra completed orders in the period.
The regression form
The same estimate comes from a regression with two indicator variables and their product:
Y = β0 + β1·Treated + β2·After + β3·(Treated × After) + error
| Coefficient | Meaning | Value in the sample |
|---|---|---|
| β0 | Comparison group, before | 52.0% |
| β1 | Standing gap between groups | +3.0 points |
| β2 | Change over time shared by both | +2.0 points |
| β3 | The difference-in-differences estimate | +4.0 points |
The regression form is useful when you want to add several periods, several regions or control variables, and to compute uncertainty in a defensible way. It does not make the assumption weaker. Adding controls that were themselves affected by the change (for example, number of sessions after the new checkout) can distort β3.
The parallel trends assumption
DiD is valid for the causal effect if, without the change, the two groups would have moved in parallel. They may start at different levels; their changes must have been the same. This statement concerns a world that did not happen, so it cannot be proven. What you can do is look at the periods before the change.
Sample weekly completion rates for the four weeks before launch:
| Week before launch | Canada | Australia | Gap |
|---|---|---|---|
| −4 | 53.8% | 50.9% | 2.9 |
| −3 | 54.6% | 51.5% | 3.1 |
| −2 | 55.4% | 52.5% | 2.9 |
| −1 | 56.2% | 53.1% | 3.1 |
Both countries were rising, which is fine: the gap stays near 3.0 points, with no drift. A quick placebo test pretends the launch happened two weeks early. Canada's average rises from 54.2% to 55.8% and Australia's from 51.2% to 52.8%; both gain 1.6 points, so the placebo estimate is 0.0, as it should be when nothing changed.
Practical checks, in order:
- Plot both series for as long a pre-period as you have, not just two points.
- Run placebo dates, and placebo outcomes that the change should not affect.
- Ask what else differs in timing: holidays, price changes, campaigns, a payment outage.
- Try a second comparison group. Estimates that swing widely with the choice are fragile.
Passing these checks makes the assumption more plausible. It does not guarantee that the paths would have stayed parallel after launch.
When difference-in-differences fails
Diverging pre-trends. Suppose the weekly figures before launch had been Canada 52.6, 54.2, 55.8, 57.4 and Australia 50.95, 51.65, 52.35, 53.05. The averages are still 55.0 and 52.0, so the 2×2 table is identical and still says +4.0. But Canada was already gaining 0.9 points a week on Australia. The midpoints of the two windows are four weeks apart, so continuing that drift alone would add 0.9 × 4 = 3.6 points. Only about 0.4 points would be left for the checkout. The placebo test catches it: 1.8 instead of 0.
Other common failure modes:
| Failure | What happens | What to do |
|---|---|---|
| A second shock in one group | A local holiday or campaign is counted as the effect | Check a change calendar; drop or model the weeks |
| Anticipation | People delay orders until the announced launch, depressing the "before" | Start the pre-period before the announcement |
| Composition change | The launch changes who reaches checkout | Compare the mix by device, new vs returning, channel |
| Spillover | The comparison group is partly exposed (shared pages, travelers, VPNs) | Choose a cleaner comparison; expect the estimate to shrink toward zero |
| Bounded metrics near a limit | A 4-point gain means something different at 95% than at 50% | State the scale; try the relative or log-odds version |
| Seasons that differ by hemisphere | December means summer sales in one market and winter in the other | Use a comparison with the same calendar, or compare year over year |
Standard errors and staggered rollouts
Treating every checkout as independent, the standard error of the 4.0-point estimate is about 0.74 points, a 95% interval of roughly 2.6 to 5.4. Do not trust that width. There is only one treated country and one comparison country, and weekly shocks move all checkouts in a country together. Marianne Bertrand, Esther Duflo and Sendhil Mullainathan showed how bad this can get: with about 20 years of state-level data and made-up "placebo laws", conventional DiD standard errors found a significant effect at the 5% level in up to 45% of cases. Their remedies include collapsing the data into one pre and one post observation per group when there are many groups, or allowing for correlation within each group over time. With two countries, neither rescues the inference much; the pre-trend plot and placebo dates are the honest evidence.
Staggered rollouts, where countries switch on in different weeks, add a second trap. Andrew Goodman-Bacon showed that the usual two-way fixed effects regression is then a weighted average of all the possible two-group comparisons, including comparisons that use already-treated groups as controls, and it can be biased when the effect changes over time. Estimate each rollout wave against not-yet-treated groups and then average, rather than reading one pooled coefficient.
Difference-in-differences vs A/B test vs before-and-after
| Before-and-after | Difference-in-differences | A/B test | |
|---|---|---|---|
| Comparison | Same group, earlier | Change vs change in another group | Randomly assigned groups, same time |
| Removes shared trends | No | Yes, if trends would have been parallel | Yes, by design |
| Main assumption | Nothing else changed | Parallel trends | Randomization was done correctly |
| Typical use | Quick monitoring | Country, region or platform rollouts, policy changes | Changes you can split per user |
If you can randomize users, do that, and check the setup with an A/A test. DiD is for the changes that arrive as a block. In marketing, the same logic underlies geo-based incrementality tests, where some regions see a campaign and others do not. Watch for seasonality whenever the windows span a holiday.
Where TapCub fits
TapCub does not release features by country, split traffic or run a DiD regression. It supplies the weekly series the Canada and Australia tables are built from.
- Instrument both steps. Send
checkout_startandpurchaseevents in both markets with the same definitions, starting well before the launch. - Build the ratio. In All-platform analytics › Behavior › Event analysis, add a formula such as
UNIQUES(purchase) / UNIQUES(checkout_start), set granularity to week and break it down by country. A trend breakdown draws only the 10 largest groups, so on a site with many countries, also filter country to the two markets. - Cover a long pre-period. Pick a date range with at least four weeks before launch, look at the two country lines for drift, then export the result as CSV and compute the 2×2 and placebo dates in a spreadsheet.
- Mark the launch. Add a Release annotation in Configuration › Annotations, and add annotations for campaigns or incidents in either market so a second shock is not forgotten when someone reads the chart later.
Check identity before reading: event analysis can count visitors or people, and the choice should be the same in all four cells.
Sources
- David Card and Alan B. Krueger, Minimum Wages and Employment: A Case Study of the Fast-Food Industry in New Jersey and Pennsylvania, American Economic Review 84(4), 1994.
- Marianne Bertrand, Esther Duflo and Sendhil Mullainathan, How Much Should We Trust Differences-in-Differences Estimates?, NBER Working Paper 8841.
- Andrew Goodman-Bacon, Difference-in-Differences with Variation in Treatment Timing, NBER Working Paper 25018.
- Jonathan Roth, Pedro Sant'Anna, Alyssa Bilinski and John Poe, What's Trending in Difference-in-Differences?, a synthesis of recent methods.
Was this explanation clear?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Technical Engineer
Focuses on tracking code, SDKs, and API integrations, with practical guidance on implementation checks and troubleshooting.