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

st: RE: RE: Parsing not-quite-standard syntax


From   "David E Moore" <davem6@hartman-group.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: RE: Parsing not-quite-standard syntax
Date   Thu, 25 Nov 2004 13:18:21 -0800

When defining a program, the -if- and -in- expressions are intended as qualifiers to the program being defined and not solely to a
statement or program embedded within it.  Thus, logically, any variables mentioned in either clause must be present in the current
working dataset.  If you want to create and apply an -if- expression or an -in- clause to another program or statement running
within your program, then you need to obtain the relevant varlists and/or expressions via options.  An example might be:

program define foo
  syntax [name] [if] [in], [, useif(string) usein(string) opt1 opt2 *]
  /* do something */
end

If program "foo" has no need for -if- or -in- itself, then you are free to use these names as options.  Actually, I don't see why
you can't use the -in- clause either way, but it seems less prone to confusion to make it a separate option.  Moreover, you may need
to perform the error checking of the values passed via -if- and -in- yourself, since any variables referenced in the -if- expression
*will* need to exist at the time the call to -use- is issued.

I hope that explanation wasn't too convoluted.  Perhaps, you might receive a more elegant solution to your problem if you provided a
little more detail concerning how you would -use- -if- with nonexistent variables.  I mean, if they are not present in the current
working dataset, what's to keep you qua programmer from using any name you wish and hard coding that name in your program?

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Nick Cox
Sent: Thursday, November 25, 2004 7:12 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Parsing not-quite-standard syntax


There is nothing non-standard here about the
options, so I will set that on one side:

program foo
	syntax [name] [if] [in]
	marksample touse
	di "|`namelist'|"
	count if `touse'
end

shows that the syntax you need may essentially be
that of your specification. Absent a varlist,
-marksample- regards every observation as prima
facie acceptable, but -if- and -in- conditions
may throw out some, as normal.

I don't however understand the bit about
variables not in memory. Stata isn't good
at extra-sensory perception...

Nick
n.j.cox@durham.ac.uk

David Harrison

> I want to write a command with the syntax
>
> command [name] [if exp] [in range] [, opt1 opt2 *]
>
> BUT, the -if exp- and -in range- are to be applied in a -use-
> statement, so they may involve variables that are not in the
> dataset in memory. Any suggestions on how I can parse this to
> get the locals `namelist' `if' `in' `opt1' `opt2' and
> `options' that would be produced by -syntax-?
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index