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: Reshape problem
From 
 
Johan Hellström <[email protected]> 
To 
 
" ([email protected])" <[email protected]> 
Subject 
 
st: Reshape problem 
Date 
 
Thu, 3 Nov 2011 12:26:16 +0100 
Dear all,
I have a dataset that is in long form (containing a lot of variables), but some variables (v1-v34 in the example below) are measured at a different level and stored in wide form. That is, it is the same variable for different sub-units.  These also contain a lot of empty cells. Does anyone know a way to create a new panel where all "wide form"-variables (V1-V34) is coverted into long form (and the values stored in a 'New-variable'). The example below gives an indication of how my dataset looks like. For each 'Unit' it is about 10-25 measurement points over time (unbalanced panel). 
Old panel:
----------------------------------------------------------------------------------------------------------------------------------------------------
Unit	Time	x1	V1	V2	V3	V4	...	v34
1	1	12.3	.	67	26	48	...	23
1	2	26.6	45	34	12	.	...	64
...
2	1	84.0	83	.	.	23	...	87
2	2	23.5	.	.	91	82	...	98
...
----------------------------------------------------------------------------------------------------------------------------------------------------
New panel:
-----------------------------------------------------------------------------------------------------
Unit	Sub-unit	Time	x1	New-variable
1	1	1	12.3	.
1	2	1	12.3	67
1	3	1	12.3	26
1	4	1	12.3	48
...
1	34	1	12.3	23
1	1	2	26.6	45
1	2	2	26.6	34
1	3	2	26.6	12
1	4	2	26.6	.
...
2	1	1	84.0	83
2	2	1	84.0	.
2	3	1	84.0	.
2	4	1	84.0	23
...
2	34	1	84.0	87
2	1	2	23.5	83
Etc.
------------------------------------------------------------------------------------------------------	
Thanks,
Johan Hellstrom
*
*   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/