Here's a neat alternative approach for getting two types of behavior from
the same option:
syntax [, X1a(real 0) X1b(varname numeric)]
The help file can just list the option name as x1, but Stata allows option
names to have the same abbreviation (as long as the full option name
differs) and then Stata will figure out how to parse it... sort of. In the
example case, if the user entered the option as -x1(mpg)- then x1a would be
set to 0 and x1b would be mpg. If they entered x1(12) then x1a would be 12
and x1b would be empty. The follow up code could check to see if x1b is
empty -- if not then they entered the varname, otherwise use the contents of
x1a...
Michael Blasnik
> David Kantor <dkantor@jhu.edu>
>
> I want to use -syntax- with an option, call it x1, which is to be
> allowed
> to be either a real number or a numeric variable. Thus, I want to
> combine
> these two forms into one:
>
> syntax, x1(real)
>
> syntax, x1(varname numeric)
>
> Is there an easy way to do this? I already have a solution, but I
> wonder
> if someone can point out a better way. Here is my solution (the main
> syntax also has a newvarname feature):
>
> syntax newvarname (numeric) , x1(passthru)
>
> local newvar "`varlist'"
> /* I captured `varlist', because I will now do several other -syntax-
> commands (which will wipe out `varlist').
> */
>
> local 0 ", `x1'"
> capture syntax , x1(real)
> if _rc {
> syntax , x1(varname numeric)
> }
>
> ////
> Thanks to anyone who has a better suggestion .
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/