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

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

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: RE: RE: RE: Parsing not-quite-standard syntax
Date   Mon, 29 Nov 2004 12:01:04 -0000

Just tp spell it out for any others interested, 
-syntax- looks at what is in the local macro with 
name 0. 

By default, local 0 contains whatever you typed 
on the command line after the command name, so 
if I type 

. foo bar bazz 

This fires up command -foo- and passes to -foo- 
a macro 0 containing 

bar bazz 

and -syntax- can then process that macro. So if 
the -syntax- were 

syntax varlist 

-bar- and -bazz- should be variable names in 
your dataset (if not, -syntax- will throw you 

However, you can assign stuff to local 0, as 
here with -gettoken-, and even by 

local 0 <whatever>

and then get -syntax- to process that. However, 
beware that this will zap existing macros like 
varlist, if, in and options, so save them first. 

This kind of thing is especially useful for 
any mix of standard and idiosyncratic syntax, 
which is where we started. 

[email protected] 

David Harrison
> Nick
> Many thanks for your suggestions.
> After much experimenting, I would add "bind" to the gettoken 
> statement to avoid any problems parsing functions that 
> contain commas (this seems to be a very useful option I had 
> not come across before).
> Otherwise, this is pretty much what I have ended up with (but 
> a little more complicated to split off the name from the 
> beginning, as this turns out to be important for the real 
> program). Bundling if and in together has saved a lot of work 
> though. I also like the idea of using -syntax- to parse the 
> rest once the dodgy bits have been removed - very handy.

*   For searches and help try:

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