I'm trying to calculate the marginal mean for each level of a categorical variable while controlling for confounding factors. I was under the impression that I could do this using the margins, over(group) command; however, introducing control variables has no effect on the marginal means.
This problem can be illustrated using a dataset released by UCLA:
If you run these commands, you will notice that the point estimates for the marginal means do not change upon introducing control variables (although the standard errors do change). Why is this the case? By contrast, the command margins group does return different estimates when control variables are introduced. For example, the commands below return different point estimates:
Should I be using the margins group command instead of margins, over(group)? If so, why?
This problem can be illustrated using a dataset released by UCLA:
Code:
use https://stats.idre.ucla.edu/stat/data/hsbdemo, clear qui: reg female i.ses margins, over(ses) qui: reg female i.ses read write margins, over(ses) qui: reg female i.ses read write i.prog margins, over(ses)
If you run these commands, you will notice that the point estimates for the marginal means do not change upon introducing control variables (although the standard errors do change). Why is this the case? By contrast, the command margins group does return different estimates when control variables are introduced. For example, the commands below return different point estimates:
Code:
use https://stats.idre.ucla.edu/stat/data/hsbdemo, clear qui: reg female i.ses margins ses qui: reg female i.ses read write margins ses qui: reg female i.ses read write i.prog margins ses

Comment