Announcement

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

  • Separate observations depending on their value in one variable

    Hi all,

    I have a dataset with many variables that indicate people and certain characteristics, but several of them have the same identifier so they are in the same observation. I must separate each person in an observation of my own, but I have complicated a bit because not every identifier necessarily has the same number of people.


    I have something like this
    ID Name_1 Name_2 Name_3 Age_1 Age_2 Age_3 Health_1 Health_2 Health_3 Education_1 Education_2 Education_3
    1 Louis George 44 36 1 1 5 6
    2 Sara 27 2 6
    3 Gary Mary Jhon 53 23 12 1 2 1 7 4 3
    4 Renato 45 1 7
    And I want something like this
    ID Number Name Age Health Education
    1 1 Louis 44 1 5
    1 2 George 36 1 6
    2 1 Sara 27 2 6
    3 1 Gary 53 1 7
    3 2 Mary 23 2 4
    3 3 Jhon 12 1 3
    4 1 Renato 45 1 7
    I have tried with "expand" in several ways but I have failed in the attempt. I hope someone can solve my problem because I've been trying for a long time, thank you in advance.

  • #2
    You may start by taking a look at the - reshape long - command.
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by Marcos Almeida View Post
      You may start by taking a look at the - reshape long - command.
      Thanks, I was complicating doing loops and adding variables and observations one by one; I think that's what I was looking for!
      Best regards.

      Comment

      Working...
      X