Announcement

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

  • Reshape from wide to long

    Hello Dear Experts,

    hope you are all fine. My problem is simple, just I want to reshape from wide to long data set. The code has been used " reshape long yr, i(id) j(year). But it produces the following result.

    (note: j = 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019)
    variable id does not uniquely identify the observations
    Your data are currently wide. You are performing a reshape long. You specified i(id) and j(year). In the current wide
    form, variable id should uniquely identify the observations. Remember this picture:

    long wide
    +---------------+ +------------------+
    | i j a b | | i a1 a2 b1 b2 |
    |---------------| <--- reshape ---> |------------------|
    | 1 1 1 2 | | 1 1 3 2 4 |
    | 1 2 3 4 | | 2 5 7 6 8 |
    | 2 1 5 6 | +------------------+
    | 2 2 7 8 |
    +---------------+
    Type reshape error for a list of the problem observations.

    Here, I need to change from wide to long. In this case, which the command should I use for the following data? Thanks for your cooperation.



    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float id str48 A double(yr2010 yr2011 yr2012 yr2013 yr2014 yr2015 yr2016 yr2017 yr2018 yr2019)
    1 "Australia" 9.33 18.82 16.09 17.32 12.56 14.1 19.88 19.56 17 18.8
    2 "Austria" 10.14 15.95 11 10.44 10.04 9.67 5.72 6.33 9.86 9.9
    3 "Belgium" 13.23 8.39 8.92 15.41 12.32 17.24 15.6 18.26 15.67 10.5
    4 "Bulgaria" 1 1 0 0 1.5 .5 .33 .22 .5 0
    5 "Canada" 13.61 12.08 24.67 28.53 23.75 27.6 27.46 36.16 35.51 37.43
    6 "China including Hong Kong" 1306.56 1429.4 1795.73 2202.71 2827.12 3778.9 4687.26 5158.88 4595.01 3975
    7 "Croatia" 1 .67 .17 0 0 0 2.16 0 0 0
    8 "Cyprus" 0 1.8 0 0 0 1 0 0 0 0
    9 "Czechia" 7.64 4.46 7.32 5 4.33 2.66 1.53 5.4 4.67 9.59
    10 "Denmark" .31 4.99 3.84 6.94 8.93 5.83 7.27 5.67 5.63 7.08
    11 "Estonia" .25 0 .25 0 3 0 1 0 0 0
    12 "European Union - 27 countries (from 2020)" 306.15 322.66 338.56 316.25 329.65 350.03 320.89 298.52 298.43 295.32
    13 "Finland" 14.54 7.79 11.73 13.09 15.35 17.14 16.19 17.83 16.1 16.33
    14 "France" 49.03 37.42 53.48 40.93 72.48 42.08 38.39 37.59 36.19 38.78
    15 "Germany (until 1990 former territory of the FRG)" 90.73 109.1 90.56 85.84 82.99 87.46 80.54 68.16 77.68 85.7
    16 "Greece" 1.29 0 0 0 .5 1.5 1 1.75 0 0
    17 "Hungary" 6.32 4.57 3.4 1.25 2.92 2.33 3.16 1 2 1
    18 "Ireland" 2.09 4.08 1.4 2.46 2.67 1.65 5.04 4.08 1.75 7
    19 "Italy" 28.7 28.41 33.59 27.02 18.55 20.61 27.45 26.85 21.27 31.44
    20 "Japan" 713.17 662.97 610.6 602.29 488.47 559.36 514.23 579.95 638.14 508.86
    21 "Latvia" 1.5 0 2.33 4 .08 2.3 1 1 0 0
    22 "Lithuania" 2 1.5 1.14 1 0 0 0 0 0 1
    23 "Luxembourg" 1.8 1.67 2.87 3.53 6.6 2.57 2.5 5.61 2.33 1
    --more--


  • #2
    Your data extract is not useful because in this data, id does in fact uniquely identify an observation, and so your reshape command succeeds.

    You may want to check for duplicates in id; see
    Code:
    help duplicates
    If you are not expecting id to be duplicated, you may want to figure out why some id's are in fact duplicates in your data and fix that. Use duplicates tag or duplicates report to diagnose.

    Comment


    • #3
      Now, it is working, Thanks for your advice

      Comment

      Working...
      X