Announcement

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

  • moptimize mata

    Is it possible to run moptimize() inside another moptmize() evaluator?

  • #2
    Yes, you can do that.
    I've used that set-up to choose the bandwidth parameter, where the main function involved a kernel density function.

    In my application, the main moptimize evaluator ran fine, but there were some problems with convergence. A key parameter of the objective function was changing with every iteration, so sometimes the problem would not converge.

    So it is technically possible, but it could complicate the actual optimization procedure.

    Mike



    Comment


    • #3
      Hi Mike,

      Thanks for your answer.

      I would like to ask another question.

      I am using moptimize to estimate a random effects probit (xtprobit, re in Stata). The Stata Reference Manual employs by default an adaptive Gauss Hermite quadrature, but it also suggests a non adaptive algorithm. The manual says that the adaptive procedure is better, but in several cases it does not matter.

      Thus, I estimated the model with a non adaptive algorithm and with a gf0 evaluator (panel data without analytical first and second derivatives). I created a small dataset (300 observations) and my code works pretty good. I have the same LLF, coefficients, and standard errors than xtprobit.

      However, once I use a real dataset (more than 25,000 obs.), the code does not work. It finds a local maximum quite far from the maximum of xtprobit.

      In your experience, do you think this is due to the adaptive algorithm that is employed by xtprobit or to the evaluator type (gf1 or gf2 should perform better than gf0)? I am asking that since it takes time to code all this stuff and I am not sure in which direction I should move.

      In addition, there is a way to say to moptimize to perform an operation like y=x+2 at each iteration?

      Thanks in advance.

      Simone

      Comment


      • #4
        Hi Simone,

        I don't really know about the quadradture question. That didn't come up at all in my application. It looks like you can control the quadrature method that xtprobit uses. Maybe you could force xtprobit to use the same method that your estimator uses, then see if you get the same answers.

        Are you sure that your estimator is getting stuck at a local maximum, and it is not just finding the wrong answer? If it is getting stuck at a local maximum, then there may be nothing wrong with your estimator. It may just be a difficult problem to estimate. You may just need to use different starting values.

        You can determine whether the problem is a local maximum by changing the starting values of your estimator. Set them to the coefficient estimates found by xtprobit. If your estimator produces estimates similar to the xtprobit estimates, then it's just a problem with starting values. If your estimator finds the same, incorrect, estimates that it found previously, then there is a problem with your estimator.

        I'm not sure what you mean with this question:
        "In addition, there is a way to say to moptimize to perform an operation like y=x+2 at each iteration?"
        Every operation that is in the objective function will be performed with every iteration.

        Mike

        Comment


        • #5
          Hi Mike,

          Thank you for your point.

          There was an error in my code since I assumed the dataset was already sorted by id and time, but it was not. I just did it before running the code and it works. My quadrature is not like Stata (adaptive) and it takes 5-7 times more, but it is OK for now. Thanks again.

          Comment

          Working...
          X