Announcement

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

  • Nested Optimization on Mata

    I am trying to run a nested optimization routine for Empirical Likelihood with the following routine (where I am implementing a mini-max optimization routine over the function f = ln(1+lambda*g(b)), where g(b) are the moment conditions). Thus there are two sets of parameters, lambda (1 x cols(z)) and beta (1 x cols(x)). However it gives an error at the end stating 'starting values for parameters required', despite providing the starting values below. Any help would be highly appreciated,

    mata:
    void lambda1(todo,lambda,beta,f,S1,H)
    {
    real colvector y
    real matrix z, x
    u = y-x*beta'
    m= z:*u
    g = m*lambda'
    f = mean(ln(1:/(1:+g)))
    if (todo>=1){
    S1 = -mean(m:/(1:+g))
    }
    }
    real scalar function invda(real rowvector beta)
    {
    I=optimize_init()
    optimize_init_evaluator(I,&lambda1())
    optimize_init_evaluatortype(I,"d1")
    optimize_init_params(I,J(1,cols(H),0))
    optimize_init_argument(I,1,beta)
    optimize_init_which(I,"max")
    optimize_init_conv_maxiter(I,10000)
    optimize_init_singularHmethod(I,"hybrid")
    lambda=optimize(I)
    a = optimize_result_value(I)
    return(lambda)
    }

    void beta1(todo,beta,f,S2,H)
    {
    real colvector y
    real matrix z, x
    real rowvector lambda
    lambda=invda(beta)
    m= z:*u
    g = m*lambda'
    f = mean(ln(1:/(1:+g)))
    if (todo>=1){
    Q2 = mean(((z:*x[,1])*lambda'):/(1:+g))
    Q3 = mean(((z:*x[,2])*lambda'):/(1:+g))
    Q4 = mean(((z:*x[,3])*lambda'):/(1:+g))
    Q5 = mean(((z:*x[,4])*lambda'):/(1:+g))
    Q6 = mean(((z:*x[,5])*lambda'):/(1:+g))
    S2 = Q2,Q3,Q4,Q5,Q6
    }
    }
    S=optimize_init()
    optimize_init_evaluator(S,&beta1())
    optimize_init_evaluatortype(S,"d1")
    optimize_init_params(S,(b0))
    optimize_init_which(S,"min")
    optimize_init_technique(S, "nr")
    optimize_init_conv_maxiter(S,10000)
    optimize_init_singularHmethod(S,"hybrid")
    q=optimize(S)
    q
    end
Working...
X