Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-299

Parallel Trends Gap

Problem

Return the absolute difference between the OLS slopes of the treated and control pre-period series, which measures how badly parallel trends is violated. Time is the integer index 0..n-1. Return 0.0 when either series has fewer than two points.

Hint

Compare the slopes, not the levels.

Test cases

case 1
in: [[10,12,14,16],[5,7,9,11]]
expected: 0
case 2
in: [[10,13,16],[5,6,7]]
expected: 2
case 3
in: [[1],[1,2]]
expected: 0
case 4
in: [[5,5,5],[1,3,5]]
expected: 2
case 5
in: [[2,4,6,8],[10,9,8,7]]
expected: 3
Starter codePython
def parallel_trends_gap(treated_series, control_series):
    # Your code here
    pass

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