Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: AW: Reshape


From   Elena Quercioli <elena.liquorice@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: AW: Reshape
Date   Wed, 15 Sep 2010 13:39:24 +0200

I obtained this

newid	x1	x2	x3	x4	x5	id	year	county	vars	id2
1				790		        1	1979	 1	        suic	1
2				4.823		1	1980	 1	        suic	2
3				2.560		1	1981	 1	        suic	3
4				1.890		1	1982	 1	        suic	4
5				1.137		1	1983	 1	        suic	5
6				2.540		1	1984	 1	        suic	6
7				3.205		1	1985	 1 	        suic	7
8				5.770		1	1986	 1	        suic	8
9				4.748		1	1987	 1	        suic	9
10				5.467		1	1988	 1	        suic	10
11				7.141		1	1989	 1	        suic	11
12				3.053		1	1990	 1	        suic	12
13				8.661		1	1991	 1	        suic	13
14				3.342		1	1992	 1	        suic	14
15				826		        1	1993	 1	        suic	15
16				3.934		1	1994	 1	        suic	16
17				4.784		1	1995	 1	        suic	17
18				7.504		1	1996	 1	        suic	18
19				2.447		1	1997	 1	        suic	19
20				4.397		1	1998	 1	        suic	20
21				4.915		1	1999	 1	        suic	21
22				6.089		1	2000	 1	        suic	22
23				6.756		1	2001	 1	        suic	23
24				5.557		1	2002	 1	        suic	24
25				6.346		1	2003	 1	        suic	25
26				2.588		1	2004	 1	        suic	26
27				7.878		1	2005	 1	        suic	27
28				4.150		1	2006	 1	        suic	28
29					   120	2	1979	 1	        west	1
30					   120	2	1980	 1	        west	2

....

How do I, then, proceed to make the  x1,...x5  variables, the actual
columns of this grid?  Currently, they are arranged as a
one-column-at-a-time table. Clearly, in need of being compacted up.
Once this is done, I guess this would constitute a long format (i.e.
Each observation is a distinct County-Year pair) and not a wide
format, as I initially thought!


Thanks so much for your extremely helpful suggestions!


Elena


>> -----Ursprüngliche Nachricht-----
>> Von: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Elena Quercioli
>> Gesendet: Mittwoch, 15. September 2010 10:56
>> An: statalist@hsphsun2.harvard.edu
>> 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/
>>
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index