FunctionRacerProblemsRace

Effect of the Program

HardstatsmodelsPython

A training program was given to some shops and not to others. df has one row per shop per period: treated is 1 for shops that got the program, after is 1 for the period after it started, and sales is the outcome.

Return the difference-in-differences estimate of the program's effect: the change in the treated shops from before to after, minus the change in the others over the same time. Get it as the coefficient of the interaction in a regression of sales on treated, after and their interaction.

Example 1

df {"treated":[0,0,0,0,1,1,1,1,0,0,1,1],"after":[0,0,1,1,0,0,1,1,0,1,0,1],"sales":[10,10,12,12,20,20,27,27,10,12,20,27]}
returns 5.0

The other shops went from 10 to 12, a change of 2. The treated shops went from 20 to 27, a change of 7. The program accounts for 7 - 2 = 5.

Example 2

df {"treated":[0,1,0,1,0,1,0,1,0,1,0,1],"after":[0,0,1,1,0,0,1,1,0,0,1,1],"sales":[5,9,8,12,5,9,8,12,5,9,8,12]}
returns 0.0

Both groups rose by 3, so the program changed nothing.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More statsmodels problems