Announcement

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

  • Trying to create a Unique Identifier for a Survey Data. (Have tried following other posts but nothing has worked)

    Hello,
    I hope this post finds you well !
    The version of STATA being used is 14.2

    The following is a glimpse of the data i am dealing with. In reality, there are much more variable
    Region Hospital_number age
    1 1 18
    1 1 25
    1 2 30
    1 2 45
    1 2 34
    1 2 50
    2 3 missing
    2 3 missing
    2 4 missing
    Only the data on region and hospital number is complete for all the patients in the survey.

    I want to generate a variable which gives numeric id to each patient within the hospital of a each region. From the data i know that in region 1, and hospital 1, there are 2 patients, and at hospital number 2, there are 4 patients.
    When running the command egen patient_id=group(Hospital_number Region), the new variables basically displays the same data as Hospital_number.
    I would be most obliged if anyone can help.

    Kind Regards

  • #2
    Welcome to Statalist.

    I think the following will start you in a useful direction.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(region hospital_number age)
    1 1 18
    1 1 25
    1 2 30
    1 2 45
    1 2 34
    1 2 50
    2 3  .
    2 3  .
    2 4  .
    end
    
    sort region hospital_number age
    by region hospital_number: generate patient_id = _n
    list, noobs sepby(region hospital_number) abbreviate(20)
    Code:
    . list, noobs sepby(region hospital_number) abbreviate(20)
    
      +---------------------------------------------+
      | region   hospital_number   age   patient_id |
      |---------------------------------------------|
      |      1                 1    18            1 |
      |      1                 1    25            2 |
      |---------------------------------------------|
      |      1                 2    30            1 |
      |      1                 2    34            2 |
      |      1                 2    45            3 |
      |      1                 2    50            4 |
      |---------------------------------------------|
      |      2                 3     .            1 |
      |      2                 3     .            2 |
      |---------------------------------------------|
      |      2                 4     .            1 |
      +---------------------------------------------+

    Comment


    • #3
      Sir Williams,

      I cannot thank you enough. It was so simple.

      For some reason, i find it really complex to do simple things on stata. But i will learn !

      Kind Regards,

      Comment

      Working...
      X