Diff for "FAQ/restwb" - CBU statistics Wiki
location: Diff for "FAQ/restwb"
Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2010-01-26 16:10:49
Size: 618
Editor: PeterWatson
Comment:
Revision 3 as of 2010-01-26 16:38:09
Size: 1551
Editor: PeterWatson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
= The VARSTOCASES command = = The VARSTOCASES and CASESTOVARS commands =
Line 4: Line 4:
The below can also be performed using the RESTRUCTURE command under the DATA menu in SPSS. For the example below we wish to stack columns x and y to make a single column called time. This is particularly useful for converting data from a format suitable for repeated measures to one suitable for multilevel modelling in SPSS. The below can also be performed using the RESTRUCTURE command under the DATA menu in SPSS. For the example below we wish to stack columns x and y to make a single column called time. This is particularly useful for converting data from a format suitable for repeated measures to one suitable for multilevel modelling in SPSS. Notice we need to sort the cases before reformatting the data.
Line 10: Line 10:
001 23 45
001 39 41
002 33 11
002 87 57
002 99 36
002 23 45
003 39 41
004 33 11
005 87 57
006 99 36
Line 23: Line 23:

To do the reverse operation we need to use the CASESTOVARS command in conjunction with SORT CASES as below:

{{{
DATA LIST LIST/week ratio.
BEGIN DATA
1 34
1 56
2 23
2 45
3 39
3 41
4 33
4 11
5 87
5 57
6 99
6 36
END DATA.
LIST.

COMPUTE num=1.
IF week = LAG(week) num = LAG(num)+1.
LIST.
                                                                   
SORT CASES BY week num.
CASESTOVARS
 /ID = week
 /INDEX = num.
LIST.
}}}

The VARSTOCASES and CASESTOVARS commands

The below can also be performed using the RESTRUCTURE command under the DATA menu in SPSS. For the example below we wish to stack columns x and y to make a single column called time. This is particularly useful for converting data from a format suitable for repeated measures to one suitable for multilevel modelling in SPSS. Notice we need to sort the cases before reformatting the data.

DATA LIST FREE / idno x y . 
BEGIN DATA 
001 34 56 
002 23 45 
003 39 41 
004 33 11 
005 87 57 
006 99 36 
END DATA. 

SORT CASES BY IDNO.
VARSTOCASES 
 /MAKE time FROM x y
 /INDEX = newfact "new var label" (time) 
 /KEEP = idno.

To do the reverse operation we need to use the CASESTOVARS command in conjunction with SORT CASES as below:

DATA LIST LIST/week ratio.
BEGIN DATA                
1 34                    
1 56                    
2 23                    
2 45                    
3 39                    
3 41                    
4 33                   
4 11                    
5 87               
5 57
6 99
6 36    
END DATA.                 
LIST.                     

COMPUTE num=1.                       
IF week = LAG(week) num = LAG(num)+1.
LIST.  
                                                                   
SORT CASES BY week num.             
CASESTOVARS                          
 /ID = week                           
 /INDEX = num.                                      
LIST.                                

None: FAQ/restwb (last edited 2015-08-11 08:38:08 by PeterWatson)