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

st: RE: invalid -syntax- when moving the option-bracket


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: invalid -syntax- when moving the option-bracket
Date   Mon, 11 Aug 2003 09:20:46 +0100

Daniel Mueller

> I am writing a program with several options and I am
> apparently missing something obvious in writing the -syntax-.
>
> The sytnax looks like:
> -----------
> syntax [varlist(num)] , opt1(varname) opt2(int) opt3(int)	///
> 	opt4(int) [ opt5(varname) otheropt SAVing(str) REPLACE ]
> -----------
> This program works.
>
> However, if I move the options-bracket -[- forward, Stata
> immediately gives me an -invalid syntax-error when I run the
> program without executing one line of code (at least -set
> trace on- doesn't show any executed code). E.g., the following
> does not work (-[- moved forward, now between opt1 and opt2):
> -----------
> syntax [varlist(num)] , opt1(varname) [ opt2(int) opt3(int)	///
> 	opt4(int) opt5(varname) otheropt SAVing(str) REPLACE ]
> -----------
>
> Where could my mistake be hidden?

Now that, for example,

opt2(int)

is a genuinely optional option Stata expects you to specify
a default. For example, specify a 0 default.

opt2(int 0)

One common trick is to specify a sensible default.

An alternative is to specify

opt2(numlist int)

and then later check whether "`opt2'" != "". If it is, the user
specified something: what's more, it must be legal, otherwise
the input would have been rejected. That's attractive because you can
add
constraints as in

opt2(numlist int >0)

which with the other route you have to spell out at some length.

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