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.
- Treated service
- Control service
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
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
What to compare
Compare Treated change (ms) with Control change (ms). Which change is subtracted to get Difference in changes (ms)?
Your result
Result tools
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.
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?
Hints for this question
- Identify the change that affects everyone.
- Find observations that include that change without the treatment.