# Adding base level when interacting categorical variables

**URL:** https://discourse.julialang.org/t/adding-base-level-when-interacting-categorical-variables/132796
**Category:** General Usage
**Tags:** regression, linear-regression
**Created:** [September 30, 2025, 11:00pm UTC](https://discourse.julialang.org/t/adding-base-level-when-interacting-categorical-variables/132796 "2025-09-30T23:00:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)
#### Post date: [September 30, 2025, 11:00pm UTC](https://discourse.julialang.org/t/adding-base-level-when-interacting-categorical-variables/132796/1 "2025-09-30T23:00:24Z")

</div>

**High level problem:**

`reg` from `FixedEffectModels` seem to ignore `contrasts` for a categorical variable if I interact this variable with another one.

**MWE**

```julia-auto
df = DataFrame(y = rand(100), x1 = categorical(rand(1:3, 100)), x2 = categorical(rand(1:3, 100)))
# Regression of y ~ x1 using x1 = 2 as base
reg(df, @formula(y ~ x1); contrasts = Dict(:x1 => DummyCoding(base = 2)))
# Regression of y ~ x1&x2 using x1 = 2 as base 
reg(df, @formula(y ~ x1&x2); contrasts = Dict(:x1 => DummyCoding(base = 2)))

```

The first case works fine but the latter just takes the highest value of each regressor as base. It is not hard to re-convert but is there not a way of setting the base you want in the latter case?
