# How to fix an error related to the Effects package

**URL:** <https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [November 11, 2021, 10:02am UTC](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320 "2021-11-11T10:02:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jad](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@Jad](https://discourse.julialang.org/u/Jad)\
**Post date:** [November 11, 2021, 10:02am UTC](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320/1 "2021-11-11T10:02:56Z")

</div>

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.

```plaintext
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:  
 ![Screenshot 2021-11-10 at 17.10.59](https://global.discourse-cdn.com/julialang/original/3X/4/b/4be8c887f5b43eac6d278c20b723f2e17fe43259.png)

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](https://beacon-biosignals.github.io/Effects.jl/stable/#Interaction-Terms-in-Effects)):

```julia
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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 11, 2021, 4:56pm UTC](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320/2 "2021-11-11T16:56:25Z")

</div>

Can you drop the `missing` from that vector and see if that works?

---

<div class="post-metadata">

**Author:** ![Jad](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@Jad](https://discourse.julialang.org/u/Jad)\
**Post date:** [November 12, 2021, 10:24am UTC](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320/3 "2021-11-12T10:24:11Z")

</div>

> [@Jad](#):
>
> `effects(design, m1)`

Thanks for the suggestion, it worked great.
