When merging files together side by side, you will need at least one variable in each data set that is used to match which cases merge together. However, you may have data sets where the matching should be done using multiple variables (e.g., a respondent ID variable and an observation number). This article describes how to create a new variable that is a combination of those variables to use to merge the files.
Requirements
- Two or more data files with multiple variables that you need to use to match cases for the merge.
Method
- Import the first file into Displayr.
- From the Data Sources tree, hover over any variable > Plus (+) > Insert Variable(s) > Custom Code > JavaScript - Numeric / JavaScript - Text.
- Select the newvariable and in General tab of the object inspector, fill in the fields as follows in the General section and press OK.
- Name: CombinedId (you can use any name)
- Label: Combined ID variable (you can use any label)
- In the Data tab of the object inspector, enter the custom code in the JavaScript Code expression and replace the variable names with your own
-
//combine the value labels for each case for the variables
//to use to merge the data files delimited by -
//replace id1 and id2 with your variable names
//add more variables and delimiters, if needed, using +
Q.Label(id1) + " - " + Q.Label(id2)
-
- Click Calculate.
- Go to Share > Export Data > Download as SPSS File (SAV) and save the file somewhere.
- Repeat the previous steps for the second file.
- Merge the two files How to Combine Data Files by Adding New Variables.
Next
How to Use JavaScript in Displayr
How to Create a Custom Numeric JavaScript Variable