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   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Re: Foreach nested in Foreach
Date   Fri, 20 Oct 2006 15:11:59 +0100

You are quite right: if one uses semi-colons, they 
are not all where they should be. In terms of my post, 
however, I didn't believe that Socrates' code was exactly as he 
posted because otherwise the error message should have
been 

option forvalues not allowed 

which was not what he reported. When 
I stripped the semi-colons I also, as 
a side-effect, fixed the apparent typos 
that differentiate what he posted and 
what I guess he used. But that was insufficient 
for me to be clear on what the problem was. 

As this is a thread started but not closed by the starter, 
further comment is difficult. 

Nick 
n.j.cox@durham.ac.uk 

John Bigelow
 
> 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
>  };
>  };	
>  };
>  

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