Get statistics for grouping of variables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | *(Q) I'd like to have statistics per grouping of variables. The desired layout is shown below and the variables are numeric. N Mean Std. Dev var1 var2 var3 Overall (var1 to var3) var4 var5 Overall (var4 to var5) etc.... *(A) Raynald Levesque 2003/09/14 * Web site: http://pages.infinit.net/rlevesqu/index.htm . SET MPRINT=no. NEW FILE. INPUT PROGRAM. LOOP cnt=1 TO 500. - VECTOR var(5). - LOOP #idx=1 TO 5. - COMPUTE var(#idx)=UNIFORM(10). - END LOOP. - END CASE. END LOOP. END FILE. END INPUT PROGRAM. LOOP varnum=1 TO 5. - COMPUTE varval=var(varnum). - XSAVE OUTFILE='c:\\temp\\temp.sav' /KEEP=varnum varval. END LOOP. EXECUTE. GET FILE='c:\\temp\\temp.sav'. * If you have CTABLES then a single command is required to produce the required result. CTABLES /VLABELS VARIABLES=varval varnum DISPLAY=DEFAULT /TABLE varnum [C] BY varval [MEAN, STDDEV] /CATEGORIES VARIABLES=varnum [1,2,3, SUBTOTAL='Var 1 to 3' ,4,5,SUBTOTAL='Var 4 & 5'] EMPTY=EXCLUDE TOTAL=yes. * If you do not have CTABLES then. SORT CASES BY varnum. AGGREGATE OUTFILE='c:\\temp\\agg by var.sav' /PRESORTED /BREAK=varnum /mean=MEAN(varval) /sd=SD(varval). RECODE varnum (1,2,3=3.5) (4,5=5.5) INTO groupnum . AGGREGATE OUTFILE=* /PRESORTED /BREAK=groupnum /mean=MEAN(varval) /sd=SD(varval). ADD FILES FILE=* /RENAME (groupnum=varnum) /FILE='c:\\temp\\agg by var.sav'. SORT CASES BY varnum. VALUE LABELS varnum 1 "var 1" 2 "var 2" 3 "var 3" 4 "var 4" 5 "var 5" 3.5 "var 1 to var3" 5.5 "var 4 and 5". * Results are in the data editor. |
Related pages
...