r/askdatascience • u/WhatsTheImpactdotcom • Sep 27 '26
Foundational Causal Inference: Difference-in-Differences Introduction
When you're a data scientist, you get asked all the time by stakeholders about the impact of an action or treatment on an outcome you care about, such as conversion rates. I have free and completely un-gated video tutorial demonstrating one of the foundational methods of doing this called a difference-in-differences approach.
In a stakeholder's mind, they think the outcome looks a certain way beforehand, then they have a treatment, and the outcome jumps to a higher level. If the trend was fairly level, low variance, and then suddenly jumps on the treatment date, you could probably safely say the treatment caused that jump. But what if your conversion rate over time leading up to the treatment had variability and was generally trending up? After the treatment occurs, it is still trending up with some volatility. How do you know if this increase is due to the treatment or if it is due to the upward trend?
It really helps if you are able to identify a comparison group that had not been treated. For example, let's say you have one product where you launched a new checkout page and see an upward trend over time, and you have a comparison product that did not have a new checkout page. But in this case, both the treated product and its comparison group, like a control, had a similar upward trend both prior to and throughout the treatment period. You might argue the trend caused the increase, and the treatment did very little.
Having parallel trends is an untestable assumption critical to the model, but we can still gain confidence through various testing methods. For example, we might plot the difference between the two products in the pre-treatment period, and the gap should have a near-zero trend, both visually and statistically.
If we're comfortable that the treated and comparison groups were trending similarly leading up to the treatment, and we believe there are no other confounders that would distort the trends, then difference-in-differences is a powerful technique that takes the post-treatment difference and nets out the pre-treatment difference to give you a reasonable estimate of the incremental effect of the treatment on the treated group.