Statalist


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

st: RE: RE: [programming] syntax syntax


From   "Feiveson, Alan H. (JSC-SK311)" <alan.h.feiveson@nasa.gov>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: [programming] syntax syntax
Date   Fri, 14 Dec 2007 09:23:20 -0600

Thanks very much Tom - Your clear explanations resolve several hours of
frustration. By the way, this program (if it ever runs) makes use of
your non-central t package. So I'll use this opportunity to put in a
plug for it.

(ssc describe nct)

Al

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Steichen,
Thomas J.
Sent: Friday, December 14, 2007 9:11 AM
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: [programming] syntax syntax

Al,

When you specify an optional option as a real in the syntax statement,
you must also specify the default value.

For varlist, you can use suboption (default=none) to keep it blank.
Then your planned approach will work. For example:

syntax [varlist(default=none)] [if] [in] , confdir(string) ///
       level(real) [ xb1(real 1.0) n1(string) ]

Tom

-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2..harvard.edu] On Behalf Of Feiveson,
Alan H. (JSC-SK311)
Sent: Friday, December 14, 2007 9:58 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: [programming] syntax syntax

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/

-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the
attorney-client or other legal privileges, and/or proprietary non-public
information. If you are not an intended recipient of this message or an
authorized assistant to an intended recipient, please notify the sender
by replying to this message and then delete it from your system. Use,
dissemination, distribution, or reproduction of this message and/or any
of its attachments (if
any) by unintended recipients is not authorized and may be
unlawful.   

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



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