| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: predict with adjusted constant in e(b) returns probabilitiesout of range after logit
From |
Daniel Mueller <[email protected]> |
To |
[email protected] |
Subject |
Re: st: predict with adjusted constant in e(b) returns probabilitiesout of range after logit |
Date |
Wed, 15 Nov 2006 11:28:57 +0100 |
Arne,
yes, that did the job! Thanks a bunch!!
Daniel
- Arne Risa Hole wrote on 11/15/2006 11:22 AM
Hi Daniel,
When you use -predict- following your "eret post b V" command you get
the linear prediction xb instead of the probability of a positive
outcome exp(xb)/(1+exp(xb)). Try replacing the last block of commands
in your code with:
// predictions with constant-adjusted e(b)
mat li e(b)
mat b = e(b)
mat score double xb = b
gen double pfor_adj = exp(xb)/(1+exp(xb))
su pfor* xb
Hope this helps
Arne
. // predictions with constant-adjusted e(b)
. mat li e(b)
e(b)[1,4]
mpg price weight _cons
y1 -.12109183 .00092639 -.00684974 13.56217
. mat b = e(b)
. mat score double xb = b
. gen double pfor_adj = exp(xb)/(1+exp(xb))
. su pfor* xb
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
pfor_base | 74 .2972973 .3698118 .0000411 .9838551
pfor_adj | 74 .2313865 .3184607 .0000174 .9626613
xb | 74 -3.987828 4.049815 -10.96 3.249673
On 15/11/06, Daniel Mueller <[email protected]> wrote:
Greetings!
After disproportionate sampling in a -logit- model I adjust the constant
term in e(b), leaving all other elements of e(b) unchanged. The
adjustment
procedure is based on Maddala (2001, p. 352). There, he states that
coefficients
are unaffected by disproportionate sampling in logit while the
constant term
needs to be decreased by log(p_1)-log(p_0) where p_1 and p_0 are the
proportion
of observations selected from each groups of y=1 and y=0.
I use the procedure pasted below to adjust the constant in e(b). But
it returns
predicted probabilities that are out of the range of 0 to 1 (between
-11 and +3,
see bottom of page). What have I overlooked? Why, in any case, is
-predict-
after logit returning predicted values that are out of range? How can
I fix that?
Thank you in advance for any insights!
Daniel
// do-file with -coefadj-
prog def coefadj, eclass
version 9
syntax , coef(int) val(real)
mat b = e(b)
mat V = e(V)
mat b[1,`coef'] = `val'
eret post b V
end
// (prog based on a post from Kit Baum)
sysuse auto, clear
loc samobs = 20
// generate proportions
qui cou if foreign == 0
loc for0 = (`samobs'/`r(N)') * 100
qui cou if foreign == 1
loc for1 = (`samobs'/`r(N)') * 100
loc constadj = log(`for1') - log(`for0')
loc depvar "mpg price weight"
qui logit foreign `depvar', nolo
qui predict pfor_base
// unadjusted e(b)
mat li e(b)
loc newcons = _b[_cons] - `constadj'
loc coefno0 : word count `depvar'
loc coefno = `coefno0' + 1
coefadj, coef(`coefno') val(`newcons')
// predictions with constant-adjusted e(b)
mat li e(b)
qui predict pfor_adj
su pfor*
--- relevant output
. // unadjusted e(b)
. mat li e(b)
e(b)[1,4]
mpg price weight _cons
y1 -.12109183 .00092639 -.00684974 14.422375
. // e(b) with adjusted constant
. mat li e(b)
e(b)[1,4]
mpg price weight _cons
y1 -.12109183 .00092639 -.00684974 13.56217
. // adjusted predictions - incorrect..
. qui predict pfor_adj
. su pfor*
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
pfor_base | 74 .2972973 .3698118 .0000411 .9838551
pfor_adj | 74 -3.987828 4.049815 -10.96 3.249673
Maddala, G.S. (2001) Introduction to Econometrics, Chichester: John
Wiley & Sons.
*
* 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/
*
* 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/
*
* 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/