The CREATE CATEGORICAL FROM <text> command allows you to apply a taxonomy to a text (open-ended) variable. Crunch reads each response, classifies it into a category of the taxonomy and saves the result as a new variable. This command gives each response exactly one category. Use this command when an answer should only count once.
The taxonomy can be defined with the DEFINE TAXONOMY command earlier in the same script, or in a previous one, or one created in Crunch UI. The taxonomy must belong to the same project (folder) as the dataset.
Important to remember:
- The input variable must be a text variable.
- The output alias must not exist in the dataset yet.
The following argument is optional:
- WHERE - a condition that allows you to categorize only some of the responses of an open ended variable. Specifically, the responses in the rows that match a condition. Conditions that can be used with WHERE include:
- ==, <, >, and <=, for example: age >= 18 or wave == "Wave 3"
- IN with a list, for example: region IN ["North", "South"]
- is_missing(), for example: is_missing(issue_coded)
- AND, OR, NOT to combine conditions, for example: age >= 18 and not (region == "North")
CREATE MATERIAL CATEGORICAL FROM <text variable alias>
WHERE condition
USING "taxonomy name"
AS <alias for output variable>
TITLE "title for output variable";Example
CREATE MATERIAL CATEGORICAL FROM <most_important_issue>
WHERE wave == "Wave 3"
USING "Created from most_important (2)"
AS most_important_cat
TITLE "Most Important Issues (Cat.)";The categorical variable has one category per category of the taxonomy, plus:
- Unclassified – responses that don't match any category of the taxonomy.
- No data – cases with no responses (missing).
REPLACE CATEGORICAL FROM <text>
The REPLACE CATEGORICAL FROM <text> command allows you to categorize additional text responses to an existing categorized variable. The properties of the categorized variable do not change, the new text responses are added to the categories of the variable.
The following argument is optional:
- WHERE - a condition that allows you to categorize only some of the responses of an open ended variable. Specifically, the responses in the rows that match a condition. Conditions that can be used with WHERE include:
- ==, <, >, and <=, for example: age >= 18 or wave == "Wave 3"
- IN with a list, for example: region IN ["North", "South"]
- is_missing(), for example: is_missing(issue_coded)
- AND, OR, NOT to combine conditions, for example: age >= 18 and not (region == "North")
REPLACE MATERIAL CATEGORICAL alias FROM <text variable alias>
WHERE condition
ELSE VARIABLE <alias>
USING "taxonomy name"; Example
REPLACE MATERIAL CATEGORICAL issue_coded FROM most_important_issue
WHERE is_missing(issue_coded)
ELSE VARIABLE issue_coded
USING "Most important issues (coded)";Example - classify unclassified responses
REPLACE MATERIAL CATEGORICAL issue_coded FROM most_important_issue
WHERE is_missing(issue_coded)
ELSE VARIABLE issue_coded
USING "Most important issues (coded)";
Related articles
CREATE MATERIAL MULTIPLE DICHOTOMY FROM <text> command for open ends