Announcement

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

  • Reshape

    Hello Members!

    I have the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 countryname float(cal_year1996 cal_year1998 cal_year2000 cal_year2002 cal_year2003)
    "Australia"       1.8 1.62 1.73 1.66 1.77
    "Austria"        1.73  1.8 1.85 1.88 1.93
    "Belgium"        1.71 1.77 1.66 1.92 1.87
    "Brazil"         -.14  -.2  .04 -.03  .08
    "Canada"         1.74 1.88 1.85 1.86 1.92
    "Chile"          1.34  1.1 1.01 1.08  1.1
    "China"          -.35  -.2 -.16 -.12 -.15
    "Colombia"       -.46 -.33  -.4 -.49 -.22
    "Denmark"        1.76 1.91  1.9 2.02 2.09
    "Finland"        1.72 1.95 2.03  2.1 2.19
    "France"         1.25 1.45 1.64 1.54 1.65
    "Germany"        1.72 1.81  1.8 1.66 1.36
    "Greece"          .84  .74  .59  .78   .7
    "Hong Kong"      1.04  1.1 1.26 1.33 1.59
    "Hungary"         .86  .94    1  .99  .83
    "India"          -.11 -.11 -.19 -.19 -.14
    "Indonesia"      -.71 -.69 -.37 -.55  -.6
    "Ireland"        1.67 1.74 1.59 1.57  1.5
    "Italy"           .84  .83  .72  .75  .74
    "Japan"           .91 1.02 1.14 1.02 1.16
    "Malaysia"        .54  .75  .99  .92 1.04
    "Mexico"          .23  .38  .28  .22  .13
    "Netherlands"    1.94    2 1.98 1.93 1.95
    "New Zealand"    1.77 1.63 1.59 1.68 1.76
    "Norway"         1.95 1.91 1.82 1.83 1.83
    "Pakistan"       -.62 -.49 -.49 -.55 -.59
    "Peru"            .03  .07 -.18 -.39 -.59
    "Philippines"    -.31 -.04  -.2 -.18 -.15
    "Poland"          .68  .62  .57  .45  .51
    "Portugal"       1.27 1.11  .97 1.15 1.11
    "Singapore"      1.99 2.07 2.11 1.79 1.93
    "South Africa"   1.02  .62  .65  .61   .6
    "South Korea"     .47  .29  .61   .8  .79
    "Spain"          1.62  1.6 1.69 1.79 1.82
    "Sweden"         1.92 1.88 1.88 1.96 2.02
    "Switzerland"    1.76 1.91 1.96 1.94 1.75
    "Taiwan"          .55   .8   .7  .74  .92
    "Thailand"        .18  .04  .18  .26  .31
    "Türkiye"       -.08 -.31 -.02  .05  .03
    "United Kingdom" 1.88 1.86 1.77 1.78 1.75
    ""                  .    .    .    .    .
    end
    I want to reshape the data so that it becomes panel data. I need the data for all countries by calendar year.

    I am using the following code, but it says cal_year ambiguous observation-

    Code:
    reshape long @effectiveness, i(cal_year) j(countryname) string

  • #2
    This may help.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 countryname float(cal_year1996 cal_year1998 cal_year2000 cal_year2002 cal_year2003)
    "Australia"       1.8 1.62 1.73 1.66 1.77
    "Austria"        1.73  1.8 1.85 1.88 1.93
    "Belgium"        1.71 1.77 1.66 1.92 1.87
    "Brazil"         -.14  -.2  .04 -.03  .08
    "Canada"         1.74 1.88 1.85 1.86 1.92
    "Chile"          1.34  1.1 1.01 1.08  1.1
    "China"          -.35  -.2 -.16 -.12 -.15
    "Colombia"       -.46 -.33  -.4 -.49 -.22
    "Denmark"        1.76 1.91  1.9 2.02 2.09
    "Finland"        1.72 1.95 2.03  2.1 2.19
    "France"         1.25 1.45 1.64 1.54 1.65
    "Germany"        1.72 1.81  1.8 1.66 1.36
    "Greece"          .84  .74  .59  .78   .7
    "Hong Kong"      1.04  1.1 1.26 1.33 1.59
    "Hungary"         .86  .94    1  .99  .83
    "India"          -.11 -.11 -.19 -.19 -.14
    "Indonesia"      -.71 -.69 -.37 -.55  -.6
    "Ireland"        1.67 1.74 1.59 1.57  1.5
    "Italy"           .84  .83  .72  .75  .74
    "Japan"           .91 1.02 1.14 1.02 1.16
    "Malaysia"        .54  .75  .99  .92 1.04
    "Mexico"          .23  .38  .28  .22  .13
    "Netherlands"    1.94    2 1.98 1.93 1.95
    "New Zealand"    1.77 1.63 1.59 1.68 1.76
    "Norway"         1.95 1.91 1.82 1.83 1.83
    "Pakistan"       -.62 -.49 -.49 -.55 -.59
    "Peru"            .03  .07 -.18 -.39 -.59
    "Philippines"    -.31 -.04  -.2 -.18 -.15
    "Poland"          .68  .62  .57  .45  .51
    "Portugal"       1.27 1.11  .97 1.15 1.11
    "Singapore"      1.99 2.07 2.11 1.79 1.93
    "South Africa"   1.02  .62  .65  .61   .6
    "South Korea"     .47  .29  .61   .8  .79
    "Spain"          1.62  1.6 1.69 1.79 1.82
    "Sweden"         1.92 1.88 1.88 1.96 2.02
    "Switzerland"    1.76 1.91 1.96 1.94 1.75
    "Taiwan"          .55   .8   .7  .74  .92
    "Thailand"        .18  .04  .18  .26  .31
    "Türkiye"       -.08 -.31 -.02  .05  .03
    "United Kingdom" 1.88 1.86 1.77 1.78 1.75
    ""                  .    .    .    .    .
    end
    
    drop in L 
    
    reshape long cal_year, i(countryname) j(year)
    rename cal_year whatever 
    
    l in 1/20 
    
         +-----------------------------+
         | country~e   year   whatever |
         |-----------------------------|
      1. | Australia   1996        1.8 |
      2. | Australia   1998       1.62 |
      3. | Australia   2000       1.73 |
      4. | Australia   2002       1.66 |
      5. | Australia   2003       1.77 |
         |-----------------------------|
      6. |   Austria   1996       1.73 |
      7. |   Austria   1998        1.8 |
      8. |   Austria   2000       1.85 |
      9. |   Austria   2002       1.88 |
     10. |   Austria   2003       1.93 |
         |-----------------------------|
     11. |   Belgium   1996       1.71 |
     12. |   Belgium   1998       1.77 |
     13. |   Belgium   2000       1.66 |
     14. |   Belgium   2002       1.92 |
     15. |   Belgium   2003       1.87 |
         |-----------------------------|
     16. |    Brazil   1996       -.14 |
     17. |    Brazil   1998        -.2 |
     18. |    Brazil   2000        .04 |
     19. |    Brazil   2002       -.03 |
     20. |    Brazil   2003        .08 |
         +-----------------------------+
    Your identifier is the country name. The prefix cal_year doesn't serve well to indicate whatever the outcome is, so rename it appropriately. Perhaps it should be effectiveness.

    It is hard otherwise to see why effectiveness was mentioned at all; perhaps it is a suffix used in your dataset that we can't see.

    The data example you give and the code you give should always be consistent.

    Comment


    • #3
      Thank you, Nick.

      I have taken note regarding the data example.

      Comment


      • #4
        Thank you, Nick.

        I have taken note regarding the data example.

        Comment


        • #5
          Thank you, Nick.

          I have taken note regarding the data example.

          Comment

          Working...
          X