Course contentsShow
← Data Science
Lesson 1454 of 2,14536. Causal Inference BasicsFree lesson

Calculating the DiD Estimator

Compute the double difference: (After-Before)_Treatment minus (After-Before)_Control to isolate causal effects.

Calculating the DiD Estimator

What you'll learn: How to compute the actual Difference-in-Differences estimate that isolates the causal treatment effect.

The Double Difference Formula

Now that you understand the DiD setup and parallel trends assumption, it's time to calculate the DiD estimator itself. This is where the "double difference" happens.

The formula works in two steps:

  1. First difference (Treatment group): Calculate the change in the treatment group from before to after the intervention: (Y_treatment_after - Y_treatment_before)

  2. First difference (Control group): Calculate the change in the control group over the same period: (Y_control_after - Y_control_before)

  3. Second difference (DiD): Subtract the control group's change from the treatment group's change:

DiD = (Y_treatment_after - Y_treatment_before) - (Y_control_after - Y_control_before)

Why This Works

The control group's change captures time trends and external factors affecting both groups. By subtracting it, you "difference out" those confounders, leaving only the causal effect of the treatment.

Think of it like adjusting for inflation: if your salary increased by 5,000butinflationraisedpricesby5,000 but inflation raised prices by 3,000, your real gain is only $2,000.

Example Calculation

Suppose average sales are:

  • Treatment group: Before = 100, After = 130
  • Control group: Before = 90, After = 110
DiD = (130 - 100) - (110 - 90)
DiD = 30 - 20 = 10

The treatment caused a 10-unit increase in sales, net of the 20-unit background trend.

Key Takeaway: The DiD estimator subtracts the control group's before-after change from the treatment group's before-after change, isolating the causal treatment effect by removing common time trends.