Announcement

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

  • Grouping individual dates

    Hi. My data comprises several observations for each date. I want to generate a sequential numeric variable, that groups together the same date. For example, in the data below, all 22646 ==1, 22648==2, 22649==3...

    I'd greatly appreciate any help in doing so.


    Code:
    input float appt_date
    22646
    22646
    22646
    22646
    22648
    22648
    22648
    22648
    22648
    22648
    22649
    22649
    22649
    22649
    22649
    22649
    22649
    22649
    22650
    22650
    22650
    22650
    22650
    22651
    22651
    22651
    22651
    22651
    22652
    22652
    22652
    22652
    22652
    22652

  • #2
    In your example data, the observations are already sorted in appt_date order. If that is true of your full data set, then:
    Code:
    gen wanted = sum(appt_date != appt_date[_n-1])
    If in the full data set that is not true, then the simplest way to proceed would instead be:
    Code:
    egen wanted = group(appt_date)

    Comment


    • #3
      Clyde Schechter Thanks a lot!

      Comment


      • #4
        Note also the label option, which is often useful.

        FAQ . . . . . . . . . . . . . . . . . . . . . . Creating group identifiers

        3/01 How do I create individual identifiers numbered
        from 1 upwards?

        https://www.stata.com/support/faqs/d...p-identifiers/

        Comment

        Working...
        X