All problems
Within Estimator
Problem
Return the fixed-effects (within) slope after demeaning x and y within each id: sum(xc*yc)/sum(xc^2). Return 0.0 when lengths differ, the input is empty, or the within-variation of x is zero.
Hint
Entity means absorb all time-invariant differences.
Test cases
case 1
in: [[1,2,3,4],[2,4,6,8],["a","a","b","b"]]
expected: 2
case 2
in: [[1,2,3],[1,3,5],["a","a","b"]]
expected: 2
case 3
in: [[1,2],[2,1],["a","a"]]
expected: -1
case 4
in: [[1,1,2],[1,3,5],["a","a","b"]]
expected: 0
case 5
in: [[],[],[]]
expected: 0
Starter codePython
def within_estimator(x, y, ids):
# Your code here
pass5 test cases · run your code against them in the editor