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

st: RE: -mlogit- & changing values of RHS (2nd try)


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: -mlogit- & changing values of RHS (2nd try)
Date   Tue, 19 Nov 2002 10:08:50 -0000

Daniel Müller
>
> I want to change some of the RHS variables in -mlogit-, then
> re-calculate the probability for a certain outcome with the
> original coefficients. I would like to do this to to compare
> the predicted probabilitites from the base estimation with
> probabilities resulting from the prediction with changed RHS
> variables.
>
> -----start-------
> ** here we go, base estimation & prediction:
> . local vars00 "d f g h j k"
>
> . mlogit lu00 `vars00', robust b(3) cl(v00acs) nolo
> <output supressed>
>
> . tokenize `vars00'
>
> . gen
> ypb_d1=exp([1]_b[_cons]+[1]_b[`1']+[1]_b[`2']+[1]_b[`3']+[1]
> _b[`4'])
>
> . gen
> ypb_n2=exp([2]_b[_cons]+[2]_b[`1']+[2]_b[`2']+[2]_b[`3']+[2]
> _b[`4'])
>
> . gen
> ypb_n3=exp([3]_b[_cons]+[3]_b[`1']+[3]_b[`2']+[3]_b[`3']+[3]
> _b[`4'])
>
> . ** base prob for outcome 1 (should be same as in -predict
> p00_1, outcome(1)- :
> . gen ypb=ypb_d1/(ypb_n2+ypb_n3)
>
> . su yp*
>
>     Variable |     Obs        Mean   Std. Dev.       Min
> Max
> -------------+----------------------------------------------
> -------
>       ypb_d1 |   22291     11.4102          0    11.4102
> 11.4102
>       ypb_n2 |   22291    4730.779          0   4730.779
> 4730.779
>       ypb_n3 |   22291           1          0          1
> 1
>          ypb |   22291    .0024114          0   .0024114
> .0024114
>
> -----end-------
>
> Obviously, the result is !!!CENSORED!!!. And here my questions:
>
> 1. What is wrong in the above code and gives me wrong
> predictions?
>
> 2. The 'real' data has more categories and many more
> variables. Is there a less error-prone and shorter way to
> write above code?

I guess you want exp(Xb) but your expressions omit
the X and as such evaluate to constants. Try

qui forval i = 1/3 {
	predict ypb_`i', outcome(`i') xb
	replace ypb_`i' = exp(ypb_`i')
}


Nick
n.j.cox@durham.ac.uk

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