Dear Statalist,

I'm trying to generate conditional skewness and kurtosis by using Gram-Charlier Expansion Series. Essentially, I'm trying to estimate the following system:
Array

where my likelihood function is :
Array
Array


Array


The following is my code:
//////////////////////////////////////////
clear

set more off

set fredkey 0c79529a0ad2485bee772c948e68374e, permanently
import fred DEXJPUS, daterange(1990-01-02 2002-05-03) aggregate(daily,eop) clear

drop if missing(DEXJPUS)

tsset daten
format daten %td

gen ret = ln(DEXJPUS)-ln(DEXJPUS[_n-1])
drop if _n==1

export excel using "jpnusfx9102daily", firstrow(variables) replace


sum ret, detail
global h0=r(Var)
global s0=r(skewness)
global k0=r(kurtosis)

* Own maximum likelihood program *
capture program drop garchsktry
program garchsktry
args lnf mu b0 b1 b2 c0 c1 c2 g0 g1 g2
tempvar et ht st kt nt psi gamma

qui gen double `et'=$ML_y1-`mu'

qui gen double `ht'=1
qui gen double `nt'=`et'/sqrt(`ht')
qui gen double `st'=`nt'^3
qui gen double `kt'=`nt'^4


//qui gen double `ht'=$h0
//qui gen double `st'=$s0
//qui gen double `kt'=$k0
//qui gen double `nt'=`et'/sqrt(`ht')

qui replace `ht'=`b0'+`b1'*`nt'[_n-1]^2 + `b2'*`ht'[_n-1] if _n>1
qui replace `st'=`c0'+`c1'*`nt'[_n-1]^3 + `c2'*`st'[_n-1] if _n>1
qui replace `kt'=`g0'+`g1'*`nt'[_n-1]^4 + `g2'*`kt'[_n-1] if _n>1

qui gen double `psi'= log((1 + (`st'*(`nt')^3 - 3*`nt')/6 + (`kt'*(((`nt')^4-6*(`nt')^2+3))/24))^2)
qui gen double `gamma'= log(1+ (`st'^2)/6 + (`kt'^2)/24)

qui replace `lnf'= -0.5*(log(`ht')+(`et'^2)/`ht') + `psi'-`gamma'



end

ml model lf garchsktry (mu: ret=) /lnf /b0 /b1 /b2 /c0 /c1 /c2 /g0 /g1 /g2

ml init /b0=0.0061 /b1=0.0309 /b2=0.9537 /c0=-0.0494 /c1=0.0018 /c2=0.3414 /g0=1.2365 /g1=0.0014 /g2=0.6464
ml search
ml max, difficult
ml report

///////////////////////////////////////////////////////////
this keeps giving me the following message:
"could not calculate numerical derivatives -- flat or discontinuous region encountered
r(430);"

I'm thinking that it might be because the starting values maybe wrong, I tried to use unconditional moments, still I keep getting the same error message, is there a way to tell Stata to not rely too much on the starting values, it shouldn't be an issue. or can anyone tell me what is wrong with my program, I really run out of good ideas.
and It has been a really long time ago since I'm stuck in here, and any help is really really appreciated.
​​​​​​​

Sarah

P.S.: I forgot to mention that I'm using Stata 17, if that makes any difference.