Announcement

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

  • ODD behavior with local options

    Dear all,
    I was working on a small program where i could provide my own options, and i found some odd behavior i never noticed before
    If i used an option that that starts with "no" , the program doesnt seem to recognize it:

    See the example below:
    Code:
    capture program drop myp
    program myp
    syntax anything, [noway noseat onoway]
    display "Noway: `noway'"
    display "noseat: `noseat'"
    display "onoway: `onoway'" 
    end
    myp asd, noway noseat onoway
    * the output
    
    Noway: 
    noseat: 
    onoway: onoway
    I dont recall having this problem before. Any suggestions?
    Fernando

  • #2
    Nevermind,
    While I have no idea why this happens, an easy solution is to do the following:
    Code:
    capture program drop myp
    program myp
    syntax anything, [Noway Noseat onoway]
    display "Noway: `noway'"
    display "noseat: `noseat'"
    display "onoway: `onoway'" 
    end
    myp asd, noway noseat onoway

    Comment


    • #3
      This has to do with how you define, in -syntax-, boolean options, that are optionally on, or optionally off, especially the latter.

      As stated in the manual, when an option name starts with no, it's optionally off:

      The result of the option is returned in a macro name formed by the first 31 letters of the option's name, excluding the no. Thus option noreplace is returned in local macro `replace'; option nodetail, in local macro `detail'; and option noconstant, in local macro `constant'.

      The macro contains nothing if not specified, or else it contains the macro's name, fully spelled out, with a no prefixed. That is, in the noREPLACE example above, macro `replace' contains nothing, or it contains noreplace.
      For options that are optionally on, the manual states:

      Warning: Be careful if the first two letters of the option's name are no, such as the option called notice. You must capitalize at least the N in such cases.
      Last edited by Jean-Claude Arbaut; 04 Jul 2019, 10:37.

      Comment


      • #4
        Thank you Jean-Claude
        I was not aware of it.
        Best Regards

        Comment


        • #5
          Note also that capitalization indicates minimal abbreviation, which means that Noway could be written simply "n" when calling the program. You don't want to have two options with the same minimal abbreviation: how will Stata decide which one was meant by the user? I didn't check, but I expect that either it will throw an error, either Stata will silently pick one of them.

          You could write NOWay and NOSeat for instance, and the minimal abbreviation would be resp. "now" and "nos". Or you could avoid abbreviations, by writing NOWAY and NOSEAT. Of course you can also allow abbreviations of only one of the options.
          Last edited by Jean-Claude Arbaut; 04 Jul 2019, 10:48.

          Comment

          Working...
          X