Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Reshape


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Reshape
Date   Wed, 15 Sep 2010 11:06:06 +0200

<> 


You may want to use -egen, group()- beforehand:


*************
clear*

inp byte id int(year x) byte(county  /* 
*/ vars:mylabel varlabel:mylabel2)  /* 
*/ byte id2, auto 
 1   1979       790  1 suic  suic      1 
 1   1980     4823  1 suic  suic      2 
 1   1981     2560  1 suic  suic      3 
 1   1982     1890  1 suic  suic      4 
 1   1983     1137  1 suic  suic      5 
 1   1984     2540  1 suic  suic      6 
 1   1985     3205  1 suic  suic      7 
 1   1986     5770  1 suic  suic      8 
 1   1987     4748  1 suic  suic      9 
 1   1988     5467  1 suic  suic     10 
 1   1989     7141  1 suic  suic     11 
 1   1990     3053  1 suic  suic     12 
 1   1991     8661  1 suic  suic     13 
 1   1992     3342  1 suic  suic     14 
 1   1993       826  1 suic  suic     15 
 1   1994     3934  1 suic  suic     16 
 1   1995     4784  1 suic  suic     17 
 1   1996     7504  1 suic  suic     18 
 1   1997     2447  1 suic  suic     19 
 1   1998     4397  1 suic  suic     20 
 1   1999     4915  1 suic  suic     21 
 1   2000     6089  1 suic  suic     22 
 1   2001     6756  1 suic  suic     23 
 1   2002     5557  1 suic  suic     24 
 1   2003     6346  1 suic  suic     25 
 1   2004     2588  1 suic  suic     26 
 1   2005     7878  1 suic  suic     27 
 1   2006     4150  1 suic  suic     28 
 2   1979       120  1 west  west      1 
 2   1980       120  1 west  west      2 
 2   1981       121  1 west  west      3 
 2   1982       122  1 west  west      4 
 2   1983       121  1 west  west      5 
 2   1984       120  1 west  west      6 
 2   1985       120  1 west  west      7 
end

list, noo sepby(id)

egen newid=group(id id2)
reshape wide x, i(newid) j(varlabel)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Elena Quercioli
Gesendet: Mittwoch, 15. September 2010 10:56
An: [email protected]
Betreff: st: Reshape

I have a dataset with multiple identifiers(id2 and id). Here is an
example of it:
 
+---------------------------------------------------------------------------
-
       |  id   year          x   county        vars   varlabel    id2 |
 
|---------------------------------------------------------------------------
|
    1. |   1   1979       790         1       suic        suic      1 |
    2. |   1   1980     4.823         1       suic        suic      2 |
    3. |   1   1981     2.560         1       suic        suic      3 |
    4. |   1   1982     1.890         1       suic        suic      4 |
    5. |   1   1983     1.137         1       suic        suic      5 |
    6. |   1   1984     2.540         1       suic        suic      6 |
    7. |   1   1985     3.205         1       suic        suic      7 |
    8. |   1   1986     5.770         1       suic        suic      8 |
    9. |   1   1987     4.748         1       suic        suic      9 |
   10. |   1   1988     5.467         1       suic        suic     10 |
   11. |   1   1989     7.141         1       suic        suic     11 |
   12. |   1   1990     3.053         1       suic        suic     12 |
   13. |   1   1991     8.661         1       suic        suic     13 |
   14. |   1   1992     3.342         1       suic        suic     14 |
   15. |   1   1993       826         1       suic        suic     15 |
   16. |   1   1994     3.934         1       suic        suic     16 |
   17. |   1   1995     4.784         1       suic        suic     17 |
   18. |   1   1996     7.504         1       suic        suic     18 |
   19. |   1   1997     2.447         1       suic        suic     19 |
   20. |   1   1998     4.397         1       suic        suic     20 |
   21. |   1   1999     4.915         1       suic        suic     21 |
   22. |   1   2000     6.089         1       suic        suic     22 |
   23. |   1   2001     6.756         1       suic        suic     23 |
   24. |   1   2002     5.557         1       suic        suic     24 |
   25. |   1   2003     6.346         1       suic        suic     25 |
   26. |   1   2004     2.588         1       suic        suic     26 |
   27. |   1   2005     7.878         1       suic        suic     27 |
   28. |   1   2006     4.150         1       suic        suic     28 |
 
|---------------------------------------------------------------------------
-|
   29. |   2   1979       120         1       west        west      1 |
   30. |   2   1980       120         1       west        west      2 |
   31. |   2   1981       121         1       west        west      3 |
   32. |   2   1982       122         1       west        west      4 |
   33. |   2   1983       121         1       west        west      5 |
   34. |   2   1984       120         1       west        west      6 |
   35. |   2   1985       120         1       west        west      7 |


I want to reshape the variable x wide. I typed the command

reshape wide x, i(id2) j(varlabel)

but there are 5 distinct values for j = 1,2,3,4,5 associated with each
value of id2 in my dataset. How do I proceed to have this dataset
reshaped with x being wide and the j variables unstacked. My final
dataset should look like this

ID | Year| Suic|West|Central|Pop!Mount|
1    1979  ....     ...      ...        ...    ...


.      .
.      .
.      .
1   2006

2  1979
.
.
.
2  2006

...   ...      ....     ....      ...      ...    ...

28 1979 Suic| West|Central|Pop|Mount

Thank you for all the help you can give me on this. Elena
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index