Announcement

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

  • optimize()

    Hi,

    I just started using Mata program and so I was not sure if it would be feasible to estimate the function that I am interested.

    First, what I am interested in optimizing the function is the following :

    \theta = arg max(p-q)' A (p-q)

    where p is a vector that stacks scalar value (probability), q is another probability vector, and A is a weighting matrix, which seems to be computed endogenously in the program. In order to estimate the above, I have tried to write a code below (source: http://repec.org/snasug08/nichols_gmm.pdf).

    Code:
     mata:  void i_crit(todo,b,crit,g,H)  {  
       external y,X,W  
       m=X’(y-X*b’)
       crit=(m*W*m’)
        }
    
    y = st data(., "px")
    cons=J(rows(y),1,1)
    X = st data(., "px2"), cons
    W=cholinv(X’X)
    init=J(1,cols(X),0)
    S=optimize init()
    optimize init evaluator(S, &i crit())
    optimize init which(S,"min")
    optimize init evaluatortype(S,"d0")
    optimize init params(S,init)
    p=optimize(S)
    
    end

    Second question is how the mata program works to "see" the estimated results. The purpose of this code is to get the estimates of parameter values that minimize the objective function.


    Thank you for your help.
    Last edited by Priver JM; 27 Oct 2021, 14:04.

  • #2
    I would start by finding or making a simple example to test the code.
    It is best to have an example from some text to copy to try upon.
    If this example does not work, you can share the example with both code and data.
    Kind regards

    nhb

    Comment

    Working...
    X