Chapter 13 Create Data Set

This chapter describes the process of loading the full NCP data set and from that creating a sample data set with the relevant variables for the Good Loser conjoint experiment.

13.1 Load packages or install them if not already installed

if(!require("ggplot2")){install.packages("ggplot2");  library(ggplot2)}
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}
if(!require("haven")){install.packages("haven");  library(haven)}
if(!require("knitr")){install.packages("knitr");  library(knitr)}
if(!require("readxl")){install.packages("readxl");  library(readxl)}
if(!require("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
if(!require("Hmisc")){install.packages("Hmisc");  library(Hmisc)}
if(!require("likert")){install.packages("likert");  library(likert)}
if(!require("naniar")){install.packages("naniar");  library(naniar)}
if(!require("ggthemes")){install.packages("ggthemes");  library(ggthemes)}

knitr::opts_chunk$set(echo = FALSE, knitr.kable.NA = "", cache = FALSE, warning = FALSE, message = FALSE, error = TRUE, echo = FALSE)

13.2 Load raw NCP data

Select variables of interest for the good loser experiment, recode, and create new data set in .sav and .csv formats

d_1 <- read_sav("C:\\Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/Data/Norwegian Citizen Panel - wave 1-13 - EN.sav")

 d_1 <- d_1 %>%
  select(responseid, #Select variables of interest for the good loser experiment
         r13pad1,    
         r13pad2,
         r13pad3,
         r13pad4,
         r13pad5_avsender,
         r13pad5_sak,
         r13pad5_utfall,
         r13pad5_vinner,
         r13pad5_vinnermargin,
         r13pad6_ran,
         r13pad6a,
         r13pad6b,
         r13pad7a,
         r13pad7b,
         r13pad8a,
         r13pad8b
         )  

13.3 Load Time tracker data

The time tracker data set is a separate data set that provides information about how long the respondents spent on answering the three post measure questions in the Good loser experiment.

d_2 <- read_xlsx("C:\\Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/Data/TimeTracker - runde 13.xlsx")

d_2 <-  d_2 %>%
  select(responseid = responseID, 
         timeTracker2_R13PAD6A,
         timeTracker2_R13PAD6B
         )  %>% 
  gather(Scale_time, time, timeTracker2_R13PAD6A:timeTracker2_R13PAD6B) %>% 
  filter(!is.na(time))

13.4 Merge data sets

d <- left_join(d_1, d_2, by= "responseid") %>% 
   filter(!is.na(time))  

d %>%    write_sav("Data/Goodloser-exp3.sav") %>%  #Create data file, .sav format
  write.csv("Data/Goodloser-exp3.csv")  #Create data file, .csv format