Announcement

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

  • Examples posted in the "bayesmh evaluator" online manual yield errors instead of executing

    I am using version 18 of Stata on a Windows 11 PC, and cannot get any of the user-defined evaluators provided in the user manual "bayesmh evaluators" to work. For example, consider program "logitll" defined on page 13 of the online manual at https://www.stata.com/manuals/bayesb...esmhevaluators.
    The first two lines of the program are:

    args lnfj xb
    quietly replace ‘lnfj’ = ln(invlogit( ‘xb’)) if $MH_y == 1 & $MH_touse

    The logitll ado file is called by the command "bayesmh foreign mpg, llevaluator(logitll) prior({foreign:}, flat)" given on p.14 of the same online manual. It is used in conjunction with the r19/auto data. Despite copying the ado file exactly as written in the manual, and placing it in my personal folder, the program will never work, always yielding the error message:

    ' invalid name
    logitll could not be evaluated
    r(198);

    Turning set trace on, the error seems to be triggered when execution encounters the apostrophe; it doesn't matter if a left or right apostrophe is used.

    I have a sinking feeling that there is a very simple and obvious fix to this problem, and that I am being incredibly obtuse. Could someone please point out what I'm missing?

  • #2
    Yes, unfortunately, the curly quotes used in the Stata manual around references to local macros may not automatically translate themselves into ` and '. So when copy/pasting code from the manual into the do-file editor, you may have to replace those characters. Now, I have to say that I have not encountered these problems in recent versions of Stata. And I can't replicate your problem in my setup, in either version 19.5 or version 17. (I don't have version 18 anymore.) But I do recall encountering it in the more remote past. Perhaps you are using something other than Stata's do-file editor?

    Another possibility, that still does occur, is that the code you are copying contains non-printing characters. You can't see them with your eye because they do not print out, but Stata sees them, and they confuse the parser. Here's something you can do to identify it either way. Copy the code into Stata's data editor (not the do file editor), as if each code line were an observation of a single variable in a data set. Then run -chartab- (by Robert Picard, available from SSC) to get a complete listing of all of the characters it contains, along with their hex and decimal and a descriptive name.

    On my setup, I get:
    Code:
    . chartab var1
    
       decimal  hexadecimal   character |     frequency    unique name
    ------------------------------------+----------------------------------------
            32       \u0020             |            13    SPACE
            36       \u0024       $     |             2    DOLLAR SIGN
            38       \u0026       &     |             1    AMPERSAND
            39       \u0027       '     |             2    APOSTROPHE
            40       \u0028       (     |             2    LEFT PARENTHESIS
            41       \u0029       )     |             2    RIGHT PARENTHESIS
            49       \u0031       1     |             1    DIGIT ONE
            61       \u003d       =     |             3    EQUALS SIGN
            72       \u0048       H     |             2    LATIN CAPITAL LETTER H
            77       \u004d       M     |             2    LATIN CAPITAL LETTER M
            95       \u005f       _     |             2    LOW LINE
            96       \u0060       `     |             2    GRAVE ACCENT
            97       \u0061       a     |             2    LATIN SMALL LETTER A
            98       \u0062       b     |             2    LATIN SMALL LETTER B
            99       \u0063       c     |             1    LATIN SMALL LETTER C
           101       \u0065       e     |             4    LATIN SMALL LETTER E
           102       \u0066       f     |             3    LATIN SMALL LETTER F
           103       \u0067       g     |             2    LATIN SMALL LETTER G
           105       \u0069       i     |             4    LATIN SMALL LETTER I
           106       \u006a       j     |             2    LATIN SMALL LETTER J
           108       \u006c       l     |             6    LATIN SMALL LETTER L
           110       \u006e       n     |             4    LATIN SMALL LETTER N
           111       \u006f       o     |             2    LATIN SMALL LETTER O
           112       \u0070       p     |             1    LATIN SMALL LETTER P
           113       \u0071       q     |             1    LATIN SMALL LETTER Q
           114       \u0072       r     |             2    LATIN SMALL LETTER R
           115       \u0073       s     |             2    LATIN SMALL LETTER S
           116       \u0074       t     |             3    LATIN SMALL LETTER T
           117       \u0075       u     |             2    LATIN SMALL LETTER U
           118       \u0076       v     |             1    LATIN SMALL LETTER V
           120       \u0078       x     |             2    LATIN SMALL LETTER X
           121       \u0079       y     |             2    LATIN SMALL LETTER Y
    ------------------------------------+----------------------------------------
    
                                        freq. count   distinct
    ASCII characters              =              82         32
    Multibyte UTF-8 characters    =               0          0
    Unicode replacement character =               0          0
    Total Unicode characters      =              82         32
    To the extent that your results differ, you will have identified spurious additional characters, or quote characters that didn't get transformed into ` ("GRAVE ACCENT") and ' ("APOSTROPHE"). The fix is then to edit them out, if you can, and, if not, to just remove the entire affected line of code and re-type it in by hand, avoiding copying from the PDF source.

    Correction: I can replicate your problem in version 19.5. I failed to do so earlier because I copied from your post here on Statalist. But when I go directly into the manual section that you linked in #1, I get:
    Code:
    . chartab var1
    
       decimal  hexadecimal   character |     frequency    unique name
    ------------------------------------+---------------------------------------------
            32       \u0020             |            17    SPACE
            40       \u0028       (     |             2    LEFT PARENTHESIS
            41       \u0029       )     |             2    RIGHT PARENTHESIS
            46       \u002e       .     |             2    FULL STOP
            50       \u0032       2     |             1    DIGIT TWO
            51       \u0033       3     |             1    DIGIT THREE
            61       \u003d       =     |             1    EQUALS SIGN
            97       \u0061       a     |             2    LATIN SMALL LETTER A
            98       \u0062       b     |             2    LATIN SMALL LETTER B
            99       \u0063       c     |             1    LATIN SMALL LETTER C
           101       \u0065       e     |             3    LATIN SMALL LETTER E
           102       \u0066       f     |             2    LATIN SMALL LETTER F
           103       \u0067       g     |             2    LATIN SMALL LETTER G
           105       \u0069       i     |             3    LATIN SMALL LETTER I
           106       \u006a       j     |             2    LATIN SMALL LETTER J
           108       \u006c       l     |             6    LATIN SMALL LETTER L
           110       \u006e       n     |             4    LATIN SMALL LETTER N
           111       \u006f       o     |             1    LATIN SMALL LETTER O
           112       \u0070       p     |             1    LATIN SMALL LETTER P
           113       \u0071       q     |             1    LATIN SMALL LETTER Q
           114       \u0072       r     |             2    LATIN SMALL LETTER R
           115       \u0073       s     |             1    LATIN SMALL LETTER S
           116       \u0074       t     |             2    LATIN SMALL LETTER T
           117       \u0075       u     |             1    LATIN SMALL LETTER U
           118       \u0076       v     |             1    LATIN SMALL LETTER V
           120       \u0078       x     |             2    LATIN SMALL LETTER X
           121       \u0079       y     |             1    LATIN SMALL LETTER Y
         8,216       \u2018       ‘     |             2    LEFT SINGLE QUOTATION MARK
         8,217       \u2019       ’     |             2    RIGHT SINGLE QUOTATION MARK
    ------------------------------------+---------------------------------------------
    
                                        freq. count   distinct
    ASCII characters              =              66         27
    Multibyte UTF-8 characters    =               4          2
    Unicode replacement character =               0          0
    Total Unicode characters      =              70         29
    I've put the offending results in red. I think you'll just have to edit them out, unfortunately.

    Last edited by Clyde Schechter; 13 May 2025, 17:10.

    Comment


    • #3
      Originally posted by Simon Parker View Post
      . . . the program will never work, always yielding the error message:

      ' invalid name
      Seems to be the identical error and error message as for this recent OP's problem. If it's a recurring problem, then Clyde's observation might be worth putting in an FAQ.

      By the way, when I run the code (I manually typed it in and not copy-and-pasted it), I get a different error message when running under version control for Release 18, but not for the current release. See below for the code and error message. I don't have the documentation for Release 18 anymore, but perhaps there was a change in the syntax? (Did Release 18 have the scalarlnden option?)

      Code for the evaluator ado file:
      Code:
      *! logitll.ado
      program define logitll
          version 18
          args lnfj xb
      
          quietly {
              replace `lnfj' = ln(invlogit(`xb')) if $MH_y == 1 & $MH_touse
              replace `lnfj' = ln(invlogit(-`xb')) if $MH_y == 0 & $MH_touse
          }
      end
      Code for the do file:
      Code:
      *! logitll_test.do
      
      version 18 // <= Note
      
      clear *
      
      quietly use https://www.stata-press.com/data/r19/auto
      
      set seed 14
      capture noisily bayesmh foreign mpg, llevaluator(logitll) prior({foreign:}, flat)
      display in smcl as result _rc
      
      version 19 // <= Note
      
      set seed 14
      bayesmh foreign mpg, llevaluator(logitll) prior({foreign:}, flat)
      
      exit
      Error message for the first (version 18) command:

      evaluator logitll must return the total log-density
      The return scalar lnf is not set.


      Do-file, ado file and log file are attached.

      Attached Files

      Comment


      • #4
        Joseph and Clyde: hearty thanks for such prompt and thorough responses.

        I took your advice of typing my own code, saving the program as an ASCII file, then changing the file type to .ado. I then reran the code exactly as in the manual. Good news! - the old error message disappeared. Bad news: was replaced by:

        logitll could not be evaluated
        r(491);

        I am guessing that this class of estimators is not yet stable across different Stata releases?

        Comment


        • #5
          Originally posted by Simon Parker View Post
          logitll could not be evaluated
          r(491);

          I am guessing that this class of estimators is not yet stable across different Stata releases?
          Mmm, in my experience that error message is typically the result of a typographical or syntax error that I've made in the evaluator coding. So, I'm more inclined to think that you've still got something wrong in your transcription. I recommend checking your code again.

          As an alternative: I've attached my transcription of the add file in #3 above and it's for your Release 18. Download it and give it a try.

          Comment


          • #6
            Hi Joseph - Thanks, I did give it a try, ran it just as it is, but got the same error:


            [P] error . . . . . . . . . . . . . . . . . . . . . . . . Return code 491
            could not find feasible values
            You are using ml and it could not find starting values for which
            the likelihood function could be evaluated. You could try using
            ml search with the repeat() option to randomly try more values,
            or you could use ml init to specify valid starting values.

            Comment


            • #7
              Originally posted by Simon Parker View Post
              . . . I did give it a try, ran it just as it is, but got the same error:
              It runs for me—see the log file. Is your Stata up to date? (update query.)

              Also, check whether you've got a typographical or syntax error in your bayesmh command line.

              Comment

              Working...
              X