> -----Original Message-----
> From: David Kantor [mailto:[email protected]] 
> Sent: Thursday, August 15, 2002 9:42 AM
> To: [email protected]
> Subject: st: syntax; option real & varname
> 
> 
> Hi everyone.
> 
> 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.  
> 
I would get x1 as a string, and then test it after your syntax line:
   syntax , x1(string)
   capture confirm new variable `x1'
   if _rc {
      confirm number `x1'
      if _rc {
         di as error "x1() must be a new variable name or a number"
         error 198
      }
      else {
         local isvar 0
	}
   }
   else {
      local isvar 1
   }
This also sets the local macro isvar to indicate if x1 is a variable
name or a 
number, in case you need to take different action for each...  (Note, by
the way, that the text of your message suggests that you want an
existing varname; the syntax you give suggests a new varname.  If the
former, just take the "new" out of the "confirm new variable `x1'" line.
Nick Winter
> 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 .
> -- David
> 
> David Kantor
> Institute for Policy Studies
> Johns Hopkins University
> [email protected]
> 410-516-5404
> 
> *
> *   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/
> 
*
*   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/