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/