Blog

Some Useful R Code: Postprocessing

In order to preprocess the data, you can use the following code to extract the selected item name:

 

total$selecteditem <- total$options_left
total$selecteditem[total$selected== 1] <- total$options_right[total$selected== 1]

 

To generate a 7 point likert scale from the data set, use this code

 

total$tracker.likert1<- total$tracker1.likert1
total$tracker.likert1[total$id==”tracker2″]<- total$tracker2.likert1[total$id==”tracker2″]
total$tracker.likert1[total$id==”tracker3″]<- total$tracker3.likert1[total$id==”tracker3″]
total$tracker.likert1[total$id==”tracker4″]<- total$tracker4.likert1[total$id==”tracker4″]
total$tracker.likert1[total$id==”tracker5″]<- total$tracker5.likert1[total$id==”tracker5″]
total$tracker.likert1[total$id==”tracker6″]<- total$tracker6.likert1[total$id==”tracker6″]
total$tracker.likert1[total$id==”tracker7″]<- total$tracker7.likert1[total$id==”tracker7″]

In both instances, we use the data frame total and 7 different trackers.

To mark the deselected item on the consideration page, use

total$dropitem<-0
total$dropitem[total$item.consideration==total$selecteditem] <- 1

To export the code for stata/spss, it is helpful to use

write.csv2(total,”total.csv”, row.names = FALSE)

If you prefer decimal commas, use write.csv instead of write.csv2.