How To Create New Variables With Multiple Categories
This page describes different ways of creating categorical variables with multiple variables as inputs. For example, computing household structure, based on information about marital status and the age of the household's occupants. The third method is, in general, the best method, although methods 1 and 2 are often regarded as more straightforward to less experienced users, while method 4 can be useful where there is a need to automate the creation of a large number of variables.
Method 1: Using binary variables
- Create binary variables representing each of the categories. The most straight method is often to create a Filter for each category. See How to Compute Binary Variables for links to other methods.
- On the Variables and Questions tab, select all the variables, right-click and select either:
- Insert Ready-Made Formula(s) Menu > Pick Any -> Pick One to create a new Pick One question (i.e., a question where all the categories are mutually exclusive). Note that if your binary variables are not mutually exclusive, they they will be forced to be mutually exclusive in the resulting variable (you will be given a warning if this occurs).
- Set Question to create other question types. Typically, a Pick Any is the most appropriate format if the categories are not mutually exclusive.
- Create the Expression using if and else if Statements.
- Change its Question Type to Pick One.
Method 4: QScript
You can automate the entire process by creating a QScript. This will involve the same logic as Method 3, except that the variable will be created using QScript and the Question Type set in the same way.