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
69
70
71
72
73
74
75
76
* (Q) How can I generate a single table containing:
	the crosstab results, Pearson Chi-square and Phi.
* (A) Raynald Levesque 2004/12/18 http://www.spsstools.net .

* Define a macro to do the job.

*////////////////////////.
DEFINE !ctab(var1=!CHAREND('/') /var2=!CHAREND('/') /title=!TOKENS(1))

OMS  
    /SELECT  TABLES
    /IF COMMANDS=['Crosstabs']   SUBTYPES=['Crosstabulation']
    /DESTINATION FORMAT =SAV NUMBERED='TableNb'  OUTFILE='c:\\temp\\crosstabs1.sav'
    /TAG="OMS1".
OMS  
    /SELECT  TABLES
    /IF COMMANDS=['Crosstabs']    LABELS=['Chi-Square Tests']
    /DESTINATION FORMAT =SAV NUMBERED='TableNb'  OUTFILE='c:\\temp\\crosstabs2.sav'
    /TAG="OMS2".
OMS  
    /SELECT  TABLES
    /IF COMMANDS=['Crosstabs']    LABELS=['Symmetric Measures']
    /DESTINATION FORMAT =SAV NUMBERED='TableNb'  OUTFILE='c:\\temp\\crosstabs3.sav'
    /TAG="OMS3".

CROSSTABS
  /TABLES=!var1  BY !var2 
  /FORMAT= AVALUE TABLES
  /STATISTIC=CHISQ PHI
  /CELLS= COUNT
  /COUNT ROUND CELL .

OMSEND.
GET FILE='c:\\temp\\crosstabs1.sav' .
SAVE OUTFILE='c:\\temp\\crosstabs1.sav' /DROP= Command_ Subtype_ Label_.

GET FILE='c:\\temp\\crosstabs2.sav'  .
SELECT IF Var1="Pearson Chi-Square".
RENAME VARIABLES (Value=Chi2Value).
SAVE OUTFILE='c:\\temp\\crosstabs2.sav' /DROP= Command_ Subtype_ Label_ Var1 .

GET FILE='c:\\temp\\crosstabs3.sav'  .
SELECT IF Var2="Phi".
RENAME VARIABLES (Value=PhiValue).
SAVE OUTFILE='c:\\temp\\crosstabs3.sav'  /DROP= Command_ Subtype_ Label_ Var1 Var2.

MATCH FILES FILE='c:\\temp\\crosstabs1.sav'  
    /TABLE='c:\\temp\\crosstabs2.sav'
    /TABLE='c:\\temp\\crosstabs3.sav'
    /BY=TableNb
    /DROP=Var3.
VARIABLE LABELS PhiValue "PhiValue" df "Chi2df" Chi2Value "Chi2Value" .
SUMMARIZE
  /TABLES=Var1 TO Chi2Value df Asymp.Sig.2sided PhiValue Approx.Sig
  /FORMAT=VALIDLIST NOCASENUM TOTAL
  /TITLE=!title
  /MISSING=VARIABLE
  /CELLS=NONE .

!ENDDEFINE.
*////////////////////////.


** Example 1 **.

GET FILE='c:\\program files\\spss\\employee data.sav'.
SET MPRINT=YES.
!ctab var1=gender minority /var2=jobcat /title='Summary of Crosstabs (gender and minority * jobcat)'.
SET MPRINT=NO.

** Example 2 **.

GET FILE='c:\\program files\\spss\\employee data.sav'.
SET MPRINT=YES.
!ctab var1=jobcat /var2=gender minority /title='Summary of Crosstabs (jobcat * gender and minority)'.
SET MPRINT=NO.