FixedEffectModels.jl
FixedEffectModels.jl copied to clipboard
`predict` doesn't work for FE-only models
This is sort of self-assigned:
julia> using FixedEffectModels, DataFrames
julia> df = DataFrame(y=rand(10), id = rand(1:2, 10), t = rand(1:2, 10));
julia> predict(reg(df, @formula(y ~ fe(id) + fe(t)), save = :fe), df)
ERROR: ArgumentError: collection must be non-empty
Stacktrace:
[1] first(itr::@NamedTuple{})
@ Base .\abstractarray.jl:470
[2] missing_omit(d::@NamedTuple{})
@ StatsModels C:\Users\ngudat\.julia\packages\StatsModels\syVEq\src\modelframe.jl:57
[3] missing_omit(data::@NamedTuple{y::Vector{Float64}, id::Vector{Int64}, t::Vector{Int64}}, formula::MatrixTerm{Tuple{InterceptTerm{false}}})
@ StatsModels C:\Users\ngudat\.julia\packages\StatsModels\syVEq\src\modelframe.jl:70
[4] predict(m::FixedEffectModel, data::DataFrame)
@ FixedEffectModels C:\Users\ngudat\.julia\packages\FixedEffectModels\9B0we\src\FixedEffectModel.jl:142
[5] top-level scope
@ REPL[34]:1
julia> predict(reg(df, @formula(y ~ id + fe(t)), save = :fe), df)
10-element Vector{Float64}:
(...)
a workaround is to add a column of ones:
df.x .= 1
reg(@formula(y ~ -1 + x + fe(id) + fe(t))
but that's clearly not ideal.