Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: Re: Continuing a loop inspite of errors


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: Continuing a loop inspite of errors
Date   Wed, 25 May 2011 12:40:32 +0100

Your first post has yet to reach the list. Evidently there have been some recent problems. 

But something as simple as 

foreach v of var xxx?? { 
	...
} 

would have worked if there were no xxx00-xxx09 or xxx91-xxx99 or other variables matching that pattern. But note the general rule: -foreach- is happy with wildcards to indicate sets of variable names. 

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

Narahari H.S.

Some research got me the solution. Code is below

forvalues i=10/90{
capture noisily : sum xxx`i'
if _rc==111{
continue
}
}

--- On Wed, 25/5/11, Narahari H.S. <naraharihs@yahoo.co.in> wrote:

> From: Narahari H.S. <naraharihs@yahoo.co.in>
> Subject: Continuing a loop inspite of errors
> To: "statalist" <statalist@hsphsun2.harvard.edu>
> Date: Wednesday, 25 May, 2011, 12:26 PM
> Hello all,
> 
> I have to run a loop on a set of variables which are named
> like xxx10, xxx11,xxx13,xxx17.....xxx90. There is no set
> pattern in the number suffix of the variable name but the
> minimum suffix is 10 and max is 90.
> 
> I cant use -forvalues- as the suffixes are not continuous
> and they do not have a fixed difference. One way to do it is
> to use -foreach- but I have to manually enter all the
> variable names and thats quite cumbersome.
> 
> I could use -forvalues- if there was a command to continue
> the loop inspite of an error i.e. if I use -forvalues
> i=10(1)90{- , the looping is stopped when i is set to 12 as
> xxx12 is not present. 
> 
> Could you please tell me if theres a command for continuing
> the loop inspite of errors or any other technique to do
> this?
> 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index