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

# Re: st: margins / over / dydx

 From jpitblado@stata.com (Jeff Pitblado, StataCorp LP) To statalist@hsphsun2.harvard.edu Subject Re: st: margins / over / dydx Date Wed, 04 Jan 2012 12:59:06 -0600

```Robert Duval <rduval@gmail.com> wants to compute a comparison of the results
from -margins- with the -over()- option:

> I have a question on the use of the command margins together with the
> option over().
>
> Suppose I want to get the prediction for a given outcome by sex in a
> probit model (other models would be ok)
>
> use http://www.stata-press.com/data/r11/margex
>
> probit outcome sex##group age distance arm
>
> margins , over(sex)
>
> That is I want the average predicted probability of having a positive
> outcome for males and again for females rather than the average
> predicted probability with everyone treated as male and then again
> with everyone treated as female.
>
> In this particular example Stata gives me
>
> margins , over(sex)
>
> Predictive margins                                Number of obs   =       3000
> Model VCE    : OIM
>
> Expression   : Pr(outcome), predict()
> over         : sex
>
> ------------------------------------------------------------------------------
>              |            Delta-method
>              |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
> -------------+----------------------------------------------------------------
>          sex |
>           0  |   .0807707   .0061496    13.13   0.000     .0687178    .0928236
>           1  |   .2587496   .0103578    24.98   0.000     .2384487    .2790504
> ------------------------------------------------------------------------------
>
> Now I want the estimated difference 0.2587496 - .0807707  = .1779789
> and its standard error.
>
> Is there an easy way to do this without using the post option?

In Stata 12, -margins- has new options for computing contrasts of margins.
These new features are documented in -[R] margins, contrast-.

For Robert's example above, simply add a contrast operator in the -over()-
option:

. margins , over(r.sex) contrast

--Jeff