Announcement

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

  • Maximum likelihood _ "ml"_ programming_reparametization return error "+age* invalid name"

    I am trying to fit the reparametized model to my data, but stata 13.0 keeps returning error message "+age* invalid name".
    In my data IGG.dta, there are only two variables, igg and age.
    Could someone please point out where went wrong in my code? Thanks a lot!
    Below is my code:
    *================================================= ================
    cap prog drop ll
    prog define ll
    args lnf a b c d e f
    tempvar b t k
    qui gen `b'=exp(`c'+age*`d')
    qui gen `t'=exp(`a'+age*`b')
    qui gen `k'=exp(`e'+age*`f')
    qui replace `lnf' = log(`b')-`k'*`b'*log(`t')-lngamma(`k')+ (`k'*`b'-1)*log(igg)-(igg/`t')^`b'
    end

    use IGG, clear
    ml model lf ll (=age)
    ml maximize
    *================================================= ================
    After typing in "ml check", below is the response Stata returned:
    *================================================= ================
    . ml check

    Test 1: Calling ll to check if it computes log likelihood and
    does not alter coefficient vector...
    FAILED; ll returned error 198.

    Here is a trace of its execution:
    ------------------------------------------------------------------------------
    -> ll __000008 __000009
    - `begin'
    = capture noisily version 13.1: ll __000008 __000009
    ---------------------------------------------------------------------------- begin ll ---
    - args lnf a b c d e f
    - tempvar b t k
    - qui gen `b'=exp(`c'+age*`d')
    = qui gen __00000A=exp(+age*)
    +age* invalid name
    ------------------------------------------------------------------------------ end ll ---
    - `end'
    = set trace off
    ------------------------------------------------------------------------------

    Fix ll.
    r(198);
    *================================================= ================


    Linda

  • #2
    You are supplying two arguments to a program you told to expect seven arguments. That first bites because local macro c is undefined.

    There is also some confusion: your code maps the third argument to b, but then you override that by asking for the same macro to include a temporary variable name.

    The root of this may be that you don't understand correctly what args does.

    By the way, we ask for full real names here, so a first name only falls short of that request.

    Comment


    • #3
      Hello Nick! Thank you for your quick reply. Apologies for not signing my full name, I will bear that in mind next time.
      I was given a model:

      `lnf' = log(`b')-`k'*`beta'*log(`t')-lngamma(`k')+(`k'*`b'-1)*log(`y')-(`y'/`t')^`b'

      Now I am trying to reparametize the model with:
      t=exp(`a'+`b'*age)
      b=exp(`c'+`d'*age)
      k=exp(`e'+`f'*age)


      And use maximum likelihood to fit the reparametized model to my data.
      Could you please be kind to point out where in my coding should be fixed? Thank you


      Linda Wong
      University of Leeds

      Comment


      • #4
        Sorry, but I don't understand this reparameterisation.

        Comment


        • #5
          I also don't understand what you're trying to do. For example, your log-likelihood expression contains "log(`t')", but you write that you want to have "t=exp(`a'+`b'*age)". But taking logs of this expression simply yields "`a'+`b'*age". And similarly for "b", though not "k".

          Apologies for not signing my full name
          The issue raised by Nick Cox is not to do with signing your name; it's to do with your registration name. Please read the FAQ -- hit the black strip at the top of the page -- to clarify what Nick was talking about, and how to change your registration name. (It's easy -- hit the Contact Us link at bottom right of screen, and make your request.)

          Comment

          Working...
          X