Statalist


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

FW: st: RE: identifying a string of consecutive numbers


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   FW: st: RE: identifying a string of consecutive numbers
Date   Wed, 16 Apr 2008 19:42:13 +0100

gen lastpos = . 

quietly forval i = 1/5 { 
	replace lastpos = `i' if yr`i' == 1 
} 

You can also collapse each string to its positive occurrences. 

gen signature = "" 
forval i = 1/5 { 
	replace signature = signature + "`i'" if yr`i' == 1 
} 

The last positive is then the last character of that signature. 
However, this is awkward whenever there are all zeros. 

	
Nick 
[email protected] 

-----Original Message-----
From: Jon Schwabish [mailto:[email protected]] 
Sent: 16 April 2008 18:18
To: [email protected]; Nick Cox
Subject: Re: st: RE: identifying a string of consecutive numbers

Sergiy & Nick,

Thanks for your responses; they were both very
helpful. And yes, Nick is correct, Observation A does
not follow the criterion I laid out. Nonetheless....

I was wondering if you might have some thoughts on a
follow-up question. How would you go about identifying
the *last* non-zero observation in the series? In
other words, a series of numbers such as "111000", how
would you identify the third number in the sequence
(or even the fourth as the *first* zero observation).


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index