Statalist The Stata Listserver


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

st: RE: Re: Foreach nested in Foreach


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Foreach nested in Foreach
Date   Thu, 19 Oct 2006 11:31:58 +0100

A further simplification to your code is 

su group, meanonly
forvalues i=1/`r(max)' {
	levelsof bvd_id_number, local(levels)
	foreach l of local levels {
		forval k = 1/`year_count' { 
			replace gamo = gamo + (tax[_`l']-tax[_`k'])*ratio_assets[_`k'] ///
			if bvd_id_number==`l' 
		}
	}
}

Here I replaced your -while- loop with another -forval-
and stripped the semi-colons cluttering up the 
code like weeds on a lawn. (Seriously, using ; 
as a delimiter doesn't mix well with looping.) 
This is all predicated on year_count being 
defined previously. 

That said, your problem is puzzling and difficult 
to debug at a distance. 

If you sprinkle your code with 

macro list 

you may get a handle on which macros are not what you 
intend. Otherwise my wild guess is that your problem
is a side-effect of getting semi-colons
in the wrong place. 

Nick 
[email protected] 

Socrates Mokkas
 
> Another problem that I have with my code below
> is that it turns out the message that I exceed the limit of 
> the macro. How could I possibly solve the problem?
>  
> #delimit;
> su group, meanonly
> forvalues i=1/`r(max)' {;
> levelsof bvd_id_number, local(levels)
> foreach l of local levels {;
> local k=1
> while `k'<=`year_count' {;
> replace gamo=gamo + (tax[_`l']-tax[_`k'])*ratio_assets[_`k'] 
> if bvd_id_number==`l' 
> local k=`k'+1
> };
> };	
> };
> 

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