Announcement

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

  • How to pass extra information to a maximum-likelihood evaluator when using ml?

    Hi,

    I know that, if I directly use Mata's moptimize, I can use moptimize_init_userinfo and moptimize_util_userinfo to pass extra information to the evaluator programme. However, I prefer to use Stata's ml to call Mata's moptimize, so I would like to know whether there is any option in ml for doing that? Specifically, I need an extra dummy variable and a scalar to specify the log-likelihood function in the Mata evaluator programme.

    I am also aware that ml's option group can pass an additional variable to the evaluator, and the variable will be treated as a cluster indicator in the calculation of robust errors. However, this is not a solution for me, because the extra variable I need is not a cluster indicator. Using ml's option group will seriously underestimate robust errors in my model.

    A temporary solution found so far is specifying the dummy variable as an additional dependent variable in Stata's ml, and using it by moptimize_init_depvar in Mata. However, I don't really like this method, since it messed up the code a bit, and also the dummy variable is not really a dependent variable in the model. More importantly, this method cannot pass a scalar to the evaluator.

    Overall, I would like to know whether there is any documented or undocumented option in Stata's ml for doing what moptimize_init_userinfo and moptimize_util_userinfo do in Mata.

    (PS1. I consider this this question mainly as a question about Stata rather than Mata, so I post it here.)

    (PS2. I am using Stata 14, but hope that my programmes can be backward compatible to at least Stata 11.)



    Thank you very much.

    Chi-lin

  • #2
    Ehen writing commands using Stata's ml I typically pass on extra information using global macros. This can also be the name of (temporary) variables or (temporary) scalars.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten, thanks for this advice. Using global macros is indeed a way out, and I did use this method for passing scalars to Mata evaluators. However, if I understand correctly, when my programme creates a global macro for its own purpose, there is always a possibility of overwriting users' macro. Certainly, I can choose a rarely used macro name to reduce that possibility, or backup users' macro and restore it after my programme executed. However, I still wonder whether there is undocumented options in ml for making everything even easier.

      Anyways, thank you very much.

      Comment


      • #4
        I understand your misgivings about using globals, I share them. I try to avoid them whenever possible, and it feels very awkward using them whenever I failed to find another solution.

        I tend to use names that start with S_ML. Using such conventions is I think more reasonable than trying to guess which names are rarely used.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Hoping someone is still paying attention, even though the last post was 8 years back. Now with version 17, are there any ways to get around using global macros for passing ancillary information to ml evaluators? It works, but feels clunky.

          Thanks

          Paul

          Comment


          • #6
            Nope, your choice is still either use global macros or go to Mata.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment

            Working...
            X