Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Use of margins command to get individual level predictions but where one factor is treated as balanced

From   Sam Brilleman <>
Subject   st: Use of margins command to get individual level predictions but where one factor is treated as balanced
Date   Thu, 04 Aug 2011 14:00:44 +0100

Hi STATAlisters,

I am hoping someone can help me with getting the correct -margins- syntax. I have found several people with similar questions, but no clear answers.

I have a GLM (log link) model fit using the following command:

glm totalcost_modelfit i.practiceid i.age_gender i.imd_decile i.QOF_MMscore_trunc6, link(log) family(gamma) eform

There are 174 levels for the i.practiceid factor variable. I wish to calculate the marginal mean for the outcome variable (totalcost_modelfit) within each practice, whilst treating the practice effect as balanced (i.e. using the average practice effect for the full sample). I've tried:

margins, over(practiceid) at((asbalanced) practiceid)

but this obviously treats practiceid as balanced within each practice rather than across the whole sample, so I may aswell have just used -predict- and calculated the mean predictions by practice manually. And if I try:

margins practiceid, at((asbalanced) practiceid)

then individuals from the full sample are contributing to the estimated marginal mean for each practice aren't that? I don't really want that since the age-gender distribution may differ across practices.

Ideally I would want to -predict- individual level prediction but where I am allowed to treat the practice effect as balanced (i.e. use the average practice fixed effect) and then I would just calculate the mean prediction within each practice manually (NB this would give me more flexibility as I would have the individual level predictions available too). Possibly using the -adjust- command? However it says that margins has superseded this.

Thanks for any help,

Sam Brilleman
School of Social and Community Medicine
University of Bristol
Canynge Hall
39 Whatley Road
Bristol BS8 2PS

Tel: (0117) 928 7319
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index