Statalist


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

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


From   Klaus Pforr <[email protected]>
To   [email protected]
Subject   Re: st: RE: forvalues loop shuts down when asked to "jump over" certain values
Date   Fri, 08 Jan 2010 00:02:38 +0100

I guess that the extended macto function <dir> might be helpful for you.
in your example it should something like this:

* create a list of all files, that fit the pattern ?survey.csv in macro
* filelist
local filelist: dir "directory_where_your_files_are" files "?survey.csv"

* loop over files in filelist
foreach file in `filelist' {
	bla bla bla
}

Klaus
Martin Weiss schrieb:
> <>
> 
> I could not replicate your initial problem, but anyway: I suspect it had
> something to do with the issues in
> http://www.stata.com/support/faqs/data/float.html
> and
> http://www.stata.com/support/faqs/data/prec.html
> 
> 
> HTH
> Martin
> 
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Dorothy Bridges
> Sent: Donnerstag, 7. Januar 2010 23:44
> To: [email protected]
> Subject: Re: st: RE: forvalues loop shuts down when asked to "jump over"
> certain values
> 
> Brilliant, thanks guys!  Problem solved.
> 
> On Thu, Jan 7, 2010 at 5:35 PM, Kieran McCaul <[email protected]>
> wrote:
>> ...
>>
>> try the following:
>>
>> forvalues i = 101(1)1301 {
>> local j = round(`i'/100,0.01)
>> capture confirm file `j'SURVEY.csv
>> if _rc==0 {
>> blah blah blah
>> }}
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Dorothy
>> Bridges
>> Sent: Friday, 8 January 2010 6:16 AM
>> 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/
>>
> 
> *
> *   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/

-- 
__________________________________

Klaus Pforr
MZES AB - A
Universität Mannheim
D - 68131 Mannheim
Tel:  +49-621-181 2801
fax:  +49-621-181 2803
URL:  http://www.mzes.uni-mannheim.de

Besucheranschrift: A5, Raum A312
__________________________________



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