Statalist The Stata Listserver


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

st: RE: Re: Foreach nested in Foreach


From   "John Bigelow" <j.bigelow@econgroup.com>
To   "Stata ListServe Address for Posting" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Foreach nested in Foreach
Date   Fri, 20 Oct 2006 09:46:14 -0400

The subject of semi-colons as line delimiters came up in a recent exchange
between Nick Cox Socrates Mokkas as follows (in part)
-----------------------------------------------------------------
Date: Thu, 19 Oct 2006 11:31:58 +0100
From: "Nick Cox" <n.j.cox@durham.ac.uk>
Subject: st: RE: Re: Foreach nested in Foreach

[  code suggestions deleted ]

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.) 

[  Additional suggestion of other points deleted ]

Otherwise my wild guess is that your problem
is a side-effect of getting semi-colons
in the wrong place. 

All of the foregoing was in respsonse to a request for help
with the following code 
> #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
> };
> };	
> };
> 

To my eye, at least one problem here looks like missing semi colons.
I bet the code would run better if semi-colons were added as below.

 #delimit;
 su group, meanonly ; /* Semi-colon added here */
 forvalues i=1/`r(max)' {;
 levelsof bvd_id_number, local(levels) ; /* Semi-colon added here */
 foreach l of local levels {;
 local k=1  /* Semi-colon added here */;
 while `k'<=`year_count' {;
 replace gamo=gamo + (tax[_`l']-tax[_`k'])*ratio_assets[_`k'] /* Semi-colon
NOT added here /* 
 if bvd_id_number==`l'  ; /* Semi-colon added here */
 local k=`k'+1
 };
 };	
 };
 
________________________________

This message is confidential and may be legally
privileged.  It is intended solely for the recipient(s)
named above.  If you receive this message in error,
please notify the sender and delete it from your computer.

________________________________

John P. Bigelow
The Princeton Economics Group
707 State Road, Princeton NJ 08540
J.Bigelow@EconGroup.Com <mailto:J.Bigelow@EconGroup.Com>   www.econgroup.com
<http://www.econgroup.com/> 
609.279.0600.x224 (Voice) 609.279.0201 (Fax)

________________________________




-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.8/489 - Release Date: 10/20/2006
 

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