# Indicator matrix for categorical data in GLM.jl with DataFrames.jl

**URL:** <https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448>\
**Category:** General Usage\
**Created:** [April 30, 2017, 9:08pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448 "2017-04-30T21:08:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [April 30, 2017, 9:08pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448/1 "2017-04-30T21:08:34Z")

</div>

I am working with a large data set and want to run a logit regression on monthly data. For this I create a DataFrame and use the GLM package in Julia. My code looke something like that:

```
f=glm((Y ~ Age + Duration + Gender + Nationality + MonthIn), Data2000, Binomial(), LogitLink())

```

My question is, as I have monthly data I want to create dummy variables for the 12 months, or eleven when I want to use a constant. The MonthIn is just a column which have numbers for the month (eg 3 for march).

Now when I tried to find how this is done I just learned that in R this possibility is build in s.t. it can automatically create monthly dummies. Now one guess of mine would be to use the pooling data function build in the dataframe.jl to create an indicator matrix, but I am not sure how this or something similar would be done.

I highly appreciate any help and please feel free to ask if my question is not clear.

Cheers

**Link:** [julia - Indicator matrix for categorical data in GLM.jl with DataFrames.jl - Stack Overflow](http://stackoverflow.com/questions/43708635/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl)

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [April 30, 2017, 9:12pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448/2 "2017-04-30T21:12:15Z")

</div>

This topic is a test of a new service discussed [here](https://discourse.julialang.org/t/link-to-julia-questions-on-stackoverflow/3357/15). Please, do not reply to it, but instead, use the link to StackOverflow posted at the end.

---

<div class="post-metadata">

**Author:** ![sarah-ji](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sarah-ji](https://discourse.julialang.org/u/sarah-ji)\
**Post date:** [August 9, 2018, 11:53pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448/3 "2018-08-09T23:53:35Z")

</div>

Did you ever get an answer to this? I am also having some trouble using categorical variables

---

<div class="post-metadata">

**Author:** ![Taylor\_Maxwell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taylor_maxwell/32/8320_2.png) [@Taylor\_Maxwell](https://discourse.julialang.org/u/Taylor_Maxwell)\
**Post date:** [August 9, 2018, 11:58pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448/4 "2018-08-09T23:58:39Z")

</div>

It looks like the poster found their own solution and wrote it as an answer in the stackoverflow link in the original post.

---

<div class="post-metadata">

**Author:** ![KyleSJohnston](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylesjohnston/32/12674_2.png) [@KyleSJohnston](https://discourse.julialang.org/u/KyleSJohnston)\
**Post date:** [October 5, 2019, 1:43pm UTC](https://discourse.julialang.org/t/indicator-matrix-for-categorical-data-in-glm-jl-with-dataframes-jl/3448/5 "2019-10-05T13:43:13Z")

</div>

Is `pool!(df, [:categoricalcolumn])` still the correct solution to this? I found the same post on stackoverflow, and I’m getting `UndefVarError: pool! not defined` (Julia 1.1.1, DataFrames 0.19.4).

Because I’m fairly new to the language, I wasn’t able to trace the logic in GLM to figure out how—or if—a formula with a categorical predictor is expanded to an indicator matrix. My goal is to use the difference of two indicator matrices as a predictor. I wrote a function to do it, but I’d rather use an existing alternative if it’s available.
