Announcement

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

  • 'invalid name' error in logit MLE program

    If anyone can help it would be great. I'm trying to do a logistic MLE. I've written an ado with the log-likelihood function, but it keeps giving me an 'invalid name' error. Here's my program:



    program mylogit_lf
    version 15.0
    args lnf xb
    quietly replace 'lnf' = ln(invlogit( 'xb')) if $ML_y1 == 1
    quietly replace 'lnf' = ln(invlogit(-'xb')) if $ML_y1 == 0
    end



    Here's the error after ml check:




    ------------------------------------------------------------------------------
    -> mylogit_lf __000008 __000009
    - `begin'
    = capture noisily version 15: mylogit_lf __000008 __000009
    ---------------------------------------------------------------------------- begin mylogit_lf ---
    - version 15.0
    - args lnf xb
    - quietly replace 'lnf' = ln(invlogit( 'xb')) if $ML_y1 == 1
    = quietly replace 'lnf' = ln(invlogit( 'xb')) if FO_label == 1
    ' invalid name
    ------------------------------------------------------------------------------ end mylogit_lf ---
    - `end'
    = set trace off
    ------------------------------------------------------------------------------


    I've tried with another more complicated program using the args -> tempvar -> gen double -> replace format, but this gives me the same error.


    Some one please help?


  • #2
    Welcome to Statalist.

    You've apparently advanced all the way to writing programs without having first mastered local macros. You should read Chapter 18 Programming of the Stata User's Guide PDF included in your Stata installation and accessible through the Stata Help menu, paying particular attention to section 18.3 Macros.

    Because the Stata User's Guide PDF is printed in a typeface that does not display punctuation identically to Stata, note that where the PDF has something that looks like
    Code:
     ‘shortcut’ 
    you need to type on your keyboard
    Code:
     `shortcut'
    where the first character is (on an American English keyboard) the "left single quote" beneath the tilde (~) character below the ESC key, and the final character is the usual "single quote" ("apostrophe") just to the left of the RETURN key.

    In your code this will be
    Code:
    program mylogit_lf
    version 15.0
    args lnf xb
    quietly replace `lnf' = ln(invlogit( `xb')) if $ML_y1 == 1
    quietly replace `lnf' = ln(invlogit(-`xb')) if $ML_y1 == 0
    end

    Comment

    Working...
    X