Bookmark and Share

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


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

st: margins option in Stata10?


From   Andreas Fagereng <[email protected]>
To   [email protected]
Subject   st: margins option in Stata10?
Date   Fri, 12 Aug 2011 13:01:21 +0200

Thanks for the help!

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


Andreas





****
First off, you are wise to be careful. I show how old commands like
mfx can give incorrect results in my Stata Conference talk

http://www.stata.com/meeting/chicago11/materials/chi11_williams.pptx

But, if you are careful, it can be done. First, here is sample code:

webuse nhanes2f
tab1 agegrp, gen(agegrp)
* Easy way if you have Stata 11+
probit diabetes i.agegrp weight
margins , atmeans dydx(agegrp)
* Hard way if you only have Stata 10
probit diabetes agegrp2-agegrp6 weight
mfx , at(agegrp2 = 0, agegrp3 = 0, agegrp4 = 0, agegrp5 = 0, agegrp6 = 0)

Since you don't have Stata 11, I'll also show the output:

. clear all

. webuse nhanes2f

. tab1 agegrp, gen(agegrp)

-> tabulation of agegrp

Age groups |
       1-6 |      Freq.     Percent        Cum.
------------+-----------------------------------
  age20-29 |      2,320       22.44       22.44
  age30-39 |      1,621       15.68       38.13
  age40-49 |      1,270       12.29       50.41
  age50-59 |      1,289       12.47       62.88
  age60-69 |      2,852       27.59       90.47
   age 70+ |        985        9.53      100.00
------------+-----------------------------------
     Total |     10,337      100.00

. * Easy way if you have Stata 11+

. probit diabetes i.agegrp weight

Iteration 0:   log likelihood = -1999.0668
Iteration 1:   log likelihood = -1822.6588
Iteration 2:   log likelihood = -1807.9974
Iteration 3:   log likelihood = -1807.7631
Iteration 4:   log likelihood = -1807.7625
Iteration 5:   log likelihood = -1807.7625

Probit regression                                 Number of obs   =      10335
                                                 LR chi2(6)      =     382.61
                                                 Prob > chi2     =     0.0000
Log likelihood = -1807.7625                       Pseudo R2       =     0.0957

------------------------------------------------------------------------------
   diabetes |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     agegrp |
         2  |   .2206309    .125082     1.76   0.078    -.0245252    .4657871
         3  |   .5985311    .114849     5.21   0.000     .3734311    .8236311
         4  |   .8427783   .1085646     7.76   0.000     .6299957    1.055561
         5  |   1.081819   .0980249    11.04   0.000     .8896939    1.273945
         6  |   1.274717   .1061677    12.01   0.000     1.066632    1.482802
            |
     weight |   .0095574   .0014072     6.79   0.000     .0067994    .0123154
      _cons |  -3.166968   .1385273   -22.86   0.000    -3.438476   -2.895459
------------------------------------------------------------------------------

. margins , atmeans dydx(agegrp)

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

Expression   : Pr(diabetes), predict()
dy/dx w.r.t. : 2.agegrp 3.agegrp 4.agegrp 5.agegrp 6.agegrp
at           : 1.agegrp        =    .2244799 (mean)
              2.agegrp        =    .1567489 (mean)
              3.agegrp        =    .1227866 (mean)
              4.agegrp        =    .1247218 (mean)
              5.agegrp        =    .2759555 (mean)
              6.agegrp        =    .0953072 (mean)
              weight          =    71.90313 (mean)

------------------------------------------------------------------------------
            |            Delta-method
            |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     agegrp |
         2  |   .0053641   .0031363     1.71   0.087    -.0007828    .0115111
         3  |   .0233968   .0049879     4.69   0.000     .0136206    .0331729
         4  |   .0442435   .0062888     7.04   0.000     .0319176    .0565693
         5  |   .0744917   .0053948    13.81   0.000      .063918    .0850653
         6  |   .1075195   .0103715    10.37   0.000     .0871918    .1278472
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.

. * Hard way if you only have Stata 10

. probit diabetes agegrp2-agegrp6 weight

[Output deleted]

. mfx , at(agegrp2 = 0, agegrp3 = 0, agegrp4 = 0, agegrp5 = 0, agegrp6 = 0)

warning: no value assigned in at() for variables weight;
  means used for weight

Marginal effects after probit
     y  = Pr(diabetes) (predict)
        =  .00657351
------------------------------------------------------------------------------
variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
---------+--------------------------------------------------------------------
agegrp2*|   .0053641      .00314    1.71   0.087  -.000783  .011511         0
agegrp3*|   .0233968      .00499    4.69   0.000   .013621  .033173         0
agegrp4*|   .0442435      .00629    7.04   0.000   .031918  .056569         0
agegrp5*|   .0744917      .00539   13.81   0.000   .063918  .085065         0
agegrp6*|   .1075195      .01037   10.37   0.000   .087192  .127847         0
 weight |   .0001762      .00005    3.73   0.000   .000084  .000269   71.9031
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1

This kind of stuff is very error prone; life will be much simpler if
you can get Stata 11 or 12. Plus, you could then use AMES instead of
MEMs or some of the other options that margins offers.


-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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