Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: -syntax , option(varlist min=0)-?


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: -syntax , option(varlist min=0)-?
Date   Thu, 08 Oct 2009 16:25:26 -0400

Nice.

Nick Winter wrote:
Even spiffier:


program twoopts
    syntax varlist , [  MYOPTion1 MYOPTion2(varlist)  ]
di "varlist: [`varlist']"
    di "myoption1: [`myoption1']"
    di "myoption2: [`myoption2']"
if "`myoption1'"!="" local myoption `varlist'
    else if "`myoption2'"!="" local myoption `myoption2'

    di "myoption: [`myoption']"

end

This gives:

. twoopts mpg price
varlist:   [mpg price]
myoption1: []
myoption2: []
myoption: []

. twoopts mpg price , myopt(mpg)
varlist:   [mpg price]
myoption1: []
myoption2: [mpg]
myoption: [mpg]

. twoopts mpg price , myopt
varlist:   [mpg price]
myoption1: [myoption1]
myoption2: []
myoption: [mpg price]



This is documented somewhere, i think....

Nick Winter

Jeph Herrin wrote:
Thanks for the tip. I knew there must be a trick somewhere.
I can even do this, no?

  capture syntax varlist, myoption(varname)
  if _rc {
     syntax varlist, myoption
  }

cheers,
J


Sergiy Radyakin wrote:
Dear Jeph,

try:

capture syntax varlist, myoption(varname)
if !_rc {

  //program implementation for syntax1

  ....
  exit
}

syntax varlist, myoption
// program implementation for syntax2

this is often used when there are several distinct syntaxes possible
for a command.
See for example the implementation of -test- in test.ado.

Best regards, Sergiy Radyakin





On Thu, Oct 8, 2009 at 2:13 PM, Jeph Herrin <[email protected]> wrote:
I would like a program to take an option which contains
either a varlist or nothing. Something like

 syntax varlist..., myoption(varlist min=0)

which Stata doesn't like. The idea is that -myoption-
only applies to the listed variables in the primary varlist;
unless -myoption()- is specified, then it applies to all
variables in the primary varlist. This sounds confusing
even to me, so in pseudo code, I would like to have

 myprogram var1-var10, myoption(var1)

apply the option to only -var1-, but

 myprogram var1-var10, myoption

apply the option to var1-var10. Seems like I have done this
before, but it escapes me now. Any ideas?



thanks,
Jeph
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index