Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Another looping problem


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Another looping problem
Date   Fri, 4 Apr 2003 17:59:37 +0100

David Kantor
> 
> In response to Joel Clovis's question, I might add...
> 
> >         drop if Country~="`Country'"
> 
> With this being in the loop, after it executes in the 
> second iteration, you 
> will have no observations left.  (Unless you -use- your 
> basis set each 
> time, but that was not included in that loop.)
> 

The last statement within the outer -foreach- 
seems to read in the main data set once more. 

This points up that it would be more efficient to 
do something more like this:  

use <datafile>
sort Country Year 
cd "P:\IDPM\DBASES\WBFinStruct\tst1" 

foreach C in <list> {
	local OKvars
	foreach v of var cba2tfina-region {
		qui count if !missing(`v') & Country == "`C'" 
		if r(N) >= 35 {
			local OKvars "`OKvars'`v' " 
            }
	}
	outsheet `OKVars' if Country == "`C'" 
		using "Splus`Country'X" , comma replace
	outsheet RGDPCap if Country == "`C'" 
            using "Splus`Country'Y" , comma replace
}	


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

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