Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • optimize() "could not calculate numerical derivatives -- flat or discontinuous region encountered"

    Hi everyone,

    I am trying to run probit using optimize() function from mata. But, I always got the error message "could not calculate numerical derivatives -- flat or discontinuous region encountered". I am very new to mata so I wonder if I did this wrong. Really appreciate it if you can enlighten me on this. Thanks in advance!

    This is my current code:
    Code:
        // define function
        void PROBIT(real scalar todo, real vector b, real vector y, real matrix x, val, grad, hess) {
            real vector mu
            mu = normal(x*b')
            val = sum(y :* log(mu) + (1 :- y) :* log(1 :- mu))
        }
    
        // setting up initial values using regression
        stata("reg Y X")
        stata("mat b = e(b)")
        
        // preparing arguments and parameter
        y = Y
        x = X,J(1000,1,0)
        b = st_matrix("b")
        
        // optimization
        S = optimize_init()    
        optimize_init_evaluator(S,&PROBIT())
        optimize_init_evaluatortype(S,"gf0")
        optimize_init_technique(S,"bfgs")
        optimize_init_params(S,b)
        optimize_init_argument(S,1,y)
        optimize_init_argument(S,2,x)
        optimize(S)
        beta_probit = optimize_result_params(S)'
        beta_probit
Working...
X