Announcement

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

  • How to Reshape data?

    Hi all,
    I have a question about how to reshape/transform data. How do I convert the top table to the bottom table?

    Thanks in advance!

    What I have:
    id labA_1 labB_1 DaysPostSurg_1 labA_2 labB_2 DaysPostSurg_2
    1 21 0.12 12 20 0.14 18
    2 30 0.36 7 19 0.30 13
    3 20 0.12 8 25 0.13 13



    What I would like:
    id labA labB DaysPostSurg
    1 21 0.12 12
    1 20 0.14 18
    2 30 0.36 7
    2 19 0.30 13
    3 20 0.12 8
    3 25 0.13 13

  • #2
    Code:
    clear 
    input id labA_1 labB_1 DaysPostSurg_1 labA_2 labB_2 DaysPostSurg_2
    1 21 0.12 12 20 0.14 18
    2 30 0.36 7 19 0.30 13
    3 20 0.12 8 25 0.13 13
    end 
    
    reshape long labA labB DaysPostSurg, i(id) string 
    
    sort id _j 
    
    list, sepby(id)
    
         +----------------------------------+
         | id   _j   labA   labB   DaysPo~g |
         |----------------------------------|
      1. |  1   _1     21    .12         12 |
      2. |  1   _2     20    .14         18 |
         |----------------------------------|
      3. |  2   _1     30    .36          7 |
      4. |  2   _2     19     .3         13 |
         |----------------------------------|
      5. |  3   _1     20    .12          8 |
      6. |  3   _2     25    .13         13 |
         +----------------------------------+

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X