Announcement

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

  • Problem generating panel data set from ‘long’ data

    Hello everyone,

    I have a panel dataset of firms over time that I am attempting to convert from ‘long’ to ‘wide’ (perhaps these terms are incorrect and I apologise if so but the code below should convey the idea).

    The data has multiple observations of the same firm per year with fiscal information at every year (giving over 4 million observations). I would like to transform this into a single observation of one firm with a new variable for fiscal information at every year (hope this makes sense!).

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float firmid str4 closingyear double fixedassets
      1092 "1989"     60274810
      1092 "1990"     77463935
     87397 "1990"     40294909
      1092 "1991"     66114814
     25177 "1991"    991958993
     87397 "1991"     43335100
    end
    Referring to the table, I would need multiple fixed assets variables across years, like fixedassets1998, fixedassets1999 etc. I imagine this would require running a macro generating new variables but I have not successfully been able to do this.

    I would appreciate any and all advice on this issue – do let me know if I have missed some important piece of information.
    Thank you for your help and time!

    Ana

  • #2
    first, I don't know why you want to do this; if you want to use any of Stata's panel data estimators, you want the data in long form (as it is now); however, it can be done:
    Code:
    reshape wide fixedassets, i(firmid) j(closingyear) string
    which gives the following result for your example (thank you for using -dataex-):
    Code:
    . li, clean noo
    
        firmid   fix~1989   fix~1990   fixe~1991  
          1092   60274810   77463935    66114814  
         25177          .          .   9.920e+08  
         87397          .   40294909    43335100
    note that I have not increase the display format but you can easily do that:
    Code:
    help format

    Comment


    • #3
      Thank you for your reply Rich! It wanted it to be able to merge with a couple of other datasets that came in this way, but will reshape it back to long after merging if you say it is better. Thanks again

      Comment

      Working...
      X