Multiple fixed effects using FixedEffects.jl

It looks like your design matrix is wrong for the by-hand approach. It’s non-singular since you included all the indicator variables. The standard for the OLS dummy variable approach to fixed effects is to drop one level of the fixed effect. With the right D matrix, the answers are the same:

# ...same until here...
D = let dv_1 = p1.refs .== unique(p1.refs)[2:end]',
           dv_2 = p2.refs .== unique(p2.refs)[2:end]'
      [ones(Bool, 10) dv_1 dv_2]
    end

 @time x1 = let β = D \ x0
           x0 - D * β
       end

@time solve_residuals!(x, [p1, p2])

x ≈ x1
1 Like