I guess the technically correct way is to parse it manually at a low level:
syntax, *
if "`options'" == "myoption" local myvarlist _all
else {
tokenize `options' , parse("()")
* local 1 must be myoption
* local 2 must be (
local myvarlist `3'
* local 4 must be )
}
You would want to augment Sergiy's suggestion with treatment of all
other possible causes of a failing -syntax- (incorrect option names,
if/in conditions, whatever). In my implementation, you would want to
make sure that `options' indeed contains the word "myoption", etc.
On Thu, Oct 8, 2009 at 1: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/
>
--
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
* 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/