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



/* 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
                 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' =
                 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,
                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' =
                 by newid: gen double `a'=`z4'+`e' if
                 mlsum `lnf' = `D'*`e'+(1-`D')*`a' if

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!
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index