Skip to content

15.7.1.1 Categorical Variables ​

An axis expression that names a categorical variable divides the data into cells according to the values of that variable. When all the variables named on TABLE are categorical, by default each cell displays the number of cases that it contains, so specifying a single variable yields a frequency table, much like the output of the FREQUENCIES command (see FREQUENCIES):

CTABLES /TABLE=ageGroup.
Count
Age group15 or younger0
16 to 251099
26 to 35967
36 to 451037
46 to 551175
56 to 651247
66 or older1474

Specifying a row and a column categorical variable yields a crosstabulation, much like the output of the CROSSTABS command (see CROSSTABS):

CTABLES /TABLE=ageGroup BY gender.
MaleFemale
S3a. GENDER:
CountCount
Age group15 or younger00
16 to 25594505
26 to 35476491
36 to 45489548
46 to 55526649
56 to 65516731
66 or older531943

The ‘>’ “nesting” operator nests multiple variables on a single axis, e.g.:

CTABLES /TABLE likelihoodOfBeingStoppedByPolice BY ageGroup > gender.
YesNo
86. In the past year, have you hosted a social event or party where alcohol was served to adults?
CountCount
Age group15 or youngerS3a. GENDER:Male00
Female00
16 to 25S3a. GENDER:Male208386
Female202303
26 to 35S3a. GENDER:Male225251
Female242249
36 to 45S3a. GENDER:Male223266
Female240307
46 to 55S3a. GENDER:Male201325
Female282366
56 to 65S3a. GENDER:Male196320
Female279452
66 or olderS3a. GENDER:Male162367
Female243700

The ‘+’ “stacking” operator allows a single output table to include multiple data analyses. With ‘+’, CTABLES divides the output table into multiple sections , each of which includes an analysis of the full data set. For example, the following command separately tabulates age group and driving frequency by gender:

CTABLES /TABLE ageGroup + freqOfDriving BY gender.
MaleFemale
S3a. GENDER:
CountCount
Age group15 or younger00
16 to 25594505
26 to 35476491
36 to 45489548
46 to 55526649
56 to 65516731
66 or older531943
1. How often do you usually drive a car or other motor vehicle?Every day23052362
Several days a week440834
Once a week or less125236
Only certain times a year5872
Never192348

When ‘+’ and ‘>’ are used together, ‘>’ binds more tightly. Use parentheses to override operator precedence. Thus:

CTABLES /TABLE hasConsideredReduction + hasBeenCriticized > gender.
CTABLES /TABLE (hasConsideredReduction + hasBeenCriticized) > gender.
Count
26. During the last 12 months, has there been a time when you felt you should cut down on your drinking?Yes513
No3710
27. During the last 12 months, has there been a time when people criticized your drinking?YesS3a. GENDER:Male135
Female49
NoS3a. GENDER:Male1916
Female2126
Count
26. During the last 12 months, has there been a time when you felt you should cut down on your drinking?YesS3a. GENDER:Male333
Female180
NoS3a. GENDER:Male1719
Female1991
27. During the last 12 months, has there been a time when people criticized your drinking?YesS3a. GENDER:Male135
Female49
NoS3a. GENDER:Male1916
Female2126

基于 GNU PSPP 2.0.1 手册与入门教程整理