My ML program works well with manually generated dummy variables and it works well with xi: too. So I decided to allow factor variables within the ML program by using fv in syntax as shown below, but then that just does not work. It generates the error: "could not calculate numerical derivatives -- discontinuous region with missing values encountered" however I just cannot pinpoint where the problem is.

Should not adding fv in the syntax as shown below just do the trick for allowing factor variables so that using xi: would not be needed? Why does xi works with my ML program but fv does not? How can I pinpoint what the problem is? Any ideas?

Below is a simplified example:

Code:
mata:
mata clear
void mymlmata(transmorphic scalar ML, real rowvector b, real colvector lnfj)
{
    depvar = moptimize_util_depvar(ML, 1)
    xb = moptimize_util_xb(ML,b,1)

    // a lot of estimation algorithms here
}
end

capture program drop mymlprog
program mymlprog, eclass
    syntax varlist(fv)
    gettoken lhs rhs : varlist
    _fv_check_depvar `lhs'
    ml model lf mymlmata() (`lhs' = `rhs')
    ml max
end

tab year, gen(yr)
mymlprog depvar yr2-yr5 var2 // THIS WORKS

xi: mymlprog depvar i.year var2 // THIS WORKS TOO and generates the same results as above

mymlprog depvar i.year var2 //THIS DOES NOT WORK and issues the mentioned error