Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-283

Synthetic Control Weights

Problem

Compute synthetic control weights for two donors. Minimize ||w*A + (1-w)*B - T||^2, giving w = sum((A - B)(T - B)) / sum((A - B)^2), clipped to [0, 1].

Return [w, 1 - w]; if the donors are identical return [0.5, 0.5].

Hint

Weights are constrained to the simplex so the synthetic control stays a convex combination.

Test cases

case 1
in: [[10,12,14],[8,10,12],[9,11,13]]
expected: [0.5,0.5]
case 2
in: [[1,2,3],[5,6,7],[4,5,6]]
expected: [0.25,0.75]
case 3
in: [[10,10],[0,0],[20,20]]
expected: [1,0]
case 4
in: [[5,5],[5,5],[7,7]]
expected: [0.5,0.5]
Starter codePython
def synthetic_control_weights(donor_a, donor_b, treated):
    # Returns [w, 1 - w]
    # Your code here
    pass

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