This article describes how to stack a data set in Displayr and save your settings so that you can automatically re-stack your data set when your data updates. Stacking can also be described as going from wide to long format like:
The output below shows the variables of a data set that have been stacked using common labels (blue) and manually stacked variables (pink):
In this example, Displayr was able to automatically detect 7 common labels and then stack the variables that included these labels. We were also able to manually map 2 variable sets that were affected by inconsistent labeling, and specify which non-stacked variables to include.
Requirements
Please note these steps require a Displayr license.
- A stackable data set saved as a .sav file with the following requirements:
- Variables being stacked together must have matching Value Attributes and Types.
- Each observation/iteration of the stacking must reference a variable - missing data is not automatically inserted.
- The stackable data set has been imported to the Displayr Cloud Drive via the Initials icon > Displayr Cloud Drive > +Upload or by selecting the data set in Data Sources > Share > Export Data > To Displayr Cloud Drive as SPSS File (.SAV).
Note, if you have inconsistent data that you want to stack that doesn't meet the first bullet above, you will need to use one of the following methods to stack: 1) How to Stack Data Using R or 2) How to Stack Data from Displayr Using Q.
Method
1. In the toolbar, go to Anything > Data > Data Set > Stack.
2. Under Data > Data Sets > Input data set, enter the name and extension of the SPSS .sav file to be stacked, e.g. Cola.sav.
3. OPTIONAL: Enter a name for your stacked SPSS data file to be saved to the Displayr Cloud Drive in the Stacked data set field. If none is specified, it will default to Input data set name + " stacked".
4. Select the method of stacking via the Stack with common labels field:
- Automatically - This is the default setting whereby a set of common labels is automatically chosen based on the variable labels in the input data set and variables with these common labels are stacked together.
- Using a set of variables to stack as reference - This lets you specify which variable set labels to use for identifying variables to be stacked.
- Using manually input common labels - This lets you manually specify the labels for identifying variables to be stacked.
- Disabled - Select this if you wish to instead manually specify the variables to be stacked.
5. OPTIONAL: If using a set of variables as a reference, you will need to enter a Reference variables to stack text input. Note, multiple sets of common labels can be specified.
Each text input should contain the comma-separated names of the reference variables to be used to determine a set of common labels that are used for stacking. Note, a set of consecutive variables can be specified using a range consisting of the name of the first and last variables separated by a dash (-). For example, variables Q1_A, Q1_B, Q1_C, Q1_D can be specified as Q1_A-Q1_D. You can also use a wildcard character (*) when dealing with common prefixes and/or suffixes, for example, Q1_*.
6. OPTIONAL: If manually inputting the labels, you will need to enter a Common label text input for each item to be stacked. Note, multiple sets of reference variables can be specified for multiple sets of common labels.
7. OPTIONAL: In addition to the Stack with common labels setting, you can include manual stacking conditions under Manually specify stacking by. You have a choice between Variable and Observation. Depending on the variables to be stacked, it may be a lot easier to specify variables using one of the methods compared to the other.
8. OPTIONAL: If manually stacking by Variable, each text input should contain the names of the variables to be stacked together into one variable. Here, we will manually stack 2 variables using Q6_* and Q9_*.
9. OPTIONAL: If manually stacking by Observation, each text input should contain the name of the variable to be stacked in an observation. Here, we would need to enter Q6_A,Q6_B,Q6_C, and so on separately.
10. OPTIONAL: Enter any variable names you wish to include as non-stacked variables in your new data set under Non-stacked variables to include. Here, we will enter Q31,Q32.
11. OPTIONAL: Untick Include original case variable in stacked data set if you don't wish to include a variable containing the original case numbers.
12. OPTIONAL: Untick Include observation variable in stacked data set if you don't wish to include a variable containing the observation numbers.
13. OPTIONAL: Tick Automatic updating if you wish for the stacked data set to be regularly updated. Selecting this will then add the below options:
- Update period - Enter the time unit for regular updates. e.g. Hours, Days, Months.
- Frequency - Enter the frequency of the update period.
- Start date and time - The date and time of the first update in the format dd-mm-yyyy hh:mm or mm-dd-yyyy hh:mm.
- US date format - If specifying the start date/time, you can confirm whether it should be expressed in US format i.e. mm-dd-yyyy hh:mm.
- Time zone - If specifying the start date/time outside of UTC, you can confirm the time zone in the Continent/City format e.g. America/Los_Angeles. See Wikipedia for a list of time zones.
14. Click Calculate to run the stacking operation.
15. Import your newly saved data set from the Displayr Cloud Drive via Data Sources > + > Displayr Cloud Drive. If you set the automatic refresh frequency, this will ensure your data set automatically updates with the latest stacked data.
Next
How to Create Data File Relationships
How to Stack Data from Displayr Using Q
How to Use the Displayr Cloud Drive
Multiple Data Sets video - including an example of stacking data