Design a fair testLesson 06 of 30 · 6 min

Compared with what?

Explain why a before-and-after difference may fail to isolate a treatment.

A control condition supplies a comparison without the change you want to investigate. Before-and-after observations can be useful, but other things may change with time. An apparent improvement after a release could reflect lower demand rather than the release itself.

In this invented example, both the changed service and an unchanged comparison service get faster after lunch. Subtracting their changes is a difference-in-differences calculation: how much more did the treated service change than the control?

That calculation has assumptions. In particular, the control must represent the treated service's time trend without the treatment. Different demand shifts could violate this parallel-trends assumption. Earlier observations can challenge its plausibility, but cannot prove what the unobserved alternative would have been.

Subtract the shared change
00.250.50.7516080100120140Time (ms)0 before, 1 after
00.250.50.7516080100120140Time (ms)0 before, 1 after
(−30)−(−20)=−10  ms(-30)-(-20)=-10\;\mathrm{ms}
  • Treated service
  • Control service
Invented before/after values. Treated: 120 → 90 ms (−30). Control: 100 → 80 ms (−20). The adjusted difference is −10 ms, conditional on the control representing the untreated trend.

If both services improve equally, how large is the adjusted treatment difference?

Write a prediction (optional)

Run the prepared example

This page puts the example in the Python editor. Select Run Python with the code unchanged.

Invented data

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

What to compare

Compare Treated change (ms) with Control change (ms). Which change is subtracted to get Difference in changes (ms)?

Published example output

The site ran the original code to produce this reference. Build environment ↗

Treated change (ms): -30
Control change (ms): -20
Difference in changes (ms): -10

The treated service improves by 30 ms. The control improves by 20 ms. If the control represents the untreated trend, the treatment accounts for the extra 10 ms.

Change and run again

In the Python editor, replace treated_before, treated_after = 120, 90 with treated_before, treated_after = 120, 100. Select Run Python again. Compare the treated and control changes. Does Difference in changes (ms) still show an extra improvement? Return to the Python editor

What this example supports. This observational adjustment does not guarantee a causal estimate. Its validity depends on the control and trend assumptions.

Try a fresh case

A training programme starts just as an easier exam replaces the old exam. What comparison would help?

Choose an answer

Hints for this question
  1. Identify the change that affects everyone.
  2. Find observations that include that change without the treatment.
Your notes