Create New Variables - Binary Variable(s)

From Q
Jump to navigation Jump to search

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 variable setsspan, 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

  1. 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).
  2. Run this tool using Automate > Browse Online Library > Create New Variables > Binary Variables.
  3. If using categorical questions, choose whether to return values for incomplete data (see below).
  4. 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:

  1. Find the new question in the Variables and Questions tab.
  2. Right-click and select Edit R Variable.
  3. Modify the formula as needed.
  4. Run the code and click Update R Variable.
  1. Select the variables that you want to use under Data Sets. These should be all numeric (Numeric, Numeric - Multi, Numeric - Grid) or all categorical (Nominal/Ordinal, Nominal/Ordinal - Multi, Binary - Multi, Binary - Multi (Compact)).
  2. Run this tool by clicking the plus-sign next to the variables and selecting Ready-Made New Variables > Binary Variables.
  3. If using categorical questions, choose whether to return values for incomplete data (see below).

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:

  1. Find the new binary data under Data Sets
  2. Expand the variable set and select one of its variables.
  3. Modify the code in Properties > R CODE on the right of the screen.
  4. Click the Calculate button.

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

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.

JavaScript

includeWeb("QScript Functions for Binary Variables");

binaryVariables();

See also