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

Re: st: logit average "marginal" effect of dummy variable with predict

 From Chris To statalist@hsphsun2.harvard.edu Subject Re: st: logit average "marginal" effect of dummy variable with predict Date Tue, 7 May 2013 14:58:57 +0200

```Hi Richard,

thanks, everything works out. Didn't know that a dummy has to be
defined as such.

On Tue, May 7, 2013 at 2:32 PM, Richard Williams
<richardwilliams.ndu@gmail.com> wrote:
> You are treating smoke as a continuous variable rather than as discrete.
>
> logit low lwt ptd i.smoke age
>
> margins, dydx(smoke) //AME of smoke
>
> The latter produces
>
> Average marginal effects                          Number of obs   =
> 112
> Model VCE    : OIM
>
> Expression   : Pr(low), predict()
> dy/dx w.r.t. : 1.smoke
>
> ------------------------------------------------------------------------------
>              |            Delta-method
>              |      dy/dx   Std. Err.      z    P>|z|     [95% Conf.
> Interval]
> -------------+----------------------------------------------------------------
>      1.smoke |    .229702   .0923031     2.49   0.013     .0487913
> .4106127
> ------------------------------------------------------------------------------
> Note: dy/dx for factor levels is the discrete change from the base level.
>
>
> Incidentally, I like this alternate syntax, mostly because of the way output
> gets labeled, especially in graphs:
>
> margins r.smoke
>
>
> At 07:48 AM 5/7/2013, Chris wrote:
>>
>> Dear statalist,
>>
>> I want to compute the average marginal effect of an interaction
>> effect, so I have to simultaneously "switch on and off" two treatment
>> dummies (one treatment dummy, and one subgroup dummy interacted with
>> the treatment dummy). Margins can't do that, as Richard Williams
>> recently pointed out here on statalist.
>> (http://www.stata.com/statalist/archive/2013-01/msg00263.html)
>>
>> So I am trying to compute it manually. However, I don't even manage to
>> compute the average marginal effect with the predict command; somehow,
>> there is a discrepancy between margins and predict even for simple
>> cases. Does anybody know why? Example:
>>
>> -------------------------------
>> webuse lowbirth, clear
>> logit low lwt ptd smoke age
>> margins, dydx(smoke) //AME of smoke
>>
>> replace smoke=1 //set entire sample smoke=1
>> predict withsmoke //predict probability
>> replace smoke=0 //set entire sample smoke=0
>> predict withoutsmoke //predict probability
>> gen me=withsmoke-withoutsmoke //compute discrete "marginal" effect
>> egen ame=mean(me) //AME of smoke
>> -------------------------------
>>
>> The margins command gives an AME of .2198375, while the predict
>> version gives .2297. Which is right and why do they differ?
>>
>> Thanks!
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
> -------------------------------------------
> 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/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```