Statalist The Stata Listserver


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

st: a question about loop and local marco name


From   "Jian Zhang" <[email protected]>
To   [email protected]
Subject   st: a question about loop and local marco name
Date   Thu, 26 Jan 2006 12:20:58 -0800 (PST)

Dear statalisters,

I have a question about the local marco name and loop.  I tried hard to 
figure the question out but can not.  Hope that you can help me out.  
Here is the question:

The following is the code that I tried to run:

local list="cuent p412 p413 p413c p414 p416 p417 p4171 p4172 p418 p419 
p420 p421 p422 p423 p424 p412ot" 

foreach x of local list {
     rename `x'_ `x'
}

but STATA returned with the following error message:
 
variable p4_ not found
r(111);

****

Then I run the following code.  The ONLY difference is that I did not use 
the equal sign in the local macro command (the first line of the code).  
This time it works!

***

I did not know why the change would make a difference.  It seems to me 
that it doesn't matter with/without equal sign in the local macro 
command.  

Then this time I shortened the list in the local marco command as follows:

local list="cuent p412" 
foreach x of local list {
	rename `x'_ `x'
}

It turns out that this time it works with AND without an equal sign in 
the local marco command.  I am really confused.  Is there any explanation 
why STATA does this?  Is there a general rule for using equal sign or not 
in the local marco command?

Thank you very much!

Jian Zhang





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