I want to run the average marginal effects between two predictors: education and unemployment rate. While the package Effects
in Julia can do the trick, i am having an error which i will describe below. First, i show the code that works perfectly fine and the results i get from running the MixedModels
package. Second, i show the part of the code that is not working.
dffnm = "df4_full"
df = DataFrame(Arrow.Table(dffnm))
df1 = DataFrame(
unemploy = disallowmissing(df.macro_unemployment),
workhours_imputed = df.workhours_imputed,
education = PooledArray(df.education),
id = PooledArray(string.(disallowmissing(df.id))),
age = Int8.(disallowmissing(df.age)) .- Int8(42), # center the age at 42
sex = PooledArray(df.sex),)
form1 = @formula workhours_imputed ~ 1 + sex + age + education + education * unemploy + sex * unemploy + (1|id)
contr = Dict(nm => Grouping() for nm in (:country, :country_year, :id))
contr = Dict(:country => Grouping(),
:country_year => Grouping(),
:id => Grouping(),
:sex => DummyCoding(base="Female"),
:education => DummyCoding(base="Tertiary"))
m1 = @time fit(MixedModel, form1, df1, contrasts=contr)
Here is the output:
Everything works perfectly so far. The aim is to run the average marginal effects for education and unemployment on working hours. However, i thought that i would start with a simpler example which is just taking the average marginal effects of education (i follow their example here: Home · Effects.jl):
design = Dict(:education => unique(df1))
Dict{Symbol, Vector{Union{Missing, String}}} with 1 entry:
:education => ["Tertiary", "Upper-secondary", "Below upper-secondary", missin…
Then the last line of code:
effects(design, m1)
KeyError: key missing not found
Stacktrace:
[1] getindex(h::Dict{String, Int64}, key::Missing)
@ Base ./dict.jl:482
[2] _broadcast_getindex_evalf
@ ./broadcast.jl:648 [inlined]
Could someone help me to fix this? I am also unsure how to run the average marginal effects for the interaction between education and unemployment rate.