Nick -
Yes, I looked at the help and buried way down inside is this cyptic
reference:
option_descriptor optional_integer_value
type OPname (capitalization indicates minimal
abbreviation)
type (integer
type # (unless the option is required)
(the default integer value)
type )
Reading this, I never would have guessed that a default is required. So
I greatly thank you and Tom and Austin for taking the trouble to reply
to my questions.
Al
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Friday, December 14, 2007 9:19 AM
To: [email protected]
Subject: st: RE: [programming] syntax syntax
When -xb1()- takes a real argument and is an optional option then you
must specify a default, e.g. -xb1(real 0)-.
An equivalent constraint does not bite with a string argument, as an
empty string is the default.
The second question is answered by specifying
[varlist(default=none)]
The online help is very dense, but both points are covered.
Nick
[email protected]
Feiveson, Alan H.
I have two questions regarding the syntax of the "syntax"
statement:
1)
I've been trying to write a program (effcon.ado) that starts with
syntax [varlist] [if] [in] , confdir(string) level(real) [xb1(string)
n1(string) ]
tokenize `varlist'
local nv: word count `varlist'
di " nv = `nv'"
For some reason, this will work only if the "xb1" option is a string,
but not if I change it to real:
a) output when xb1 is a string in the syntax statement:
. discard
. effcon x1,level(.95) confdir(L) xb1(xyz) n1(asd) nv = 1 [it works,
etc.]
But if I change the "xb1" option to real, I get a syntax error:
b) output when xb1 is real in the syntax statement:
. set trace on
. discard
. effcon x1,level(.95) confdir(L) xb1(1.234) n1(asd)
------------------------------------------------------------------------
-------------- begin effcon ---
- version 9.0
- syntax [varlist] [if] [in] , confdir(string) level(real) [xb1(real)
n1(string) ]
invalid syntax
------------------------------------------------------------------------
---------------- end effcon ---
r(197);
2)
My second question deals with the word count of `varlist'. I want to
have the option of no variables in varlist. But if I don't list any in
my calling statement, `'varlist' is treated as a list of all the
variables in my dataset. I thought I could just count the elements in
`'varlist' and then do something if that count is zero (i.e. if I don't
enter any variables) - but the count comes out 12 (in this case) because
I have 12 variables in my data set. Any other suggestions on how to test
if I entered any variables in my calling statement?
Thanks
Al Feiveson
2) Example where I enter no variables but `varlist' contains all my
variables:
Contains data from temprat.dta
obs: 100
vars: 12 13 Dec 2007 08:05
size: 5,200 (99.9% of memory free)
------------------------------------------------------------------------
-------
storage display value
variable name type format label variable label
------------------------------------------------------------------------
-------
R float %9.0g
C float %9.0g
xb1 float %9.0g
xb2 float %9.0g
s float %9.0g
rat float %9.0g
rat10 float %9.0g
a float %9.0g
b float %9.0g
n1 float %9.0g
x1 float %9.0g
x2 float %9.0g
------------------------------------------------------------------------
-------
. discard
. set trace on
. effcon ,level(.95) confdir(L)
------------------------------------------------------------------------
-------------- begin effcon ---
- version 9.0
- syntax [varlist] [if] [in] , confdir(string) level(real) [xb1(string)
n1(string) ]
- tokenize `varlist'
= tokenize R C xb1 xb2 s rat rat10 a b n1 x1 x2
- local nv: word count `varlist'
= local nv: word count R C xb1 xb2 s rat rat10 a b n1 x1 x2
- di " nv = `nv'"
= di " nv = 12"
nv = 12
[rest omitted]
*
* 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/