Statalist


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

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


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: -syntax , option(varlist min=0)-?
Date   Thu, 8 Oct 2009 19:53:56 +0000 (GMT)

--- On Thu, 8/10/09, Nick Winter wrote:
> 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....

This trick is also discussed in the latest Stata Journal:

Nick Cox (2009) Stata tip 79: Optional arguments to options. 
The Stata Journal 9(3): 504.
http://www.stata-journal.com/article.html?article=pr0048

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------



Send instant messages to your online friends http://uk.messenger.yahoo.com 

*
*   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