In addition to saving templates for pages, visualizations, and advanced analysis outputs, variable sets can be saved as templates. This means you can set up a variable set the way you want, save it as a template, and insert it into the same or another document to update other similar variables in bulk or create new versions of them without having to manually recreate these changes.
- How applying a variable set template works
- What is saved in the variable set template?
- How templates match the saved information to the selected variable
- What happens when things don't match?
- Custom code variable sets
- Method
- Technical Details
How applying a variable set template works
The information saved in the variable template and the metadata in the selected variable set(s) on which the template is being used is matched up when the template is applied. Any changes that can be made based on the template are made. However, suppose there are differences between the information (variable metadata) in the template vs. the selected variable set. In that case, those changes will not come through (e.g., missing categories will not be added and included in any further templated modifications).
Example: Updating Row/Column Labels
Template matching is done on the row/column labels in a table. In the example below, I have a Nominal variable containing attitudes about cola brands, and I updated the "Neither like nor dislike" row to "Neutral" by right-clicking the row and selecting Rename.
I can then save this variable as a template and apply the template across other variables with a similar scale, and the row names in the tables will automatically be updated:
The changes to the row names are saved in the underlying variable set (in the variable set’s data reduction).
Example: Updating Values and Table Format
Values assigned to each attribute in a variable set can be updated and saved as a variable template. In the following example, we will use Q4 - Brand Attitude, which is a Nominal - Multi variable set:
The variable set used to create the above table has underlying Value Attributes. You can see these by selecting the variable set under Data Sources and then clicking Data > Properties > Values.
Modifications are then made:
- Change Values to 1 to 5 instead of the original -2 to 2 via Data > Properties > Values (notice the Average values change from the table above to a a number between 1 and 5 in the table below).
- On the table itself, remove Hate, Dislike, and Neither like nor dislike by right-clicking the columns and selecting Hide.
- Create a Top 2 Box net category from Like and Love by selecting both columns, right-clicking, and selecting Create NET. Then, drag and drop the new column to the first column in the table.
The changes made to the table will be saved in the underlying variable set, into the data reduction. When we save a template based on this variable set, the following things will be stored:
- The changes to the Values for each scale point.
- The scale points (Hate, Dislike, and Neither like nor dislike) that were hidden will be saved as hidden.
- The Top 2 Box NET category.
- The position of the Top 2 Box NET category.
We will then apply these changes to the individual non-grouped variables below.
Each variable will have the same changes made to it once the template is applied.
Example: Updating Variable Structure and Attributes
Next, let's consider restructuring a variable and amending the value attributes, specifically, Count this value. In this case, we'll look at:
A Nominal - Multi variable set with value labels of:
- Very dissatisfied
- Somewhat dissatisfied
- Neither satisfied nor dissatisfied
- Somewhat satisfied
- Very satisfied
- Don’t know
A user updates as follows:
- Changes the Structure to Binary - Multi in the object inspector.
- Sets "Don’t know" to Missing Values > Exclude from analyses in the Value Attributes.
- Ticks Count this Value for "Somewhat satisfied" and "Very satisfied" (i.e., creating a top 2 box score, to use the jargon of market research) in the Value Attributes.
When saved as a template, it will automatically create a Binary - Multi with a top two box score and "Don’t know" set to missing values, provided that the target variable set’s value labels include "Somewhat satisfied", "Very satisfied", and "Don’t know". If these labels don’t appear, a Binary - Multi will still be created, but will show all 0% as it has no way of selecting the Count this Value settings. In this instance, a warning will appear explaining that The values to be counted in <variable set name> should be verified.
What is saved in the variable set template?
- The variable set Structure (e.g., Nominal, Binary, etc.)
- Elements of the Value Attributes, such as the values, what's counted as missing data, and "Count this Value" settings, depending on the structure of the variable set.
- How the variable set is presented as a table, i.e., the Table format (also known as the data reduction), which includes NETs, merged categories, spans, changes made to row/column labels in the table, custom column comparisons, and for variable sets with a grid structure, whether the rows and columns have been switched around.
- For variable sets made using custom code, the template includes inputs created by Inputs JavaScript, and the R code (Inputs JavaScript GUI controls and Code Editor formulas).
How templates match the saved information to the selected variable
Templates match on the selected variable sets' labels, but do so without considering the case (i.e., "Strongly Agree" is the same as "strongly agree". Any extra white space is also ignored (e.g., extra spaces).
Transposed variable sets
Nominal - Multi, Ordinal - Multi, Binary - Grid, and Numeric - Grid variable sets can be transposed (i.e., select the resulting table, and press Switch rows and columns). This information is saved in templates and applied when the template is used.
Custom comparisons
Custom column comparisons are also saved and applied in templates.
What happens when things don't match?
Regardless of the variable set's structure, if any value or label cannot be matched up with what's in the template, then the template settings will be applied to the value or label that can be matched up. If no value or labels match at all, then the template will do nothing.
Where the template contains spans, but there is no, or only one, matching value or label within that span between the target variable set and the template, then the span will be omitted. Conversely, if the target variable set contains values or labels that are not saved in the template, then these will not be included in any spans.
Templates and variable set structure
If a template was created using a variable set of one structure, and it's applied to a variable set with a different structure, then the closest matching structure type will be used.
Structure in Target VarSet | Numeric | Nominal | Ordinal | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid | Numeric - Grid | Ranking |
---|---|---|---|---|---|---|---|---|---|---|---|
Numeric | Numeric | Nominal | Ordinal | Numeric | Binary - Multi | Nominal | Ordinal | Nominal | Binary Multi | Numeric | Ordinal |
Nominal | Numeric | Nominal | Ordinal | Numeric | Binary - Multi | Nominal | Ordinal | Nominal | Binary Multi | Numeric | Ordinal |
Ordinal | Numeric | Nominal | Ordinal | Numeric | Binary - Multi | Nominal | Ordinal | Nominal | Binary Multi | Numeric | Ordinal |
Numeric - Multi | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Binary - Multi | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Nominal - Multi | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Ordinal - Multi | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Binary - Multi (Compact) | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Binary - Grid | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid | Numeric - Grid | Ranking |
Numeric - Grid | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid | Numeric - Grid | Ranking |
Ranking | Numeric - Multi | Nominal - Multi | Ordinal - Multi | Numeric - Multi | Binary - Multi | Nominal - Multi | Ordinal - Multi | Binary - Multi (Compact) | Binary - Grid if no error; otherwise Binary - Multi | Numeric - Grid if no error; otherwise Numeric - Multi | Ranking |
Note that data conversion steps are not included in the template. For example, a Binary - Multi variable set saved as a template but applied to a Nominal variable set will not create binary-format variables from the value labels of the Nominal variable set.
The template remembers the Label of the corresponding row or column name. If the value attribute label says Men, and the corresponding row name says Males, the template will replace Men with Males.
However, some row and column names do not correspond to a category label in the value attributes (e.g., Numeric variables, either the rows or columns of a Nominal - Multi, the rows and columns of a Binary Grid). For these, the default value of the row (column) names is used instead. Where the default value is taken directly from the variable label, this can be modified by selecting the corresponding variable in the data sources tree. Thus, the general rule is that templates always record how the default name of a row or column is changed to the actual label in the table used to create the template.
Custom code variable sets
If a template was created from a custom code variable set created using R or JavaScript, then applying the template to a variable set that was not created using code will update only the metadata of the target variable set.
Only variables referenced in Inputs JavaScript GUI controls will be replaced by selected variables when applying R variable set templates, and these variables must not be in an error state when saving as a template.
Method
How to save a Variable Set Template
1. Select the modified variable set in the Data Sources tree and right-click > Save as Template.
2. Change File name as required, e.g. T2B, and press Save.
How to apply a Variable Set Template
1. Select the variable set(s) to apply the template to in the Data Sources tree and right-click > Apply Template.
2. Select your template file and press Apply.
3. The selected variables have now been updated with the template settings.
How to insert a new variable set from a template
1. Select the variable(s) to apply the template to in the Data Sources tree.
2. Hover and click + > Template.
How to insert an R variable template as a new variable set - single variable
In this example, we will use an R-based count variable based on Q4 - Brand Attitude, which was created from the Data Sources tree via + > Calculate Across Variables > Count, which counts the number of Love responses.
The modifications are:
- Change Categories To Count to Love.
- Change Structure to Nominal.
We will then apply these changes to the Coca-Cola variables from Q4 - Brand Attitude below.
1. Select the modified variable set in the Data Sources tree and right-click > Save as Template.
2. Change File name as required, e.g. Count, and press Save.
3. Now select only the Coca-Cola variables.
4. Hover and click + > Apply Template.
6. Select your template file and press Apply.
7. A new Count variable, which counts the Love category across the selected variables, has now been created with these template settings.
How to insert an R variable template as a new variable set - multiple variables
In this example, we will use an R-based multiplication variable based on a Coca-Cola variable, which was created from the Data Sources tree via + > Calculate Across Variables > Multiply, and multiplies each value by 100.
The modifications are:
- Change the Single numeric value to 100.
We will then apply these changes to the Q2 - No. of colas consumed variable set below.
1. Select the modified variable set in the Data Sources tree and right-click > Save as Template.
2. Change File name as required, e.g. Multiply by 100, and press Save.
3. Now select only the Q2 - No. of colas consumed variable set.
4. Hover and click + > Apply Template.
A new set of variables based on each of the original variables, which multiplies every value by 100, has now been created with these template settings.
Technical Details
These templates are saved in the Displayr Cloud Drive, and they can be accessed by clicking the User Initials icon at the top right corner and selecting Displayr Cloud Drive.
Templates saved from the Data Sources tree will end in varset.QTemplate:
Note that if you place your template files within folders in your Cloud Drive, when you bring up the importing template dialog, you will additionally need to select the relevant folder.
Next
How to Create and Apply a Page Template
How to Create and Apply a Visualization Template
How to Save and Apply a Customized Analysis Output as a Template