Announcement

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

  • reshape data to panel

    Dear,

    I have a dataset that I want to transfer to panel.
    My time variables (Year Month) are in two different columns, my ID variable is on the top as a row. I want to create one variable for ID that includes all countries (e.g., CHN ARG FRA).

    My dataset looks like the following and I do not know how to transfer it to a panel.

    Code:
    clear
    input int(Year Month) double(CHN ARG FRA)
    2007 12        .        .        .
    2008  1  29.2365 486.3999    11.77
    2008  2 54.63599 486.3999    11.31
    2008  3       83      581       13
    2008  4     61.5      569      8.5
    2008  5     43.5      589      6.5
    2008  6       67      589      8.5
    2008  7     69.5      589       10
    2008  8     59.5      589       11
    2008  9       78      589     12.5
    2008 10       92  2350.36       30
    2008 11    164.5  3945.34       41
    2008 12      217 4245.867       56
    2009  1      192  3527.81       56
    2009  2    219.5  2833.31       66
    2009  3      217  3730.81       79
    2009  4      142  3319.31       40
    2009  5     99.5   2857.1       33
    2009  6     74.5  1902.65       33
    2009  7       82  2164.71     32.5
    2009  8       69  1683.93       19
    2009  9       74  1302.64     16.5
    2009 10       63  1007.15   15.011
    2009 11       78   998.99 16.50499
    2009 12       70 955.7598 17.49899
    2010  1       64  1010.67 30.94899
    2010  2       82 1064.398 54.85599
    2010  3     61.5 1004.263   27.946
    2010  4     57.5 821.2368 44.86699
    2010  5       69      936    60.73
    end
    Thank you for your time.

  • #2
    Code:
    rename (CHN ARG FRA) value=
    gen int mdate = ym(Year, Month)
    format mdate %tm
    drop Year Month
    reshape long value, i(mdate) j(country) string
    You did not say what the numbers in the CHN, ARG, and FRA variables represent. So I gave the variable that was created to hold them the neutral name "value." You probably should give it a more descriptive name like "imports" or "GDP" or whatever it actually is.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      rename (CHN ARG FRA) value=
      gen int mdate = ym(Year, Month)
      format mdate %tm
      drop Year Month
      reshape long value, i(mdate) j(country) string
      You did not say what the numbers in the CHN, ARG, and FRA variables represent. So I gave the variable that was created to hold them the neutral name "value." You probably should give it a more descriptive name like "imports" or "GDP" or whatever it actually is.
      Thank you Clyde for your help. The code woks perfectly fine. Apologies for not reporting what these values are. They are cds values for countries.

      Best

      Comment

      Working...
      X