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

st: Loops using local macros


From   "Pradeep Kurukulasuriya" <[email protected]>
To   <[email protected]>
Subject   st: Loops using local macros
Date   Tue, 16 Mar 2004 08:29:00 -0500

Dear STATA users:

I am relatively new STATA user and have a basic question on loops which
I hope some of you will be able to answer:

Suppose I have the following variables:

x1y1 x1y2 x2y1 x2y2

If I wanted to loop through these variables one possible solution is the
following:

local i=1
 while `i'<=2 {
   local j=1
     while `j'<=2 {
 
 {SOME STATA FUNCTION e.g tab x`i'`j'}

  local j=`j'+1
}
local i=`i'+1 
} 

This works fine. My problem is what do when there is an additional
variable, such as x3y1.

In this cases, I need to add a line or something to tell STATA to stop
the loop after it processes x3y1 and not to look to do x3y2 which
doesn't exist. I am a bit stuck here and I was hoping you might be able
to give me some pointers here. Any solutions come to mind?

Many thanks!
Pradeep


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