The QScript Modify Data - Use Question as Template for Modifying Other Questions
replicates changes made to one question (e.g., merging categories, renaming of categories), to other questions of the same structure (i.e., same number of categories with the same labels).
Technical details
Changes are replicated between Pick One and Pick One - Multi questions, or between two Pick Any questions. Only questions that have the same set of categories can be modified. If any of the target questions have been modified previously, for example by making changes on the table or by editing the Value Attributes, then it will not be possible to replicate the changes for these questions, and the QScript will generate a report describing what needs to be done to allow those questions to be used. See below for instructions on how to revert changes.
The types of changes that can be copied are:
- Renamed categories
- Hidden categories
- Removed categories
- Merged categories and NETs
- Recoded categories
When you run this script you will be asked to select the question to use as a template. The script will then identify all questions which can be changed in the same way and you can then choose which questions you would like to modify. Once the script is finished a new group will be added to your Report which contains a description of what changes have been made, and a table showing each of the changed questions.
Reverting existing changes
The questions that you choose choose to modify with this QScript must start with all of their original labels and values unchanged. If some changes have already been made, then these will need to be reverted before you can replicate the changes from your main question. If some questions need to be reverted then this QScript will generate a report describing which questions need to be reverted and how to do so.
If changes have been made in the table only (for example renaming labels on the table, merging categories or adding NETs, or hiding/removing categories) then you can right-click on a SUMMARY table for this question and select Revert.
If changes have been made to the Value Attributes (for example recoding) then you instead need to:
- Highlight the variable(s) for the question in the Variables and Questions tab.
- Right-click and select Revert to Source.
- Ensure the question has the same Question Type as it did previously. If there are many variables, right-click them and use Set Question. If there is a single variable then click in the Question Type column to select the Question Type.
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
▶ Show Code
Prior to the 15th of December, 2015, this page was known as Modifying Rows and Columns - Use a Question as a Template for Modifying Other Questions
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.