Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: margins option in Stata10?

From   Richard Williams <[email protected]>
To   [email protected], [email protected]
Subject   Re: st: margins option in Stata10?
Date   Fri, 12 Aug 2011 09:32:45 -0500

At 06:01 AM 8/12/2011, Andreas Fagereng wrote:
Thanks for the help!

Hopefully I will be able to run it all on Stata11/12 soon.


There is also a do it yourself approach for AMEs. In the case of a discrete variable, do something like

webuse nhanes2f, clear
* Replicate AME for black without using margins
clonevar xblack = black
logit diabetes i.xblack i.female age, nolog
margins, dydx(xblack)
replace xblack = 0
predict adjpredwhite
replace xblack = 1
predict adjpredblack
gen meblack = adjpredblack - adjpredwhite
sum adjpredwhite adjpredblack meblack if e(sample)

After the margins and sum commands you get

. margins, dydx(xblack)

Average marginal effects                          Number of obs   =      10335
Model VCE    : OIM

Expression   : Pr(diabetes), predict()
dy/dx w.r.t. : 1.xblack

             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    1.xblack |   .0400922   .0087055     4.61   0.000     .0230297    .0571547
Note: dy/dx for factor levels is the discrete change from the base level.

. sum adjpredwhite adjpredblack meblack if e(sample)

    Variable |       Obs        Mean    Std. Dev.       Min        Max
adjpredwhite |     10335    .0443248    .0362422    .005399   .1358214
adjpredblack |     10335     .084417    .0663927   .0110063   .2436938
     meblack |     10335    .0400922    .0301892   .0056073   .1078724

I wish the margins command provided an easy way to compute those values for each case. In this instance, I like it because it shows that, while the average marginal effect for black may be .04, across individuals the ME varies from almost 0 to almost .11, i.e., it isn't like every black is 4% more likely to get diabetes than a comparable white. As I show in the presentation I cited earlier, it can be very useful to compute MERs (marginal effects at representative values), e.g. in this case it is useful to show how the marginal effects differ across age levels.

It is also possible to compute AMEs for continuous variables. Cameron & Trivedi show how in

(or at least they did show how in the original version of the book).

Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  [email protected]

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index