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

st: ml problem


From   Edwin Leuven <[email protected]>
To   [email protected]
Subject   st: ml problem
Date   Fri, 5 Jul 2002 12:40:08 +0200

Just trying out ml, I programmed up a multinomial logit. Using the data used 
in Stata's manual ml can't find feasible starting values. Could someone 
enlighten me as to what I am doing wrong?

Thank you, Edwin.




/* my mlogit 
   assumes depvar is called y 
   categories are numbered 1 to k, 
   k is base category */
   
capture program drop mymlogit
program define mymlogit
args lnf
macro shift 1
local pars `*'
quietly {
    tempvar s
    g double `s' = 1
    local k = 1
    foreach theta in `pars' {
        replace `lnf' = `theta' if y==`k'
        replace `s' = `s' + exp(`theta')
        local k = `k' + 1
    }
    replace `lnf' = 1 if y==`k'
    replace `lnf' = `lnf' - ln(`s')
}
end



/* try it */
use http://www.stata-press.com/data/r7/sysdsn3.dta, clear

mlogit insure nonwhite, base(3)

local xvars nonwhite
rename insure y

/* with 3 categ you would call */
ml model lf mymlogit (`xvars') (`xvars')
ml max

/* with 2 categ you would call */
ml model lf mymlogit (`xvars')
ml max

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index