Announcement

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

  • Create panel data

    Hi, I have some troubles with this data set to transform it into standard panel form with observations over year for those countries. The dataset is in form of country and years as variables. Thank you so much.
    https://drive.google.com/file/d/1TRY...ew?usp=sharing

  • #2
    Thomas:
    as you are surely aware of, downloading files from unknown sources is risky.
    Please provide an excerpt/example of what's the matter with your data, abd/or see -help reshape- and -help xtset-.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Hi,
      Sorry about this. I have some issue with upload data to the forum. Let me just give example. The dataset in my hand has the form as follow
      country 2010 2011 2012 2013
      Korea 1 2 3 4
      China 5 6 7 8
      USA 9 10 11 12
      How can i transform it into standard panel data set such as:
      USA 9
      USA 10
      USA 11
      USA 12
      China 5
      Chian 6
      China 7
      China 8
      Thank you

      Comment


      • #4
        You're going to use reshape long. Since Stata won't allow variables that begin with a number, I renamed 2010 to y2010, 2011 to y2011, etc.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str5 country byte(y2010 y2011 y2012 y2013)
        "Korea" 1  2  3  4
        "China" 5  6  7  8
        "USA"   9 10 11 12
        end
        Code:
        reshape long y, i(country) j(year)
        
        . list, sepby(country) noobs
        
          +---------------------+
          | country   year    y |
          |---------------------|
          |   China   2010    5 |
          |   China   2011    6 |
          |   China   2012    7 |
          |   China   2013    8 |
          |---------------------|
          |   Korea   2010    1 |
          |   Korea   2011    2 |
          |   Korea   2012    3 |
          |   Korea   2013    4 |
          |---------------------|
          |     USA   2010    9 |
          |     USA   2011   10 |
          |     USA   2012   11 |
          |     USA   2013   12 |
          +---------------------+

        Comment


        • #5
          Hi David,
          your code worked like a charm, my grateful thank to you and Merry Christmas.

          Comment

          Working...
          X