Create New Variables - Binary Variable(s)
This tool creates new binary variables from existing data. Binary variables are ones which can take two values, 1 and 0, with the possibility of a missing value for cases that do not have data. For numeric data, the new binary variables correspond to cases which have a value greater than 0, and you can customize this to other threshhold values as needed (see below). For categorical data, the new binary variables correspond to the categories in the data. Additionally, when applying this tool to multiple categorical span, the new binary variables will indicate which cases match those categories in any of the selected data. This is useful when wanting to combine categorical data of different types, for example if wanting to combine responses from a Top of mind awarness question (single response) with those from an Other awareness question (multiple response) to form a measure of Total awarness.
Usage
- Select the variables or questions that you want to use in the Variables and Questions tab. These should be all numeric (Number, Number - Multi, Number - Grid) or all categorical (Pick One, Pick One - Multi, Pick Any, Pick Any - Compact).
- Run this tool using Automate > Browse Online Library > Create New Variables > Binary Variables.
- If using categorical questions, choose whether to return values for incomplete data (see below).
- Enter a name for the new data and click OK'.
If you have chose numeric data, you can modify the formula used to determine which values in the underlying data are mapped to a value of 1 in the new binary variables using the following steps:
- Find the new question in the Variables and Questions tab.
- Right-click and select Edit R Variable.
- Modify the formula as needed.
- Run the code and click Update R Variable.
Technical details
When the inputs to the binary variables are categorical, you are offered the choice to Compute for cases with incomplete data. If you click Yes, then the new variables will always have a 0 or 1 value unless all of the input data for that category for that case are missing. If you click No, then each category will have a missing value when that case in the data has any missing values among the selected input data.
How to apply this QScript
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Click on the QScript when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Select this QScript from the list.
Customizing the QScript
This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.
Customizing QScripts in Q4.11 and more recent versions
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
- Press Edit a Copy (bottom-left corner of the preview).
- Modify the JavaScript (see QScripts for more detail on this).
- Either:
- Run the QScript, by pressing the blue triangle button.
- Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.
Customizing QScripts in older versions
JavaScript
includeWeb("QScript Functions for Binary Variables");
binaryVariables();
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.