Statalist The Stata Listserver


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

st: RE: Funky local macro result


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Funky local macro result
Date   Fri, 18 Aug 2006 11:25:26 -0500

I am not sure why Stata doesn't recognize the final closing bracket, but a
simpler example returns:

. sysuse auto,clear
(1978 Automobile Data)

. local lagif "foreach l in 2 4"

. `lagif' {
foreach command may not result from a macro expansion interactively or in do
files
r(198);


Since -foreach- cannot result from a macro expansion one way around this
would be to wrap the -foreach- and -forv- in -if- statements.  

For example:

count 
if r(N) > 900 {
	local lagif  "l in 2 4"
	local tag =1 
}
else {
	local lagif "l = 1(1)4"
	local tag =2
	}

if `tag' == 1 {
	foreach  `lagif' {
	//global X...
	}
}

if `tag' == 2 {
	forv `lagif' {
	//global X...
	}
}


Scott

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of dferry
> Sent: Friday, August 18, 2006 10:13 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Funky local macro result
> 
> Dear Statalisters,
> I've pasted in a program I wrote, below. As shown, it works just fine.
> However, if I change the lines that say:
> foreach l in 2 4 {;
> 
> to:
> `lagif' {;
> 
> then, I get an error in which Stata doesn't recognize the final closing
> bracket in the program. I.e., I get the following error msg:
> unrecognized command:  } invalid command name
> r(199);
> 


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