# Re: st: Marginal effect of interaction var in multinomial logit model

 From Maarten buis <[email protected]> To [email protected] Subject Re: st: Marginal effect of interaction var in multinomial logit model Date Sat, 15 Sep 2007 13:30:17 +0100 (BST)

```What you showed are the marginal effect of foreign, mpg, and forXmpg on
the probability of falling in the reference category of rep78. More
sensible to me would be the effect of mpg for foreign cars and the
effect of mpg for domestic cars. Moreover, you also have marginal
effects on the probabilities of falling in category 2 and category 3.

In the example below Dp1DmpgF is the marginal effect of mpg on the
probability of falling in category 1 of rep78 for foreign cars,
Dp1DmpgD is the marginal effect of mpg on the probability of falling in
category 1 of rep78 for domestic cars, Dp2DmpgF is the marginal effect
of mpg on the probability of falling in category 2 of rep78 for foreign
cars, etc.

Hope this helps,
Maarten

*-------------- begin example -----------------
set more off
#delimit ;
sysuse auto, clear;
recode rep78 2=1 3=1 4=2 5=3 .=3 ;
* WARNING: recode .=3 is something you would not do in a
* normal analysis but in this case it stabalizes the model,
* and I don't care about the results, I just use it to
* show the mechanics of creating marginal effects. You
* should never ever do this in an analysis that you

gen forXmpg = foreign * mpg ;

mlogit rep78 foreign mpg forXmpg ;

sum mpg if e(sample) ;
scalar mmpg = r(mean) ;

local exp2f "exp([2]_cons + [2]foreign*1
+ [2]mpg*scalar(mmpg) + [2]forXmpg*1*scalar(mmpg))" ;
local exp2d "exp([2]_cons + [2]foreign*0
+ [2]mpg*scalar(mmpg) + [2]forXmpg*0*scalar(mmpg))" ;

local exp3f "exp([3]_cons + [3]foreign*1
+ [3]mpg*scalar(mmpg) + [3]forXmpg*1*scalar(mmpg))" ;
local exp3d "exp([3]_cons + [3]foreign*0
+ [3]mpg*scalar(mmpg) + [3]forXmpg*0*scalar(mmpg))" ;

local p1f "1/(1 + `exp2f' + `exp3f')" ;
local p1d "1/(1 + `exp2d' + `exp3d')" ;

local p2f "`exp2f'/(1 + `exp2f' + `exp3f')" ;
local p2d "`exp2d'/(1 + `exp2d' + `exp3d')" ;

local p3f "`exp3f'/(1 + `exp2f' + `exp3f')" ;
local p3d "`exp3d'/(1 + `exp2d' + `exp3d')" ;

nlcom (Dp1DmpgF: `p1f'*(0-(`p2f'*[2]mpg + `p3f'*[3]mpg)))
(Dp1DmpgD: `p1d'*(0-(`p2d'*[2]mpg + `p3d'*[3]mpg)))
(Dp2DmpgF: `p2f'*([2]mpg+[2]forXmpg-(`p2f'*[2]mpg +
`p3f'*[3]mpg)))
(Dp2DmpgD: `p2d'*([2]mpg-(`p2d'*[2]mpg + `p3d'*[3]mpg)))
(Dp3DmpgF: `p3f'*([3]mpg+[3]forXmpg-(`p2f'*[2]mpg +
`p3f'*[3]mpg)))
(Dp3DmpgD: `p3d'*([3]mpg-(`p2d'*[2]mpg + `p3d'*[3]mpg)))  ;
*--------------------- end example ------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

--- Guido Heineck <[email protected]> wrote:

> Dear all.
>
> I'm somewhat struggling with calculating marginal effects for
> interaction variables in a multinomial logit model framework.
>
> Adapting two codes by Maarten L. Buis from prior posts that address
> related issues
> (http://www.stata.com/statalist/archive/2005-09/msg00126.html and
> http://www.datasets.org/statalist/archive/2006-05/msg01057.html) I
> get
> some results with the following code but I am unsure as to whether it
> is
> correctly programmed.
>
> *-------------- begin example -----------------
> #delimit ;
> sysuse auto, clear;
> recode rep78 2=1 3=1 4=2 5=3 ;
>
> gen forXmpg = foreign * mpg ;
>
> mlogit rep78 foreign mpg forXmpg ;
>
> sum foreign if e(sample) ;
> scalar mfor = r(mean) ;
> sum mpg if e(sample) ;
> scalar mmpg = r(mean) ;
>
> local exp2 "exp([2]_cons + [2]foreign*scalar(mfor)
>   + [2]mpg*scalar(mmpg) + [2]forXmpg*scalar(mfor)*scalar(mmpg))" ;
>
> local exp3 "exp([3]_cons + [3]foreign*scalar(mfor)
>   + [3]mpg*scalar(mmpg) + [3]forXmpg*scalar(mfor)*scalar(mmpg))" ;
>
> local p1 "1/(1 + `exp2' + `exp3')" ;
> local p2 "`exp2'/(1 + `exp2' + `exp3')" ;
> local p3 "`exp3'/(1 + `exp2' + `exp3')" ;
>
> nlcom (foreign: `p1'*(0-(`p2'*[2]foreign + `p3'*[3]foreign)))
>   (mpg: `p1'*(0-(`p2'*[2]mpg + `p3'*[3]mpg)))
>   (forXmpg: `p1'*(0-(`p2'*[2]forXmpg + `p3'*[3]forXmpg))) ;
>
> *--------------------- end example ------------------
>
> Any comment will be appreciated.
> Guido
>
>
> ----------------------------------------------
> http://www.unicef.org
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

___________________________________________________________
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```