Announcement

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

  • Check empty vs not specified option

    Dear Statalist,

    I would like to implement an option of the form
    Code:
    program myprog
    syntax, [myoption(string)]
    ...
    ...
    end
    How can I check if the option has been specified but left empty such as
    Code:
    myprog, myoption()
    or if the option has not been specified such as
    Code:
    myprog
    ?

    In both cases the local `myoption' will be empty, but how can i distinguish between the two cases?

    Many thanks.

    Raffaele

  • #2
    As far as I know, you can't.

    Comment


    • #3
      You can't with one option, but Nick Cox came up with a neat trick to get around this by using two options, as explained in Stata Tip 79 You define myoption and MYOPTION2(string) and then check both. If "`myoption'`myoption2'" == "" nothing was specified (case 1), else if "`myoption2'" == "" the option was specified but left empty (case 2), otherwise a string was specified and will be in myoption2 (I guess this would be case 3). Note that you don't say myoption(), instead you say myoption or myoption(string). I used this trick in markstat to allow the options beamer and beamer(theme).

      Comment


      • #4
        Thanks to German for his generous comments. It's hard for me to imagine that I invented that. It's also very hard for me to remember where I first encountered it or even used it independently. No matter: just use it!

        Comment


        • #5
          Many thanks!
          Very useful trick!

          Comment

          Working...
          X