Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: syntax; option real & varname


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   Re: st: syntax; option real & varname
Date   Thu, 15 Aug 2002 14:48:08 +0100

David Kantor <[email protected]>

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 .

>>> Different suggestion, which may be the same as yours really:

capture syntax , x1(real)
if _rc {
	capture syntax, x1(varname numeric)
}
if _rc {
	di as err "x1() should specify real number or numeric variable"
	exit 198
}

In short, if one -syntax- doesn't fit, the other one must.

Nick
[email protected]

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



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