Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-203

IV Wald Estimate

Problem

Compute the instrumental variable (Wald) estimate of a treatment effect: cov(z, y) / cov(z, x), where z is the instrument, x the endogenous regressor, and y the outcome.

Return 0.0 if cov(z, x) is 0 or input is empty.

Hint

The instrument must affect the outcome only through the endogenous variable for this estimator to be valid.

Test cases

case 1
in: [[1,2,3,4],[2,4,6,8],[1,3,5,7]]
expected: 1
case 2
in: [[1,2,3,4],[0,0,0,0],[1,2,3,4]]
expected: 0
case 3
in: [[1,2,3],[2,3,4],[5,6,7]]
expected: 1
case 4
in: [[],[],[]]
expected: 0
Starter codePython
def iv_wald_estimate(z, x, y):
    # Your code here
    pass

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