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

st: Question on maximum likelihood estimation


From   Liqun An <[email protected]>
To   [email protected]
Subject   st: Question on maximum likelihood estimation
Date   Sun, 22 Jun 2003 01:00:03 -0700 (PDT)

Dear List,

I am wondering if anyone could give me suggestions on
the following codes that I wrote. It seems that "ml
search" or "ml check" could never find a feasible
value to start. The error message is "could not find 
feasible values". I have checked the codes many times
but still couldn't figure out what goes wrong. 

Any suggestion would be greatly appreciated.

Frank

************************************************

/* This is to construct our own likelihood function
and maximize it*/
/* the data used is "C:\DATA\dataact.dta"*/

clear set more off cap log close set mem 300m


cd c:\psid

log using "C:\psid\data16",replace t


capture program drop jtest

program define jtest
        version 6
        args todo b lnf
        
        tempvar theta1 theta2 
        tempvar z1 z2 z3 z4 z5 z12 a e D
        tempvar lt 
        tempname s_H alpha lsh lalp
        
        mleval `theta1' = `b', eq(1)
        mleval `theta2' = `b', eq(2) /*hazard rate*/
        mleval `s_H' = `b', eq(3) scalar
        mleval `alpha' = `b', eq(4) scalar
        
          quietly{ 
          
                 scalar `s_H' = `s_H'
                 scalar `alpha' = `alpha'
                 scalar `lsh' = ln(`s_H')
                 scalar `lalp' = ln(`alpha')
                      
                 gen double `z1' =
ln(normd(($ML_y1-`theta1')/(`s_H')))-`lsh' /*normal*/
                 gen double `z5' =
-(`theta2')*(($ML_y2)^(`alpha'))
                 gen double `z2' = ln(`theta2') +
`lalp'+ (`alpha'-1)*ln($ML_y2)+`z5' /*weibull*/
                                   
                 gen double `z12' = `z1'+`z2'         
        
                                       
                          
                by newid: gen  `lt' = cond(_n==_N,
_N,.)
                gen `D' = (`lt'==1) if `lt' !=. 
                                              
              
               by newid: gen double `z3' =
cond(_n==(_N-1), sum(`z12'),.)
               by newid: gen double `z4' = `z3'[_n-1]
if (`lt'!=.&`lt'!=1)               
                
                gen double `e' =
(1-$ML_y3)*(`z12')+($ML_y3)*(`z5') 
                 by newid: gen double `a'=`z4'+`e' if
(`lt'!=.&`lt'!=1)
                 
                 mlsum `lnf' = `D'*`e'+(1-`D')*`a' if
`lt'!=.
                 
             }  
                 
end



use "C:\DATA\dataact.dta", clear
/*gen lhv = ln(hv)*/
sort newid t
save "C:\DATA\dataact.dta", replace
use "C:\DATA\dataact.dta", clear
ml model d0 jtest (lhv dur c  = fsize)(age)/s_H /alpha


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
*
*   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