This article describes how you can use a QScript to combine several Binary-Multi variable sets into a Binary-Grid set, or several Number-Multi questions into a Number-Grid.
In this article, we will work through an example to produce a table that looks like this:
The key things to keep in mind with grouping together variables into questions are:
- Each variable needs to be stored as a Numeric - Multi or Binary - Multi variable set.
- Consistent Order – the order in which options appear for each attribute. You can drag and drop variables in the Data Sets tree to line them up correctly.
- Consistent Labels – the labels of the questions must include both the final row and column names (Note: these are also case-sensitive). I’ve found it yields the best results to separate them using spaces and a special character like “–” or “:”. Displayr makes it easy to edit labels by changing them directly in the Data Sets tree or using Find/Replace.
Load the data
If you want to work through the example with the same data used in this article:
- Download the CSV file to your computer. The file we will be using in this example is called Cola_dataset.csv. You can use this link to download the file: CSV file.
- Create a new Displayr document and load the data. See Get Your Data Into Displayr for more information.
Review the data
You can see the brand attitude question looking at attitudes and colas is broken into several questions and in different formats. For example, the feminine questions are already stored in a grid, but in contrast, the health-conscious questions are broken into multiple variables.
The rest of the questions we want to use (innocent, older, open to new experiences, rebellious, sleepy, and traditional) are stored in another variable called Grid.
The rest of this article will work through the tasks we need to accomplish to combine these variables into a single grid which we will call Brand Attitudes.
Standardize the labels
In order to combine the questions into the same grid, the variables in each variable set must have identical labels. We will edit the labels for health-conscious, innocent, older, open to new experiences, rebellious, sleepy, and traditional to match the ones for the feminine variables:
We will start with the health-conscious variables.
- In the Data Sets tree, right-click and Rename each label for the health-conscious rows to look like the feminine rows. For example, "Coke", "Diet Coke", etc. Ensure that there are no leading or trailing spaces in each label.
- After you have renamed all the labels, make sure that they are in the same order as the ones for feminine. If not, drag and drop the rows to make sure the options are in the same order.
- Highlight the health-conscious rows, right-click the highlighted area, and select Combine. You may need to right-click and select Rename to remove the "X" that appears in the label.
The next step is to deal with the variables contained in the Grid variable.
- In the Data Set tree, right-click on Grid and select Split.
- Rename the labels for the innocent rows to match the ones in the feminine rows (e.g., Coke, Diet Coke, etc.)
- Highlight the innocent rows, right-click the highlighted area, and select Combine.
The results are as follows:
- Repeat steps 1 and 2 for older, open to new experiences, rebellious, sleepy, and traditional.
Standardize the structure of each variable set
In order to combine the variable sets into the same grid, they must have one of the following structures: Numeric - Multi or Binary - Multi.
- In the Data Sets tree, select the feminine variable set.
- In the object Inspector, change the structure for feminine to Binary - Multi: Non-mutually exclusive categories.
- Click Fix if you get a message that the values to be counted should be verified and then OK.
- Repeat steps 1 thru 3 for health-conscious, innocent, older, open to new experiences, rebellious, sleepy, and traditional.
Create the Final Grid
To combine the variables into a grid:
- Select the variable sets feminine, health-conscious, innocent, older, open to new experiences, rebellious, sleepy, and traditional in the Data Sets tree.
- Hover until a + sign appears, then click on + > Ready-Made New Variable(s) > Combine Variable Sets as a Grid.
- Rename your new grid to Brand Attitudes.
You now have a grid variable called Brand Attitudes.