Caroline B. Theoharides <[email protected]>:
There are several ways to do this depending on what kind of "marginal
effects" you want, and the syntax is given by -help nlogit
postestimation-. Perhaps the most natural approach is to simply
replace the value of kids with each of the possible values at which
you want to calculate predictions (i.e. each of your counterfactuals)
and predict probabilities. This uses the empirical distribution of
each choice's attributes, but I believe -spost- uses means of the
estimation sample instead (or would if it supported -nlogit-). The
two approaches are illustrated below. The second approach assumes
every restaurant has the same (mean) cost, distance, and rating, which
is why I say the first approach is more natural; others may disagree
with that assessment. The calculation of marginal effects will depend
on your counterfactuals.
clear all
webuse restaurant
nlogitgen type=restaurant(fast: 1 | 2, family: 3 | 4 | 5, fancy:6 | 7)
nlogit ch cost d ra||type:income kids,base(family)||re:,noconst case(f)
preserve
qui forv i=0/7 {
replace kids=`i'
predict p`i'_*, pr
forv r=1/7 {
su p`i'_2 if re==`r', meanonly
loc k`i'r`r'=r(mean)
}
}
loc l
forv r=1/7 {
forv k=0/7 {
loc l `l' `k`k'r`r'' `=`r'.`k''
}
}
loc o "recast(spike) yti(Prob) xti(Rest) yla(0(.1).5) xla("
forv r=1/7 {
loc o `"`o' `r'.4 "`:label (re) `r''" "'
}
loc o `"`o', angle(90))"'
tw scatteri `l', `o' name(e, replace)
bys type rest: su p*_2
restore
foreach v in cost d ra income {
su `v', meanonly
loc `v'=r(mean)
}
preserve
collapse ch cost d ra income kids fam, by(type rest)
foreach v in cost d ra income {
qui replace `v'=``v''
}
expand 8
bys type rest: replace kids=_n-1
bys type rest: replace fa=_n
predict p*, pr
loc l2
forv r=1/7 {
forv k=0/7 {
su p2 if rest==`r' & kids==`k', meanonly
loc l2 `l2' `r(mean)' `=`r'.`k''
}
}
tw scatteri `l2', `o' name(m, replace)
sort kids type rest
li type rest kids p2, noo sepby(kids)
restore
gr combine e m, ycommon nocopies ti(Pr Choice by Number of Kids)
On Fri, Jun 27, 2008 at 9:22 AM, Caroline B. Theoharides
<[email protected]> wrote:
> To clarify the question somewhat, an explicit example may be useful.
> In the context of the following nested logit model, we are trying to
> generate predicted probabilities of selecting each restaurant (7
> different outcomes) for each value of kids (i.e., kids=0, kids=1,
> kids=2, etc.).
> webuse restaurant, clear
> nlogitgen type=restaurant(fast: 1 | 2, family: 3 | 4 | 5, fancy:6 | 7)
> nlogittree restaurant type, choice(chosen)
> nlogit chosen cost distance rating || type: income kids,
> base(family)|| restaurant:, noconst case(family_id)
>
> Thanks for any suggestions.
>
> Caroline
>
> On 6/24/08, Caroline B. Theoharides <[email protected]> wrote:
>>
>>
>> Hello,
>>
>> I am running a 2 level nested logit model in Stata 10 using –nlogit-. Does
>> anyone know how to calculate marginal effects with the –nlogit- command?
>>
>> I specifically want to do post-estimation analysis of the predicted
>> probabilities, similar to that encompassed by –asprvalue- in –spost- (which
>> incidentally doesn't support nlogit). Is it possible to calculate these
>> predicted probabilities in Stata?
>>
>>
>> Thank you,
>> Caroline
*
* 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/