Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-201

Difference-in-Differences

Problem

Compute the difference-in-differences estimate: (treat_post - treat_pre) - (control_post - control_pre).

Hint

DiD subtracts the control group's change from the treatment group's change.

Test cases

case 1
in: [10,15,12,14]
expected: 3
case 2
in: [20,30,18,22]
expected: 6
case 3
in: [5,4,9,10]
expected: -2
Starter codePython
def difference_in_differences(treat_pre, treat_post, control_pre, control_post):
    # Your code here
    pass

3 test cases · run your code against them in the editor