See Crunch Automation basics for more information.
The CREATE NUMERIC TALLY command creates a new numeric variable that counts how many categories of a multiple response variable were selected for each row. All input variables must be of the multiple_response type.
To compute the tally of a subset, first create a multiple response variable containing only the items you wish to tally.
- The EXCEPT block takes either a list of aliases (unquoted or using backticks if required) or a list of labels (quoted strings).
- The VALID | MISSING expression allows you to define the result of a missing mask. By default, it takes MISSING all_missing(input_var).
CREATE NUMERIC TALLY alias
[EXCEPT alias, ... , alias (or) "string", ... , "string"]
[ALL VALID | (VALID | MISSING expression)]
AS alias
[TITLE "string"]
[DESCRIPTION "string" | COPY]
[NOTES "string" | COPY];
Example Syntax
CREATE NUMERIC TALLY watched_dramas
EXCEPT none_of_these
MISSING is_missing(watched_dramas)
AS num_watched_dramas
TITLE "Number of drama shows watched"
DESCRIPTION "Computed from Drama shows watched";
Use Case
For the following example, respondents were asked to select which of the following stores they have shopped at in the past 12 months.
To calculate the number of stores each respondent selected, you can use the CREATE NUMERIC TALLY command.
CREATE NUMERIC TALLY q5_mr
AS num_q5
TITLE "Number of Stores Shopped"
DESCRIPTION "Tally of stores shopped in past 12 months (Q5)";Running this script results in the following numeric variable:
Additionally, you could exclude the "Other store" option if you'd like to only count the stores that were listed in the question directly and include those who said they personally shop for homewares for their household (s5=1). To do so, you would need to reference the alias of the "Other" subvariable to include in the script (alias q5_35) and mark those valid where s5=1.
CREATE NUMERIC TALLY q5_mr
EXCEPT q5_35
VALID s5=1
AS num_q5_exclude_other
TITLE "Number of Stores Shopped (Exclude Other)"
DESCRIPTION "Tally of stores shopped in past 12 months (Q5)";