Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grouping with a condition

    Hello all,

    Below is the data I am using:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(start end) byte ID
    16071 16454 1
    16455 16620 2
    16819 17166 2
    17167 17911 2
    end
    format %td start
    format %td end
    I want to group these observations based on whether the end date is one day before the next start date. If the end date is not one day before the next start date, then it is its own group. For example, the first two observations should be group 1 and the last two observations should be groups 2 and 3.

    I would appreciate any help.

    Anoush K.

  • #2
    Anoush, you may try the code below.

    Code:
    gen group = sum(start-end[_n-1]!=1)

    Comment


    • #3
      Fei Wang Works perfectly! Thank you.

      Comment

      Working...
      X