# Replicating predictive margins for a categorical variable

**URL:** <https://discourse.julialang.org/t/replicating-predictive-margins-for-a-categorical-variable/136741>\
**Category:** General Usage\
**Created:** [April 16, 2026, 2:59pm UTC](https://discourse.julialang.org/t/replicating-predictive-margins-for-a-categorical-variable/136741 "2026-04-16T14:59:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@Rodrigo](https://discourse.julialang.org/u/Rodrigo)\
**Post date:** [April 16, 2026, 2:59pm UTC](https://discourse.julialang.org/t/replicating-predictive-margins-for-a-categorical-variable/136741/1 "2026-04-16T14:59:10Z")

</div>

I am new with Julia, my background is Stata. I am looking a way for get marginal mean for a categorical variable (Stata: margins i.group).

I am using categorical variable for variable group, then my goal its get probabilities for each level of variable group, but lamentably I get for all model.

example:

```julia-auto
using Margins, DataFrames, GLM, CategoricalArrays, Random   

n = 10000
Random.seed!(06515)
y = rand([0,1], n)

data = DataFrame(y=y, x1 = randn(n), 
       x2 = randn(n), 
       bino =rand([1,2], n), 
       group = rand(["A", "B", "C"], n))

model = glm(@formula(y ~ x1+ x2+ bino+ group), data, Binomial(), LogitLink())

population_margins(model, data; type=:predictions)

PredictionsResult: 1 population predictions (N=10000)
────────────────────────────────────────────────────
  Prediction Std. Err. [95% Conf. Interval]
────────────────────────────────────────────────────
      0.4952 0.005 0.4854 0.505
────────────────────────────────────────────────────

My goal its get this Stata result but using Julia:
------------------------------------------------------------------------------
             | Delta-method
             | Margin std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
      group |
          A | .4845861 .0086549 55.99 0.000 .4676229 .5015493
          B | .5056282 .0087316 57.91 0.000 .4885145 .5227418
          C | .4955554 .0085923 57.67 0.000 .4787148 .5123959
------------------------------------------------------------------------------

. 

```
