Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: forvalues loop shuts down when asked to "jump over" certain values


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: forvalues loop shuts down when asked to "jump over" certain values
Date   Thu, 7 Jan 2010 23:32:13 +0100

<>

You have a precision issue (see [U], 13.11) from 1.51 onwards, but for the
five files listed in your post, everything goes smoothly for me: I create
the files with the first loop and check for their presence beforehand with
the -dir- command. The second loop then displays "blah blah blah" for the
files containing "SURVEY", and not for the fourth one containing "DATA". 


*******
foreach file in 1.01SURVEY.csv 1.02SURVEY.csv /* 
 */ 1.03SURVEY.csv 1.04DATA.csv 1.05SURVEY.csv{
 clear*
 set obs 1
 gen x=1
 outsheet using `file', comma replace
}

dir *SURVEY.csv
dir *DATA.csv


forvalues i = 1.01(.01)13.01 {
	capture confirm file `i'SURVEY.csv
	di in r  "`i' " _rc
		if _rc==0 {
			di in r "blah blah blah"
		}
}

*******


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Dorothy Bridges
Sent: Donnerstag, 7. Januar 2010 23:16
To: [email protected]
Subject: st: forvalues loop shuts down when asked to "jump over" certain
values

Hi everyone,

I have a forvalues loop along the following lines:

forvalues i = 1.01(.01)13.01 {
capture confirm file `i'SURVEY.csv
if _rc==0 {
blah blah blah
}
}

My list of files is along the lines of:

1.01SURVEY.csv
1.02SURVEY.csv
1.03SURVEY.csv
1.04DATA.csv
1.05SURVEY.csv.

The loop works perfectly for the first three files, then stops when it
gets to 1.04DATA ... I want it to go on to 1.05SURVEY.  I attempted to
solve this problem with the capture confirm line, but no luck.  I
think I need another expression along the lines of, "if _rc~=0,
(continue the loop)".

Many thanks,
Dorothy
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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