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 datasets where 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 combines those variables for use in merging 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 (+) > Custom Code > JavaScript > and select the appropriate variable set structure.
- Select the newvariable and in the General tab of the object inspector
Fill in the fields in the General section as follows, then 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 editor 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 JavaScript Variable
UPCOMING WEBINAR: The Roadmap for Market Researchers in the Age of AI