Modify Data - Merge Scales (Custom)
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:
- 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.
- Choose the questions that you wish to apply the merges to.
- 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.
- 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.
Before running the script, we would check the Value Attributes, which show the following values.
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:
- Always use the source values from your questions when specifying the values of categories to be merged.
- 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
JavaScript
includeWeb('QScript Functions for Combining Categories');
if (!applyCustomMerges(false))
log("QScript Cancelled");
else
conditionallyEmptyLog("QScript Finished");
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.
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library