Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: identifying a string of consecutive numbers


From   "Scott Merryman" <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: identifying a string of consecutive numbers
Date   Wed, 16 Apr 2008 07:14:19 -0500

On Tue, Apr 15, 2008 at 3:27 PM, Jon Schwabish <jschwabi@yahoo.com> wrote:
> Dear List,
>
> I'm hoping someone can help me with this b/c I'm
> totally stumped. I have a wide data set and am trying
> to identify observations that have a series of
> consecutive zeros following any positive number.

Something like this?

clear
input str4 id y1 y2 y3 y4 y5
ObsA  1 1 1 1 0
ObsB  1 1 1 0 0
ObsC  1 1 0 0 1
ObsD  1 0 1 1 1
ObsE  0 0 0 0 1
ObsF  1 5 7 2 0
ObsG  1 0 1 0 1
end
forv i = 1/4 {
	gen diff`i' =1 if  y`i' == 0 & y`=`i' +1' !=0
}
egen tag = anymatch(diff*), values(1)
drop diff*
l

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