Reconcile question numbers across waves

Updated at June 23rd, 2023

Question numbers and response values sometimes change between waves of a survey.  This tutorial shows  ways you can reconcile question numbers   to compare results across waves.

Ideally, question numbers and response options would mean the same thing in each waves.If  If new questions and response options are added, they get new identifiers.  If questions or response options are dropped, those would be retired and not repurposed in later waves.  

But in practice, things aren't always this simple.  So you can use Protobi data processes to reconcile question numbers and response options so they are consistent for each wave.  

An effective way to start is to create a worksheet with a list of questions and responses as rows, and showing their identifiers in each wave.   

We refer to this process as "mapping" questions. This tutorial demonstrates how such a mapping can be read and applied programmatically in Protobi. 

A simpler  example of stacking waves of data is in this tutorial Combine data.

Example

In this example there are two data tables, wave2 and wave1. We created a project with the wave2 data, and now we want to bring in all data columns from the first wave. However, two data columns have been renamed in wave2. Since the questions are the same from the previous wave, we would like Protobi to recognize values from the wave 1 file as values for the two renamed data columns in the wave2 file. 

Step 1: Create a file that connects questions

First we create a CSV file that contains four columns. The first column contains the names of all the data columns we want to bring in from the first wave, and the second column contains any data labels associated with the data columns. The last two columns have the corresponding variables from the wave 2 datafile.

This table lists all column names.  In this example there are only two changes,  "price" in wave 1 changed to "sales price"  in wave 2,  and "mpg" changed to "milespergallon": 

Step 2: Upload the file as a data table

Next, upload the CSV file you created into project data as a new data table. Here we've named the data table "element_mapping". 

Step 3: Create a data process

Now we will need to create a data process that references the CSV file to match data columns from the prior wave with the data columns in the current wave. 

Note the process needs to be set as the primary datafile for the project.  


Code to map questions WoW

This is the code seen in the image above. After you run the code, you will see that values from prior wave data columns that have been renamed will be connected to the current wave's data columns. 

var rows = data.main;              //Current datafile in main
var prior_wave = data.wave_1;      //Prior wave(s) datafile
var element_mapping = data["element_mapping"]  //Mapping file for fields to bring in 


prior_wave.forEach(function(row){  //Assign wave variable as needed 
    row.wave = 1;
})


rows.forEach(function(row){
    row.wave = 2;
})


prior_wave.forEach(function(row){ //For each prior_wave record 
    var new_row = {}              //Create a new row
    new_row.wave = row.wave;      //Bring in wave information
    element_mapping.forEach(function(map){        //Bring in all columns listed in the mapping file
        new_row[map["w2_variable"]]= row[map["w1_variable"]] 
    })
    rows.push(new_row)            //Add the newly create row(s) to current datafile
    
})

return rows;

Was this article helpful?