Announcement

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

  • Reshape panel data into normal data

    Hi,

    I have the following data:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year byte month float(pf1 pf2 pf3 pf4 pf5)
    1994  1  .7317769 . . . .
    1994  2 -1.438106 . . . .
    1994  3  3.289205 . . . .
    1994  4 1.0543115 . . . .
    1994  5  2.646325 . . . .
    1994  6  2.441891 . . . .
    1994  7 2.3143687 . . . .
    1994  8 1.1576985 . . . .
    1994  9  .3261626 . . . .
    1994 10 .53481084 . . . .
    end
    format %ty year

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year byte month float(pf1 pf2 pf3 pf4 pf5)
    1994  1 .  1.9344295 . . .
    1994  2 . -1.3845674 . . .
    1994  3 .  .44359535 . . .
    1994  4 .  -.4544522 . . .
    1994  5 .  -.6438199 . . .
    1994  6 .  -.1969062 . . .
    1994  7 .  1.7479986 . . .
    1994  8 .   .5169064 . . .
    1994  9 .  -2.756419 . . .
    1994 10 .  1.3164024 . . .
    1994 11 .  2.2525797 . . .
    end
    format %ty year

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year byte month float(pf1 pf2 pf3 pf4 pf5)
    1994  1 . .  .18590222 . .
    1994  2 . .  -.3532267 . .
    1994  3 . .  -.2996352 . .
    1994  4 . .  -.7759086 . .
    1994  5 . .  -.8043643 . .
    1994  6 . . -1.2875673 . .
    1994  7 . .  1.8588865 . .
    1994  8 . . -.33721325 . .
    1994  9 . .   2.477706 . .
    1994 10 . . -.54519296 . .
    1994 11 . .   1.580461 . .
    end
    format %ty year
    These examples are all under each other in the same dataset. Is there an easy way to put them next to each other, so that the data from for example 01/1994 of the 5 portfolios is next to each other instead of under each other?

    Thanks

  • #2
    Using your example data, you may find the following starts you in a useful direction.
    Code:
    . collapse (firstnm) pf1-pf5, by(year month)
    
    . list, clean noobs
    
        year   month         pf1         pf2         pf3   pf4   pf5  
        1994       1    .7317769     1.93443    .1859022     .     .  
        1994       2   -1.438106   -1.384567   -.3532267     .     .  
        1994       3    3.289205    .4435953   -.2996352     .     .  
        1994       4    1.054312   -.4544522   -.7759086     .     .  
        1994       5    2.646325   -.6438199   -.8043643     .     .  
        1994       6    2.441891   -.1969062   -1.287567     .     .  
        1994       7    2.314369    1.747999    1.858886     .     .  
        1994       8    1.157699    .5169064   -.3372132     .     .  
        1994       9    .3261626   -2.756419    2.477706     .     .  
        1994      10    .5348108    1.316402    -.545193     .     .  
        1994      11           .     2.25258    1.580461     .     .

    Comment


    • #3
      Thank you very much, it worked

      Comment

      Working...
      X