Statalist The Stata Listserver


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

st: RE: RE: Re: Foreach nested in Foreach


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Re: Foreach nested in Foreach
Date   Thu, 19 Oct 2006 06:57:46 -0500

Another slight simplification would be move the -levelsof- outside the
loops.

su group, meanonly
local max = r(max)
levelsof bvd_id_number, local(levels)
forvalues i=1/`max' {
....

Scott


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: Thursday, October 19, 2006 5:32 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Re: Foreach nested in Foreach
> 
> 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'
> 		}
> 	}
> }
> 


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