Module 8 — Making new variables
Question: the analysis you want needs a variable you don't have — a pulse-pressure number, or BMI as categories. Derive it; never overtype raw data.
Open the sample (Ctrl+Shift+O). Both tools are in the Transform menu.
Compute Variable — a formula makes a new column
Transform → Compute Variable… Target PulsePressure, expression
SystolicBP - DiastolicBP, OK.
A new numeric column appears, computed for every case (cases missing either input come out blank — missingness propagates, correctly). Give it a label in Variable View, then run Descriptives on it.
Recode — grouping a scale variable into categories
BMI has standard clinical bands; a categorical version unlocks crosstabs, boxplot grouping and ANOVA factors.
Transform → Recode into Different Variables… Source BMI, new variable
BMIGroup, and the ranges:
| Range | New value |
|---|---|
| lowest – 18.4 | 1 |
| 18.5 – 24.9 | 2 |
| 25.0 – 29.9 | 3 |
| 30.0 – highest | 4 |
Then, in Variable View, label the codes (1=Underweight, 2=Normal, 3=Overweight, 4=Obese) and set the measure to Ordinal — a recode is only finished once it is labelled.
Always "into Different": recoding into same overwrites the original values, and the analysis you have not thought of yet will want them back.
Grouping vs histogram bins
Module 4's histogram bins slider also "grouped" BMI — but only in the picture. A recode makes a real variable every procedure can use, and is recorded in the document. Rule of thumb: exploring shape → bins; analyzing groups → recode.
Exercise
- Crosstab
BMIGroup× Hypertensive with chi-square — the module 7 BMI→SBP effect, now visible as a category pattern. - Compute
MAP(mean arterial pressure)= DiastolicBP + PulsePressure / 3. Check one case by hand against the Data View. - Boxplot SystolicBP by
BMIGroup. Do the medians climb across the four bands?
The syntax trail
compute target=PulsePressure, expression="SystolicBP - DiastolicBP"
compute target=MAP, expression="DiastolicBP + PulsePressure / 3"
crosstabs row=BMIGroup, column=Hypertensive, chi_square=true
Recode is dialog-only (its ordered rules don't reduce to a one-line
command), so it does not appear in the trail — one more reason the labelled
.ckd you Save is part of the reproducible record.