Announcement

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

  • Reshape with different items and years

    Dear all,

    I would like to undertake a complex reshape and all the various commands I tried, did not work. I am sure there is already a solution to my problem in this forum, however, all the posts, I've read, did not help to solve my problem. Here is an example of the data that I have and what I would like to achieve with the reshape:

    Actual data:
    i j y2012 y2013
    1 1 10 50
    1 2 20 60
    2 1 30 70
    2 2 40 80

    New data strcuture after reshape:
    i y j1 j2
    1 2012 10 20
    1 2013 50 60
    2 2012 30 40
    2 2013 70 80

    What is even the description for such a reshape? I even had problems to enter the correct search terms.

    Thank you very much in advance!

  • #2
    Two reshape commands are required for this.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(i j y2012 y2013)
    1 1 10 50
    1 2 20 60
    2 1 30 70
    2 2 40 80
    end
    reshape long y, i(i j) j(year)
    reshape wide y, i(i year) j(j)
    rename (y#) (j#)
    list, clean
    Code:
    . list, clean
    
           i   year   j1   j2  
      1.   1   2012   10   20  
      2.   1   2013   50   60  
      3.   2   2012   30   40  
      4.   2   2013   70   80
    For further explanations, see
    Code:
    help reshape
    help rename group

    Comment


    • #3
      Dear William,
      thank you very very much! Somehow, I could not think about the possibility to combine a long and wide reshape. I'll edit the title so that other people might having the same problem can find the post more easily.
      Edit: Unfortunately, I can't edit the initial post anymore.

      Comment

      Working...
      X