Hi
I’m using FixedEffects.jl
to residualize matrices with fixed effects. I might be missing something with the syntax, but I couldn’t get the same results using a simple regression approach. Below is the code from the readme file
using FixedEffects
# define fixed effects:
p1 = FixedEffect(repeat(1:5, inner = 2))
# combine fixed effects
p2 = FixedEffect(repeat(1:2, outer = 5), repeat(1:2, inner = 5))
x = rand(10)
x0 = copy(x)
# Regression approach
# fixed effect matrix
D = [p1.refs .== unique(p1.refs)' p2.refs .== unique(p2.refs)']
@time x1 = x0 - D*inv(D'*D)*D'*x0
#HDFE approach
@time solve_residuals!(x, [p1, p2])
# compare two methods
[x1 x]