Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: [programming] syntax syntax


From   "Feiveson, Alan H. (JSC-SK311)" <[email protected]>
To   <[email protected]>
Subject   st: [programming] syntax syntax
Date   Fri, 14 Dec 2007 08:58:05 -0600

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



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