Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Estimate marginal effects with interaction terms in non-linnear models.


From   "maartenbuis" <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Estimate marginal effects with interaction terms in non-linnear models.
Date   Tue, 06 Sep 2005 12:11:48 -0000

Hi Alexander,

Here are some general remarks about your question (which do not
explain your syntax error) and than some code that works on Stata 8.2
(I do not have version 9 yet) but the -version 8.2- command on top of
the code should ensure that it also works on your version. 

First, are you sure you want marginal effects? When using interaction
terms you think that the effect of a variables is different for males
and females, or foreign and domestic cars, or ... But with marginal
effects you summarize these different effects with one number, and
thus loose this information.

Second, as you already saw the code you used will give you the
marginal effect for the probit model instead of the logit model you
want to estimate. You can either continue to use the logit and use the
example code below, or switch to probit and use the example code
provided by the FAQ. Conclusions drawn form either model are usually
the same, so the choice can be entirely guided by what is practical
for you. 

Third, -predictnl- will create a new variable in your dataset with the
marginal effect as its value. You can see the result with -list xxx,
in 1-. -nlcom- is easier: it immediately shows the result, does not do
things to your data, and gives you standard errors and confidence
intervals.

Fourth, there are people who do not like means of dummy variables:
have you ever seen someone who is .504 female? They would suggest that
you use the modal category. My position is that the modal category is
also a good summary measure and using it saves you some whining from
these purists.

Fifth, if you want easier code than the logit allows you to calculate
 odds ratios, which is just if the continuous variable is xxx and the
interactionterm with the dummy is yyy than the odds ratios are
exp(_b[xxx]) when the dummy is zero and exp(_b[xxx]+_b[yyy]) when the
dummy is one. See the thread on statalist started by:
http://www.stata.com/statalist/archive/2005-04/msg00658.html

*-----------begin example code------------
version 8.2

sysuse auto, clear
gen good = rep78>=4 if rep78~=.
gen forXturn = foreign * turn

logit good turn foreign forXturn

sum foreign
local meanfor = r(mean)

sum turn
local meanturn = r(mean)

local xb = _b[_cons] + _b[turn]*`meanturn' + /* 
*/ _b[forXturn]*`meanturn'*`meanfor' + /*
*/ _b[foreign]*`meanfor'
nlcom exp(`xb')/(1+`xb')^2 * _b[turn] + _b[forXturn]*`meanfor'
*--------------end example code-------------

For an explanation of why this code works see the thread started by:
http://www.stata.com/statalist/archive/2004-11/msg00254.html.

Hope this helps,
Maarten

---"Dozet Alexander" <Alexander.Dozet@s...> wrote:
> Currently I'm trying to estimate marginal effects with a logit model 
> with 10 interaction terms (one continuous and one dummy). 
> Furthermore one of the interaction terms is age sqr*male. Hence the 
> use of -inteff- is not possible. I'm trying to learn how to use the 
> -predictnl- command but have run into some difficulties. I tried to
> re-estimate the probit model that is to be found in  "FAQ:I am using 
> a model with interactions. How can I obtain marginal effects and 
> their standard errors?" 
> However when I estimate 
> ...
> local xb _b[turn]*`meantur'  + /*
>                */  _b[dum]*`meandum' + _b[td]*`meantur'*`meandum' + 
> _b[_cons]
> predictnl dydt = normden(`xb')*(_b[turn] + _b[td]*`meandum') in 1, 
> se(set)
> ....
> just after -predictnl- i get the error message 
> invalid syntax
> r(198);
> Does any one know where the misstake is?



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



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index