Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: pb with mL both with d0 and d1 (numerical derivatives pb or flat region)

 From Valerie Orozco To "statalist@hsphsun2.harvard.edu" Subject st: pb with mL both with d0 and d1 (numerical derivatives pb or flat region) Date Thu, 29 Sep 2011 13:07:48 +0000

```Hi,

I have a new question concerning Maximum Likelihood estimation on Stata.
I wrote a probit model estimation with mL (Where Y is a 3 levels variable, not a binary variable) (see my program below).

I began with a d0 mL estimation which works well on my first set of variables (Z1) (see example Z1_d0 below). But when I add 2 more variables to the set Z1 (going to Z2), I have an error "could not calculate numerical derivatives -- discontinuous region with missing values encountered" (see example Z2_d0 below).

So I had the idea to program a d1 ML estimation hoping it will help convergence.
Fortunately, the d1 estimation on Z1 gives the same results than with the d0 estimation (see example Z1_d1 below).

But unfortunately, this d1 estimation doesn't help convergence concerning the Z2 set of variables. I still have a message "cannot compute an improvement -- flat region encountered" (see example Z2_d1 below).

What strange is that a colleague wrote the estimation on Matlab and it runs both with Z1 and Z2 (with a d1 estimation).

Do you have an idea? What am I doing wrong? What can I do more (please help me not to switch to Matlab).

Thank you very more.

valérie

/*******************************************/
/************* Z1_d0 example ***************/
/*******************************************/
ml model d0 mlZ (class_bmi2=\$VarZ ,nocons)   ,technique(dfp)
ml check
ml search
ml maximize
Number of obs   =       4388
Wald chi2(7)    =     466.14
Log likelihood = -3814.5343                       Prob > chi2     =     0.0000

------------------------------------------------------------------------------
class_bmi2 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
etude |  -.0994435   .0092792   -10.72   0.000    -.1176304   -.0812567
age |   .0028481   .0008506     3.35   0.001      .001181    .0045151
auto |  -.0852969   .0261524    -3.26   0.001    -.1365546   -.0340392
clas |   .0381725   .0207485     1.84   0.066    -.0024937    .0788388
nf |  -.0499705   .0192123    -2.60   0.009    -.0876258   -.0123151
Cal_Jour_i~f |   .0572555   .0144158     3.97   0.000     .0290011    .0855099
nbext_sem2 |  -.0094686   .0066547    -1.42   0.155    -.0225116    .0035745
------------------------------------------------------------------------------

/*******************************************/
/************* Z1_d1 example ***************/
/*******************************************/
ml model d1 mlZ_d1 (class_bmi2=\$VarZ ,nocons)   ,technique(dfp)
ml check
ml search
ml maximize

Number of obs   =       4388
Wald chi2(7)    =     466.14
Log likelihood = -3814.5343                       Prob > chi2     =     0.0000

------------------------------------------------------------------------------
class_bmi2 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
etude |  -.0994435   .0092792   -10.72   0.000    -.1176304   -.0812567
age |   .0028481   .0008506     3.35   0.001      .001181    .0045151
auto |  -.0852969   .0261524    -3.26   0.001    -.1365546   -.0340392
clas |   .0381725   .0207485     1.84   0.066    -.0024937    .0788388
nf |  -.0499705   .0192123    -2.60   0.009    -.0876258   -.0123151
Cal_Jour_i~f |   .0572555   .0144158     3.97   0.000     .0290011    .0855099
nbext_sem2 |  -.0094686   .0066547    -1.42   0.155    -.0225116    .0035745
------------------------------------------------------------------------------

/*******************************************/
/************* Z2_d0 example ***************/
/*******************************************/
ml model d0 mlZ (class_bmi2=\$VarZ  erreur_conso  erreur_rep_ext,nocons)   ,technique(dfp)
ml check
ml search
ml maximize

initial:       log likelihood = -4064.3941
rescale:       log likelihood = -4064.3941
could not calculate numerical derivatives -- discontinuous region with missing values
encountered
r(430);

/*******************************************/
/************* Z2_d1 example ***************/
/*******************************************/
ml model d1 mlZ_d1 (class_bmi2=\$VarZ     erreur_conso      erreur_rep_ext ,nocons)   ,technique(dfp)
ml check
ml search
ml maximize

.....
Iteration 303: log likelihood = -3814.5344  (backed up)
cannot compute an improvement -- flat region encountered
r(430);

/*******************************************/
/**********   Stata d1 Program    **********/
/*******************************************/
program mlZ_d1
args todo b lnf g
mat bb=`b'
capture drop Z
tempvar Pnc  Z
tempvar gj

local nZ : word count \$VarZ
loc i 0
gen double `Z'=0
foreach vZ of glob VarZ  {
loc ++i
capture replace `Z' = `Z' + `b'[1, `i'] * `vZ'
}
local B0=0
local B1=1
capture drop Pnc
gen double `Pnc' = normal(`B0'-`Z') * (Yvar==0)  + (normal( `B1' -`Z' ) - normal(`B0' -`Z')) * (Yvar==1)     +  normal(`Z' - `B1' ) *  (Yvar==2)

mlsum `lnf'=ln(`Pnc')
if (`todo'==0 |`lnf'==.) exit

#delimit ;
qui gen double `gj' = ((-normalden(`B0'-`Z'))/normal(`B0'-`Z')) * (Yvar==0)
+  (- (normalden(`B1' -`Z') - normalden(`B0' -`Z')) / (normal(`B1' -`Z') - normal(`B0' -`Z')))  * (Yvar==1)
+  (normalden(`Z' - `B1') / normal(`Z' - `B1')) *  (Yvar==2)  ;
#delimit cr

mlvecsum `lnf' `g' = `gj'

end

-------------------------------
Valérie OROZCO
Toulouse School of Economics (INRA-GREMAQ)
21, allée de Brienne
F-31000 Toulouse, France

MF 219
+33 5 61 12 85 91
-------------------------------

*
*   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/
```