Announcement

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

  • Make panel data

    Hello Statalist!


    I want to make panel data from this:

    ID roa2009 roa2010 roa2011 roa2012 bis2009 bis2010 bis2011 bis2012 ....


    Can I make this data to panel data like this?

    ID time roa bis
    1 2009 ... ...
    1 2010 ... ...
    1 2011 ... ...
    1 2012 ... ...
    2 2009 ... ...
    2 2010 ... ...
    2 2011 ... ...
    2 2012 ... ...

    Thanks in advance. (I tried to google it, but no answers)


  • #2
    You're going to do a reshape long.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte id float(roa2009 roa2010 roa2011 roa2012) int(bis2009 bis2010 bis2011) byte bis2012
    1 .06 .16 .19 .05  94 107 103 73
    2 .23 .05 .19 .14  94  44 117 82
    3 .24 .05 .06 .09  30  79 103 22
    4 .17 .06 .07 .17 109  23  47 47
    5 .12 .08 .13 .17  49 106 101 90
    end
    Code:
    . list, noobs
    
      +------------------------------------------------------------------------------------+
      | id   roa2009   roa2010   roa2011   roa2012   bis2009   bis2010   bis2011   bis2012 |
      |------------------------------------------------------------------------------------|
      |  1       .06       .16       .19       .05        94       107       103        73 |
      |  2       .23       .05       .19       .14        94        44       117        82 |
      |  3       .24       .05       .06       .09        30        79       103        22 |
      |  4       .17       .06       .07       .17       109        23        47        47 |
      |  5       .12       .08       .13       .17        49       106       101        90 |
      +------------------------------------------------------------------------------------+
    
    reshape long roa bis, i(id) j(year)
    
    . list, sepby(id) noobs
    
      +-----------------------+
      | id   year   roa   bis |
      |-----------------------|
      |  1   2009   .06    94 |
      |  1   2010   .16   107 |
      |  1   2011   .19   103 |
      |  1   2012   .05    73 |
      |-----------------------|
      |  2   2009   .23    94 |
      |  2   2010   .05    44 |
      |  2   2011   .19   117 |
      |  2   2012   .14    82 |
      |-----------------------|
      |  3   2009   .24    30 |
      |  3   2010   .05    79 |
      |  3   2011   .06   103 |
      |  3   2012   .09    22 |
      |-----------------------|
      |  4   2009   .17   109 |
      |  4   2010   .06    23 |
      |  4   2011   .07    47 |
      |  4   2012   .17    47 |
      |-----------------------|
      |  5   2009   .12    49 |
      |  5   2010   .08   106 |
      |  5   2011   .13   101 |
      |  5   2012   .17    90 |
      +-----------------------+

    Comment


    • #3
      Thank you very much, DAVE!!!

      Comment

      Working...
      X