Introduction
This article describes how to merge data files when each file needs to be merged using two different variables (e.g., a respondent ID variable and an observation number).
Requirements
Two or more data files with different ID variables that you want to merge.
Method
- Import the first file into Q as follows: File > Data Sets > Add to Project, select the source, and choose Use original data file structure and press OK.
- Create > Variables and Questions > Variable(s) > JavaScript Formula > Text, filling in the fields as follows and press OK.
- Name: CombinedId (you can use any name)
- Label: Combined ID variable (you can use any label)
- Expression: id1 + " " + id2 (replace the variable names with your names)
- Tools > Save data as SPSS/CSV file, and save the file somewhere.
- Repeat the previous steps for the second file.
- Merge the two files in the normal way (see Merging Data Files).