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

# Re: st: margins / over / dydx

 From Richard Williams To statalist@hsphsun2.harvard.edu Subject Re: st: margins / over / dydx Date Wed, 04 Jan 2012 13:09:10 -0500

```At 04:19 AM 1/4/2012, Robert Duval wrote:
```
```I can of course estimate

margins , over(sex) post

and then proceed "by hand" given that I have the parameter estimates
to differentiate and the variance-covariance matrix. However, I want
to do this for several models and for many different values in the
at() option. So before I program a complicated loop for my specific
problem in hand I wanted to ask if anyone knows a direct way of
obtaining the  difference 0.2587496 - .0807707  = .1779789 and its
standard error.
```
```
```
Is the post option all that horrible? You could save and restore the probit results if you want to do a bunch of different things with the same model.
```
```
Does this do what you want? It at least saves you doing the calculation by hand. You will need Stata 12 for this.
```
use http://www.stata-press.com/data/r11/margex
probit outcome sex##group age distance arm
margins, over(sex) post
contrast r.sex

The last command yields

. contrast r.sex

Contrasts of predictive margins
Model VCE    : OIM

Expression   : Pr(outcome), predict()
over         : sex

------------------------------------------------
|         df        chi2     P>chi2
-------------+----------------------------------
sex |          1      218.99     0.0000
------------------------------------------------

--------------------------------------------------------------
|            Delta-method
|   Contrast   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
sex |
(1 vs 0)  |   .1779789    .012027      .1544063    .2015515
--------------------------------------------------------------

Also, note that contrast saves its results in r, e.g. after doing the above,

. mat list r(chi2)

symmetric r(chi2)[1,1]
c1
r1  218.98749

. mat list r(b)

symmetric r(b)[1,1]
r1vs0.
sex
r1  .17797889

. mat list r(V)

symmetric r(V)[1,1]
r1vs0.
sex
r1vs0.sex  .00014465

. di .00014465^.5
.01202705

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  Richard.A.Williams.5@ND.Edu
WWW:    http://www.nd.edu/~rwilliam

*
*   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/
```