Announcement

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

  • Reshaping Data

    Hello Everyone,
    I have this dataset that I'm trying to reshape, here's a snippet

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str24 name int(grade_year class1 class2 class3 class4)
    "Anthony"              5  56  66   34   66
    "Anthony"              6  45  78   89   12
    "Adam"                  5  59  70   30   100
    "Adam"                  6  45  56  34  21
    "Alexander"                  5  67  88   55   35
    "Alexander"                  6  35  53   85   87
    "Angela"                   5   60  72   93   34
    "Angela"                   6   91  98   91   89
    "Alfie"                5 13 23  94  76
    "Alfie"                6 49 15  57  33
    "Alan"                  5  30  51   31   91
    "Alan"                  6  29  41   62   70
    end
    I'm attempting to have the data reshaped to look a little something like this, here's an example with just the first "name".
    Anthony 5 56 Grade for 1
    Anthony 5 66 Grade for 2
    Anthony 5 34 Grade for 3
    Anthony 5 66 Grade for 4
    Anthony 6 45 Grade for 1
    Anthony 6 78 Grade for 2
    Anthony 6 89 Grade for 3
    Anthony 6 12 Grade for 4
    I'm new to Stata and I'm not sure that the reshaping tool can accomplish this but any help would be appreciated!

  • #2
    what you want can be achieved using -reshape long-,
    Code:
    reshape long class, i(name grade_year)
    for more information, type help reshape

    Comment


    • #3
      Hi, thanks for the help. I'm attempting to reshape my data to look like this instead:
      Anthony 5 1 56
      Anthony 5 2 66
      Anthony 5 3 34
      Anthony 5 4 66
      Anthony 6 1 45
      Anthony 6 2 78
      Anthony 6 3 89
      Anthony 6 4 12
      I tried to use the help functions but couldn't figure it out, any suggestions?

      Comment


      • #4
        the code in #2 should do the job,
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str7 name byte(grade_year class1 class2 class3 class4)
        "Anthony" 5 56 66 34 66
        "Anthony" 6 45 78 89 12
        end
        
        list, ab(10) clean
        
                  name   grade_year   class1   class2   class3   class4  
          1.   Anthony            5       56       66       34       66  
          2.   Anthony            6       45       78       89       12  
        
        reshape long class, i(name grade_year)
        
        list, ab(10) clean
        
                  name   grade_year   _j   class  
          1.   Anthony            5    1      56  
          2.   Anthony            5    2      66  
          3.   Anthony            5    3      34  
          4.   Anthony            5    4      66  
          5.   Anthony            6    1      45  
          6.   Anthony            6    2      78  
          7.   Anthony            6    3      89  
          8.   Anthony            6    4      12

        Comment

        Working...
        X