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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: identifying a string of consecutive numbers |

Date |
Wed, 16 Apr 2008 18:03:36 +0100 |

Jon's criterion in general was "a series of consecutive zeros following any positive number" In the example he gave, the only positive numbers were all 1. I took a series of consecutive zeros to mean two or more zeros. How can zeros be consecutive if they occur singly? But if that is so, A does _not_ contain such a series, but C does. So, Jon's example does not match his criterion. I now guess that Sergiy is correct and that Jon did not mean what he said. Another way into this is to set aside 1. "111111" and 2. "00000" What remains are mixtures of 1s and 0s. We want to find patterns that are just 1s followed by 0s. These are the complement of patterns including any "01". In Sergiy's example these would be if !(strpos(yrs, "01") | strpos(yrs, "00000") | strpos(yrs, "11111")) Nick n.j.cox@durham.ac.uk Sergiy Radyakin I guess Nick's solution will give a false-positive in observation C (which also has a pattern 100), but not identify observation A, which ends in one 0 following a 1. I interpret the question as "how to identify observations ending in 0-spell after 1-spell". Here is how: input str5 years "11110" "11100" "11001" "10111" "00001" "00000" end gen indicator=strpos(strreverse(years),"0")>strpos(strreverse(years),"1") & strpos(years,"1")>0 list //----------------------------------------------------------------- the code requires at least one occurance of 1-spell, if this is not necessary, remove "& strpos(years,"1")>0". On 4/16/08, Nick Cox <n.j.cox@durham.ac.uk> wrote: > I don't understand what differentiates A and B from the other three, > but you can concatenate all and then search for patterns. > > . egen all = concat(yr?) > . l if strpos(all, "100") Jon Schwabish > 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. > > For example, say I have 5 years of data and the > following information for 5 observations: > > 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 > > The variable names are something like yr1, yr2, yr3, > yr4, yr5. I would like to create a variable that > differentiates ObsA and ObsB from the other three. * * 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/

**References**:**st: identifying a string of consecutive numbers***From:*Jon Schwabish <jschwabi@yahoo.com>

**st: RE: identifying a string of consecutive numbers***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: identifying a string of consecutive numbers***From:*"Sergiy Radyakin" <serjradyakin@gmail.com>

- Prev by Date:
**st: Baby Got Stats** - Next by Date:
**st: problem with stattransfer within Stata** - Previous by thread:
**Re: st: RE: identifying a string of consecutive numbers** - Next by thread:
**st: R: identifying a string of consecutive numbers** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |