Diff for "FAQ/restwb" - CBU statistics Wiki
location: Diff for "FAQ/restwb"
Differences between revisions 10 and 11
Revision 10 as of 2010-09-29 12:59:33
Size: 2552
Editor: PeterWatson
Comment:
Revision 11 as of 2012-02-29 17:38:12
Size: 2890
Editor: PeterWatson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:

To add id number (e.g. for performing Tukey's HSD with UNIANOVA) you need to use the syntax below. In this example id number is placed in the column called id assuming there are 6 subjects (vary depending on the number of subjects).

{{{
compute idd=$casenum.
EXECUTE.
COMPUTE id=MOD(idd,6).
EXECUTE.
if (id=0) id=6.
exe.
}}}

The VARSTOCASES and CASESTOVARS commands

The below can also be performed using the [:FAQ/mixedR: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.

Use the /KEEP or /DROP subcommands to specify which variables (not created by the restructuring) are to be saved into the new file. The default is to keep all the variables in the original data file ie drop none.

To add id number (e.g. for performing Tukey's HSD with UNIANOVA) you need to use the syntax below. In this example id number is placed in the column called id assuming there are 6 subjects (vary depending on the number of subjects).

compute idd=$casenum.
EXECUTE.
COMPUTE id=MOD(idd,6).
EXECUTE.
if (id=0) id=6.
exe.

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

DATA LIST LIST/sub score.
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 sub = LAG(sub) num = LAG(num)+1.
LIST.  
                                                                   
SORT CASES BY sub num.             
CASESTOVARS                          
 /ID = sub                           
 /INDEX = num
 /AUTOFIX=NO.                                      
LIST.                                

By default all variables are saved into the new file. The /DROP subcommand may be used to remove variables which are not required after restructuring. There is no /KEEP subcommand available for CASESTOVARS. You may need to average over nuisance factors prior to using CASESTOVARS using the [:FAQ/aggregate: AGGREGATE] command.

NB: The CASESTOVARS command can omit reformatting columns with a large number of missing values or columns which immediately follow a column or columns with a lot of missing values. The AUTOFIX subcommand used above corrects this and produces reformatting of all columns including those omitted due to containing large numbers of missing values or immediately preceding columns with large numbers of missing values.

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