Skip to content

15.7.1.2 Scalar Variables ​

For a categorical variable, CTABLES divides the table into a cell per category. For a scalar variable, CTABLES instead calculates a summary measure, by default the mean, of the values that fall into a cell. For example, if the only variable specified is a scalar variable, then the output is a single cell that holds the mean of all of the data:

CTABLES /TABLE age.
Mean
D1. AGE: What is your age?48

A scalar variable may nest with categorical variables. The following example shows the mean age of survey respondents across gender and language groups:

CTABLES /TABLE gender > age BY region.
EnglishSpanish
Was this interview conducted in English or Spanish?
MeanMean
D1. AGE: What is your age?S3a. GENDER:Male4637
Female5139

The order of nesting of scalar and categorical variables affects table labeling, but it does not affect the data displayed in the table. The following example shows how the output changes when the nesting order of the scalar and categorical variable are interchanged:

CTABLES /TABLE age > gender BY region.
EnglishSpanish
Was this interview conducted in English or Spanish?
MeanMean
S3a. GENDER:MaleD1. AGE: What is your age?4637
FemaleD1. AGE: What is your age?5139

Only a single scalar variable may appear in each section; that is, a scalar variable may not nest inside a scalar variable directly or indirectly. Scalar variables may only appear on one axis within TABLE.

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