Modifying Data - Apply Custom Merges to Scales

From Q
Jump to: navigation, search

This QScript automates the process of merging categories in Pick One and Pick One - Multi questions where you would like to merge the exact same set of categories in many different questions. For example, if you have a battery of 100 11-point scales, and you would like to merge the top 4, middle 3, and bottom 4 categories to 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. You example, if you want to merge categories in questions which are 7-point scales, choose 7 here.
  2. Choose the questions that you wish to apply the merges to.
  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 likelihood scale, which we want to merge to show the Top 4 (7 to 10), Middle 3 (4 to 6), and Bottom 4 (0 to 3) categories.

MergeScale434.PNG

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

MergeScale434ValueAttributes.PNG

We can see that the Source Value in the data does not match the label. That is, category 0 Not at all likely has been stored with a value of 1, the category 1 has been stored with a value of 2, and so on. When the script runs, the following entries would be made at the prompts, in order to successfully perform the merge as illustrated:

Label for merged category Values
Bottom 4 1, 2, 3, 4
Middle 3 5, 6, 7
Top 4 8, 9, 10, 11

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.
  2. Avoid making changes to the questions (e.g. renaming, hiding, or removing categories) prior to using the script. If you have made changes to your questions, you can revert the changes by selecting a table that shows the question, right-clicking on one of the category labels, and selecting Revert.

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(false))
    log("QScript Cancelled");
else
    conditionallyEmptyLog("QScript Finished");


See also