Announcement

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

  • Renaming person identity numbers in survey data

    Hello, I have survey data with lengthy person identity numbers, for example:
    1000600101
    1000600101
    1000600107
    1000600107
    1000600107
    1000600110
    1000600110
    etc.
    I would like to create a new column where the identity numbers (which have been sorted already) are reduced to the following:
    1
    1
    2
    2
    2
    3
    3
    etc.
    I would appreciate any advise on how to renumber the identity column taking into account duplicates (all identity numbers have at least one duplicate, some up to 8).
    Thank you.

  • #2
    Gregory:
    welcome to this forum,
    You may want to try:
    Code:
    egen new_id=group(id)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      To expand on @Carlo Lazzaro's answer.

      This is also an FAQ. See https://www.stata.com/support/faqs/d...p-identifiers/

      The solution below should work even if your identifier is string.

      Code:
      clear 
      input double bad_id 
      1000600101
      1000600101
      1000600107
      1000600107
      1000600107
      1000600110
      1000600110
      end 
      
      format bad_id %10.0f 
      
      egen better_id = group(bad_id)
      
      list , sepby(bad_id)
           +-----------------------+
           |     bad_id   better~d |
           |-----------------------|
        1. | 1000600101          1 |
        2. | 1000600101          1 |
           |-----------------------|
        3. | 1000600107          2 |
        4. | 1000600107          2 |
        5. | 1000600107          2 |
           |-----------------------|
        6. | 1000600110          3 |
        7. | 1000600110          3 |
           +-----------------------+

      Comment


      • #4
        Many thanks Carlo and Nick

        Comment

        Working...
        X