Levels on interaction terms
Opened this issue · 0 comments
anniejw6 commented
via Murtaza
In Stata:
regress y i.sex#i.group or regress y i.sex i.group
. margins sex#group
Adjusted predictions Number of obs = 3,000
Model VCE : OLS
Expression : Linear prediction, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
sex#group |
male#1 | 50.6107 1.367932 37.00 0.000 47.92852 53.29288
male#2 | 61.98514 .7772248 79.75 0.000 60.46119 63.50908
male#3 | 72.2295 .8074975 89.45 0.000 70.64619 73.8128
female#1 | 72.23577 .63942 112.97 0.000 70.98203 73.48952
female#2 | 78.75863 .9434406 83.48 0.000 76.90877 80.60849
female#3 | 87.7697 2.468947 35.55 0.000 82.92869 92.6107
------------------------------------------------------------------------------
Current best workaround
with(margex,table(sex,group))
margex$sexgrp <-with(margex,interaction(group,sex))
margex$sexgrp <- factor(as.numeric(margex$sexgrp) - 1,
labels=c("fem.grp1", "fem.grp2","fem.grp3",
"mal.grp1","mal.grp2","mal.grp3" ))
with(margex,table(sexgrp))
g <- glm(y ~ as.factor(sexgrp) , data = margex)
summary(g)
> modmarg::marg(mod = g, var_interest = "sexgrp", type = 'levels')
[[1]]
Label Margin Standard.Error Test.Stat P.Value Lower CI (95%) Upper CI (95%)
1 sexgrp = fem.grp1 72.23577 0.6394200 112.97077 0.000000e+00 70.98203 73.48952
2 sexgrp = fem.grp2 78.75863 0.9434406 83.48022 0.000000e+00 76.90877 80.60849
3 sexgrp = fem.grp3 87.76970 2.4689473 35.54944 3.100836e-231 82.92869 92.61070
4 sexgrp = mal.grp1 50.61070 1.3679321 36.99796 4.247584e-247 47.92852 53.29288
5 sexgrp = mal.grp2 61.98514 0.7772248 79.75187 0.000000e+00 60.46119 63.50908
6 sexgrp = mal.grp3 72.22950 0.8074975 89.44857 0.000000e+00 70.64619 73.81280