Announcement

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

  • Reorganize data from long (panel) form to id-separated variables?

    Dear all,
    I need to reorganize my dataset. I have an unbalanced panel dataset in long form for 100 individuals over 70 years (monthly data). I would need to separate every time-series by id. Now I have the following (see a piece of the dataset here proves_mgarch.dta):
    I have I need
    date id var1 var2 var3
    1950m1 1 value value value
    1950m2 1 value value value
    .
    .
    1951m1 2 value value value
    1951m2 2 value value value
    .
    .
    1993m1 5 value value value
    1993m2 5 value value value
    date var1_id1 var2_id1 var3_id1 var1_id2 var2_id2 ....
    1950m1 value value value value value
    1950m2 value value value . .
    .
    .
    1951m1 value value value value value

    I tried using
    Code:
    separate varname, by (id)
    and, then,
    Code:
    bysort date: gen varname_sum=sum(varname)
    but it does not produces what I need and it is tedious. How could I efficiently transform it?

    I need it because I am still struggling to find a way to regress a panel GARCH with Stata (see this post). After going through a RATS code for it (without having that software), I suspect that, authors are programming a multivariate GARCH model, entering every panel-id variable as dependent or independent in the mean and conditional variance equations. They specify the characteristics of the conditional covariance equation too. Therefore, I will try what George Ford suggested me in the cited post(mgarch).

    Thank you for your help.

  • #2
    Code:
    rename (var1 var2 var3) =_id
    reshape wide var1_id var2_id var3_id, i(date) j(id)
    Note: if the data set is very large, this will take a long time. Be patient.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Dear Clyde Schechter,
      Thank you so much! Your code does exactly what I needed.
      Thank you for your advise on showing data examples. I have now installed dataex for the future.

      Comment

      Working...
      X