Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: MLE for descrete competing risk model


From   csepulve@bu.edu
To   statalist@hsphsun2.harvard.edu
Subject   st: MLE for descrete competing risk model
Date   Fri, 21 Apr 2006 00:03:42 -0400

I am trying to program a MLE for a descrete competing risk model but I am not
able to get a result. It says it cannot find feasible values. I would appreciate
any comments on the program. 

Here is the baseline model. I take data on miscarriages, abortions and weeks
when the lost happend. The probability of individual i being "assigned" a
miscarriage in period t is mit*=exp(Cmt). The probability of being "assigned" an
abortion is ait*=exp(Cat). t=2,..17. Assume if misc and abortion are assigned in
the same week misc occurs. Then, the probability of observing a miscarriage
(mit) or abortion (ait) in period t is:
mit=[1-(sum from j=1 to t-1 of ait*)]mit*
ait=[1-(sum from j=1 to t of mit*)]ait*

Taking the logs is the ML of each individual. 

The program i wrote is the following. (Some additional notes: I set initial
values calculated under other method which should be correct, but `lnf' is
always missing, but given the initial values there is a value for lnf. I try to
set the "K" terms in the program as scalars but is the same). 


program define myreg15
		args lnf Cm2 Ca2 Cm3 Ca3 Cm4 Ca4 Cm5 Ca5 Cm6 Ca6 Cm7 Ca7 Cm8 Ca8 Cm9 Ca9 Cm10
Ca10 Cm11 Ca11 Cm12 Ca12 Cm13 Ca13 Cm14 Ca14 Cm15 Ca15 Cm16 Ca16 Cm17 Ca17 
		local z=2
		while `z'<18{
		tempvar Km`z' Ka`z'
		local z=`z'+1
}						
		quietly gen double `Km2'=exp(`Cm2')
		local z=2
		local z1=3
		while `z1'<18{
		quietly gen double `Km`z1''=`Km`z''+exp(`Cm`z1'')
		local z1=`z1'+1
		local z=`z1'-1
}
		quietly gen double `Ka3'=exp(`Ca2')
		local z=3
		local z1=4
		while `z1'<18{
		quietly gen double `Ka`z1''=`Ka`z''+exp(`Ca`z'')
		local z1=`z1'+1
		local z=`z1'-1
}
		quietly replace `lnf'=`Cm2' if $ML_y1==1&$ML_y3==2
		local x=2
		while `x'<18{
		quietly replace `lnf'=ln(1-`Km`x'')+`Ca`x'' if $ML_y2==1&$ML_y3==`x'
		local x=`x'+1
}
		local y=3
		while `y'<18{
		quietly replace `lnf'=ln(1-`Ka`y'')+`Cm`y'' if $ML_y1==1&$ML_y3==`y'
		local y=`y'+1
}
end
ml model lf myreg15 (misc_all abort weeks_preg=) () () () () () () () () () ()
() () () () () () () () () () () () () () () () () () () ()  ()
ml init -6.45782681 -5.94542101 -5.60789065 -5.35395693 -4.7158448 -3.80446541
-6.83320455 -5.34381695 -4.52569379 -3.65878487 -6.39577033 -4.58382953
-5.28623071 -3.83417347 -3.82233771 -3.2374956 -5.11313324 -4.44926961
-5.20495454 -4.22983444 -6.69191836 -4.44207392 -4.11287927 -3.66223752
-6.24095207 -6.36816729 -6.64431467 -6.36671088 -6.64216545 -5.85448909
-5.38581614 -4.36783975, copy
ml maximize


I appreciate any help you can give me. 

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