Announcement

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

  • A Mata written log-likelihood function with extra variables

    I am writing an ado file where I use the
    Code:
    ml
    command with a mata-written log-likelihood function.

    Specifically, my code is like below:
    Code:
    // my_fun command
    program define my_fun
                   version 18
                   syntax varlist
                   gettoken y xvars: varlist
                   ml model my_log_like_fun() (Eq.1: something) (Eq.2: something) ... (Eq.q: something)
                   ml maximize
    end
    
    // the mata written log-likelihood function
    mata:
    void my_log_like_fun (transmorphic scalar ML, real rowvector b, real colvector lnf)
    {
                   depvar = moptimize_util_depvar(ML, 1)
                   xb        = moptimize_util_xb(ML, b, 1)
                   something others
    
                    lnf       = expression
    }
    end
    Here, my two questions are like below.

    First, in the "my_log_like_fun" (specifically in expression), I need to use variables, say varlist2, that does not appear in Eq. 1 - Eq. q. But, I am not sure how to do that.

    Second, since the varlist2 are intrinsically different from the variables in the "varlist", I want to know how to distinguish the variable in the "syntax" line.
    For example, in the "ivregress" command, the syntax is "ivregress estimator depvar [varlist1] (varlist2 = varlist_iv) ... ".
    Like the "ivregress" command, I want to make a command in that we can specify "varlist2" and the "varlist2" is used in the "my_log_like_fun".

    How can I do that?
    Thank you
Working...
X