All problems
IV 2SLS Estimate
Problem
Return the just-identified instrumental variables (2SLS) estimate cov(z, y)/cov(z, x) using sample covariances with means. Return 0.0 when input is empty or mismatched, or when cov(z, x) is zero.
Hint
The Wald ratio is the reduced form over the first stage.
Test cases
case 1
in: [[1,2,3,4],[2,4,6,8],[1,3,5,7]]
expected: 1
case 2
in: [[1,0,1,0],[2,1,3,0],[5,2,7,1]]
expected: 2.25
case 3
in: [[1,1,1],[1,2,3],[1,2,3]]
expected: 0
case 4
in: [[],[],[]]
expected: 0
case 5
in: [[1,2],[0,0],[1,2]]
expected: 0
Starter codePython
def iv_2sls_estimate(instrument, treatment, outcome):
# Your code here
pass5 test cases · run your code against them in the editor