Create New Variables - Create Variables from Merged Categories

From Q
Jump to: navigation, search

This QScript automates the process of creating new variables based on merged categories in Pick One and Pick One - Multi questions, where the sets of merged categories are to be the same for each question. For example, if you have a battery of 100 11-point scales, and you would like to created variables for the top 4, middle 3, and bottom 4 categories for all of them at once, you can do so using this QScript.

When the script runs you will be prompted to:

  1. Choose the number of categories in the questions you want to work with. For example, if you are creating new variables from questions that have 7-point scales, you would choose 7 here.
  2. Choose the questions that you wish to create new variables for.
  3. Specify the Source Values for the categories that should be combined. Values should be entered as numbers separated by commas, e.g. 1, 2, 3. To work out which values you want to use look in the Value Attributes for the question, and check the Source values. If you have already entered all the mergings you want to apply, leave this blank and the script will go on to perform the merges.
  4. Enter a label for each merge you want to apply.

If any Don't Know style options are identified you will be given the option to remove them.

Example

Consider the following agreement scale, where we want to create new questions for the Top 2 (1, 2), and Bottom 3 (3,4,5) categories.

PickOneMultiToPickAnyMerge1.PNG

Before running the script, we would check the Value Attributes, which show the following values.

MergePhoneScale1.PNG

This lets us see how the category labels match up to the source values in the data. Note the scale is reversed here, in the sense that the highest level of agreement (Strongly agree corresponds to the lowest value (1). We should enter the following values and labels when running this script:

Label for merged category Values
Top 2 1, 2
Bottom 3 3, 4, 5

Technical details

When running this script, note:

  1. Always use the source values from your questions when specifying the values of categories to be merged.

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 Combining Categories');
 
if (!applyCustomMerges(true))
    log("QScript Cancelled");
else
    conditionallyEmptyLog("QScript Finished");


See also