# Re: st: Error: "could not calculate numerical derivatives; missing values encountered" with command "ml model d0..."

 From Maarten buis To statalist@hsphsun2.harvard.edu Subject Re: st: Error: "could not calculate numerical derivatives; missing values encountered" with command "ml model d0..." Date Sat, 16 Aug 2008 06:51:11 +0100 (BST)

```I have 2 comments:
The first is a general strategy of dealing with these problems: Start
simple. In this case I would start with a piece-wise exponential model
without any frailty. This is easy to do and you can use official Stata
commands to compare the results of your model against their results.
That way you have a solid basis on which to add complications.

The second comment is that these types of models are pretty hard to
estimate, so they benefit a lot from good starting values. In essence,
you are doing a finite mixture model for survival data. Have a look at
the code from Partha Deb's -fmm- (downloadable from SSC) for an example
of how to create starting values for this kind of model.

Hope this helps,
Maarten

--- aguo@stanford.edu wrote:

> Hi there, I was trying to estimate a piece-wise exponential model
> with discrete shared frailty with "ml model d0" command but it always
> stopped here. I have no clue what have caused the problem. Can you
> give me some suggestions that I can try? Many thanks!
>
> The ado file that computes the lnf to be evaluated is this:
>
> program define myereghet_dlf_sh
> 	version 7.0, missing
> 	args todo b lnf
>
> 	tempvar beta
> 	tempname theta1 theta2
> 	tempname pi2base
> 	mleval `beta' = `b', eq(1)
> /* normalize theta1 to 0 */
> 	mleval `theta2' = `b', eq(2) scalar
> 	mleval `pi2base' = `b', eq(3) scalar
>
> 	local t = "\$EREGt"
> 	local t0 = "\$EREGt0"
> 	local d = "\$EREGd"
> 	local by "by \$EREG_by"
>
> 	quietly {
>
> /* Calculate the log-likelihood */
> 	tempname pi1 pi2
> 	scalar `pi1'=1/(1+exp(`pi2base'))
> 	scalar `pi2'=exp(`pi2base')/(1+exp(`pi2base'))
>
>  	        tempvar sums sumd logs dbeta sumdbeta
> 		gen double `logs' = exp(`beta')*(`t0'-`t') if \$ML_samp
> 		gen double `dbeta' = `d'*`beta' if \$ML_samp
>
> 		`by': gen double `sums' = cond(_n==_N, /*
> 			*/ sum(`logs'),.) if \$ML_samp
> 		`by': gen double `sumd' = cond(_n==_N, /*
> 			*/ sum(`d'),.) if \$ML_samp
> 		`by': gen double `sumdbeta' = sum(`dbeta') if \$ML_samp
>
> 		mlsum `lnf' = cond(`sumd'<.,  /*
>                    */ ln(`pi1'*exp( `sums' +`sumdbeta')  /*
> 			*/  +
> `pi2'*exp(exp(`theta2')*`sums'+`theta2'*`sumd'+`sumdbeta')),0)
>
> 		if `todo'==0 | `lnf'>=. {exit}
> }
> end
>
>
>
> The ado file that contains the ml command has the following lines:
>
> 	version 8.1: ///
> 	ml model d0 myereghet_dlf_sh /*
> 		*/ (`t': `t'=`rhs' ,  `constant' `offopt') /*
> 		*/ /theta2 /pi2base `w' if `touse', `cont' noout /*
> 		*/ `robust' `cluopt' `scopt' `iniopt' `mlopts' /*
> 		*/ missing collin nopreserve /*
> 		*/ max search(quietly) `log' `options'  /*
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

Send instant messages to your online friends http://uk.messenger.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

• References: