See Crunch Automation basics for more information.
The SET NUMERIC VALUE command allows you to change the numeric values associated with categories on a categorical variable, including categorical arrays.
Generally, only "scales" in your dataset should have numeric values; otherwise, mean scores may appear in tables and graphs for nominal data (e.g., a mean of 1.4 on Gender isn’t useful and might be a distraction).
You may find it helpful to first use the UNSET NUMERIC VALUES command to run on all variables (in order to clear all the values) before setting numeric values. You only need to use the UNSET NUMERIC VALUES command once on all categorical variables (see the examples below).
Important notes
The SET NUMERIC VALUE command includes a few important caveats:
- The command only works on categorical variables and categorical arrays.
- You can change multiple categorical variables at once (provided they have the same categories). Categorical arrays have the same categories by definition.
- You don’t need to specify the categories exhaustively.
- code corresponds to the category id. The code is not the same as any existing numeric value assigned to the category.
- For example, if there is an "18-29" category, it might have a numeric value of 23 but a category id of 2. You can only refer to this category by the code = 2.
- float is the numeric value you want to assign to the category. Floats can have decimal places (as opposed to integers).
SET NUMERIC VALUE alias, ..., alias
WITH
code|"label" = float,
...
code|"label" = float;
Use case
The following example is from the Mobile Technology and Home Broadband Study 2019 (you can use the data from the examples page). In that study, the SPSS datafile imports a categorical variable representing income (as seen in the following example):
It is common for SPSS imports to have numeric values associated with the categories that correspond to the category id. This is why unsetting the numeric values on all categorical variables may be a prudent first step on importing the data, in order to avoid any analytic errors when it comes to calculating means:
UNSET NUMERIC VALUE ALL("categorical", "categorical_array");
In the example that shows income brackets, we may wish to set numeric values for each of the categories so that it has an estimated midpoint for that bracket. Note that the 'Don’t know' and 'Refused' categories are assigned NULL values, so they are excluded from any mean calculation:
SET NUMERIC VALUE inc
WITH
"Less than $10,000" = 5000,
"10 to under $20,000" = 15000,
"20 to under $30,000" = 25000,
"30 to under $40,000" = 35000,
"40 to under $50,000" = 45000,
"50 to under $75,000" = 62500,
"75 to under $100,000" = 87500,
"100 to under $150,000, OR" = 125000,
"$150,000 or more?" = 200000,
"(VOL) Don't know" = NULL,
"(VOL) Refused" = NULL;
which results in the following: