Announcement

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

  • Repeated options (syntax)

    Dear All,

    the following reference describes the use of repeated options in Stata:
    https://www.stata.com/manuals/g-4con...tedoptions.pdf

    I do not find, though, a description of declaring commands that support repeated options.

    I'd like to declare a command that would support syntax such as

    mycmd , optname(x y "some text label) optname(z t "some other label") optname(u v "yet another text label) opt1() opt2() .....

    I believe repeated options are standard for graphing commands, where I can find an example of e.g. merging multiple by() options into a single by() option (see graph.ado). But I was wondering if there is a more straightforward declaration of it. I recall there were procedures to collect repeated options together either appending to each other, or replacing the previous value with the current for each option, but don't seem to find them now.

    Ideally, I'd like the syntax to be something like: syntax , optname(string repeated)
    then `optname' should evaluate to `"`"x y "some text label""' `"z t "some other label""' `"u v "yet another text label""'"'
    with which I can later do word 1, word 2, etc. to obtain individual triplets.


    A head on approach results in an error:
    Code:
    program define foobar
      version 16.0
      syntax , myoption(string)
      
      display `"`myoption'"'
    end
    
    . foobar, myoption("1") myoption("2")
    option myoption() not allowed

    Any advice is welcomed.

    Thank you, Sergiy

  • #2
    For what it's worth, I am not aware of a higher-level implementation of repeated options. The looping approach in graph.ado is similar to how margins parses multiple at() options, which leads me to believe that there is no general-purpose program for this. There is the undocumented _get_gropts but it only has a short online help file (hence: undocumented); might be worth a quick look anyway.

    Comment


    • #3
      https://www.stata-journal.com/articl...article=pr0048 may help, although the question is not identical.

      Comment


      • #4
        Dear Daniel and Nick,

        thank you very much for your responses. I have followed Nick's advice as presented in the Stata Journal issue that he pointed to and this worked perfectly for my needs.

        Much appreciated!

        Best, Sergiy

        Comment

        Working...
        X