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 Harrison" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Parsing not-quite-standard syntax
Date   Fri, 26 Nov 2004 09:44:07 -0000


You say 'Stata isn't good at extra-sensory perception' however the command -use- can manage it...

. clear

. use auto.dta if foreign==1
(1978 Automobile Data)

. tab foreign

   Car type |      Freq.     Percent        Cum.
    Foreign |         22      100.00      100.00
      Total |         22      100.00

. clear

. use auto.dta in 1/10
(1978 Automobile Data)

. count

The syntax looks standard, but cannot be parsed by the -syntax- command. Suppose the program I wanted to write was as follows (in reality it is more complex, obviously)...

program foo
	syntax [name] [if] [in] [, *]
	use `namelist'.dta `if' `in' , `options'


. clear

. foo auto if foreign==1
foreign not found

. foo auto in 1/10
Obs. nos. out of range

So what I am trying to work out is how to manually parse the input (using -gettoken- and the like) to identify the name (if there is one), if statement (if there is one), in statement (if there is one) and options (if any are specified).

I could get around it by putting the [if] and [in] as options instead, eg

syntax [name] [, ifopt(string) inopt(string) *]

but this goes against the appeal of the intuitive standard syntax of Stata, so I wondered if anyone had overcome this problem before?

[email protected]

Nick Cox

> I don't however understand the bit about 
> variables not in memory. Stata isn't good 
> at extra-sensory perception... 
> 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:

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