Statalist The Stata Listserver


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

st: Funky local macro result


From   dferry <[email protected]>
To   [email protected]
Subject   st: Funky local macro result
Date   Fri, 18 Aug 2006 11:13:10 -0400

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);

I have inserted -display- statements to verify that it is the final closing bracket which is causing the error. I have also verified that even though the program breaks as a result of this error, everything up unti this point works as it should. In other words, the global macro, X, contains exactly what it should. 

So, why is this happening, and what can I do about it? 

Thanks,
Danielle Ferry

capture program drop get_yx;
program get_yx;

	version 9;
	args y r;

	use time region using "$remach/data/regData" 
		if time>=q(1998-1) & region==`r', clear;
	count;
		
	if r(N)<900 {;
		local lagif "foreach l in 2 4";
	};

	else if r(N)>=900 {;
		local lagif "forval l = 1(1)4";
	};

	use using "$remach/pooledr/reg_unitroot" if region==`r', clear;
	
	levelsof diffvar if var=="`y'", local(y) c;
	levelsof diffvar if xy=="x", local(X) c;
	
	global y "`y'";
	global X = "";
	
	tokenize `X';
	local firstx `1';
	mac shift;
	local restx `*';

	foreach l in 2 4 {;
		global X "$X L`l'`firstx'";
	};

	while "`restx'"!="" {;

		tokenize `restx';
		local nextx `1';
		mac shift;
		local restx `*';

		foreach l in 2 4 {;
			global X "$X L`l'`nextx'";
		};
		
	};
	
end;



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