On Friday, Etienne asked how to compute an interaction effect after
-tobit-.
In principle, this is not difficult to do. It can get tricky though
if you have large numbers of variables as the expressions involved
get rather long. But I will do a small example to show Etienne
the idea of what needs to be done.
We begin by making sure we know what the predict formulas are after
-tobit-. I will use only pr() for the purposes of this example:
clear
sysuse auto
tobit mpg len, ll(20)
predict xb,xb
predict p, pr(20,.) /* Probability Uncensored */
gen myp = norm(-((20-xb)/_b[_se]))
sum p myp
The marginal effects are the derivatives of p with respect to the
independent variables. If the model contains interactions,
the there will be second derivatives which are non-zero, and these
are called interaction effects.
Before we get to the second derivatives, let's makes sure we know how
to get the first derivatives. I differentiate in the normal way (ie.
using calculus, applying the chain rule) and then let -nlcom- work out
the standard error for me. Since this is what -mfx- does, I can
compare my answer to that from -mfx-:
clear
sysuse auto
tobit mpg len, ll(20)
sum len
local meanlen=r(mean)
nlcom normden(-((20-(_b[len]*`meanlen'+_b[_cons]))/_b[_se]))
*(_b[len]/_b[_se])
mfx, predict(pr(20,.))
I evaluated the derivative at the mean of length, sicne that is the
default for -mfx-.
The variable length was a continuous variable. If I had used a
dichotomous 0/1 variable, I would not have needed calculus:
I would have subtracted the probability at for=0 from that at for=1.
For an example of calculating the second derivative, I will
interact a continuous variable with a dichotomous variable:
clear
sysuse auto
gen X=for*len
tobit mpg len for X, ll(20)
sum len
local meanlen: di %5.2f r(mean)
local xb1 "_b[len]*`meanlen'+_b[for]*1+_b[X]*`meanlen'*1+_b[_cons]"
local xb0 "_b[len]*`meanlen'+_b[for]*0+_b[X]*`meanlen'*0+_b[_cons]"
nlcom normden(-((20-(`xb1'))/_b[_se]))
*(_b[len]/_b[_se])-normden(-((20-(`xb0'))/_b[_se])) *(_b[len]/_b[_se])
In this example I first took the derivative of norm(-((20-xb)/_b[_se]))
with respect to the continuous variable len to obtain
normden(-((20-(xb))/_b[_se]))*(_b[len]/_b[_se]). I then evaluated it
at for=0 and substracted that from it evaluated at for=1, that is, I
took the discrete difference.
The expression I pass to -nlcom- depends on whether or not I have
a continuous-dichotomous, dichotomous-dichotomous or
continuous-continuous interaction.
-- May
[email protected]
*
* 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/