I have the following custom ml problem.
I received the error: "could not calculate numerical derivatives -- flat or discontinuous region encountered". How do you debug this?
Code:
cap program drop censored_likelihood
program define censored_likelihood
version 17.0
args lnf sigma lambda gamma0 gamma1
tempvar m epsilon Iy0 Iy010 Iy10
local y "$ML_y1"
gen double `m' = (1 + (`lambda' - 1) * x * (`gamma0' - exp(-`gamma1' * z)))
gen double `epsilon' = `y' - `m'
qui replace `epsilon' = 0 if `y' == 0
gen double `Iy0' = (`y' == 0)
gen double `Iy010' = (`y' > 0 & `y' < 10)
gen double `Iy10' = (`y' == 10)
replace `lnf' = -0.5 * ln(2*c(pi)*`sigma'^2) - (`y'-`m')^2/(2*`sigma'^2) ///
+ `Iy0' * ln(normal(-`m'/`sigma')) ///
+ `Iy010' * ln(normal((10-`m')/`sigma') - normal(-`m'/`sigma')) ///
+ `Iy10' * ln(1 - normal((10-`m')/`sigma'))
end
ml model lf censored_likelihood (b1: y = x z, nocons) (lambda:) (gamma0:) (gamma1:) (sigma:)
ml check
ml maximize
I received the error: "could not calculate numerical derivatives -- flat or discontinuous region encountered". How do you debug this?

Comment