How To Create New Variables With Multiple Categories

From Q
Jump to: navigation, search

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

  1. 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.
  2. 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.

Method 2: Using a banner

When creating a banner, Q automatically creates binary variables and sets these as a Pick Any question.

Method 3: Using JavaScript

  1. Create > Variables and Questions > Variables > JavaScript Formula(s) > Numeric.
  2. Create the Expression using if and else if Statements.
  3. 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.

See also

Creating Categorical Variables

Personal tools