Announcement

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

  • Optimize with constraints

    Dear all,

    I need to minimize the following function L=(Xit*b- Y)^2 with nonlinear constraints.

    I have imported the matrix Xit [556,28] and the vector Y[556]
    so I need to find (the vector) b[28] subject to: b>=betaMAX (real colvector)

    I wrote the following commands in mata but Stata reports a "redundant or inconsistent constraints".
    This is my code:

    mata

    void maxme(todo,b,y,X,lnf,g,H)
    {
    lnf = (-y :+ X*b'):^2
    }

    init=J(cols(X),1,1)
    s=optimize_init()

    //build the constraint matrix
    C = I(28)
    c = exp(init):+betaMAX
    Cc = (C, c)
    optimize_init_constraints(s,Cc)

    optimize_init_evaluator(s,&maxme())
    optimize_init_evaluatortype(s,"v0")

    optimize_init_argument(s, 1, y)
    optimize_init_argument(s, 2, X)

    optimize_init_evaluatortype(s,"d0")
    optimize_init_which(s,"min")
    optimize_init_params(s, init')

    b = optimize(s)
    b'

    end

    Thank you,
    Giulia
Working...
X