Chapter 2 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.

2.1 Load packages or install them if not already installed

if(!require("ggplot2")){install.packages("ggplot2");  library(ggplot2)}
## Loading required package: ggplot2
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}
## Loading required package: tidyverse
## -- Attaching packages --------- tidyverse 1.2.1 --
## v tibble  1.4.2     v purrr   0.2.5
## v tidyr   0.8.2     v dplyr   0.7.7
## v readr   1.1.1     v stringr 1.3.1
## v tibble  1.4.2     v forcats 0.3.0
## -- Conflicts ------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
if(!require("haven")){install.packages("haven");  library(haven)}
## Loading required package: haven
if(!require("knitr")){install.packages("knitr");  library(knitr)}
## Loading required package: knitr
if(!require("readxl")){install.packages("readxl");  library(readxl)}
## Loading required package: readxl
if(!require("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
## Loading required package: kableExtra
if(!require("Hmisc")){install.packages("Hmisc");  library(Hmisc)}
## Loading required package: Hmisc
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
if(!require("likert")){install.packages("likert");  library(likert)}
## Loading required package: likert
## Loading required package: xtable
## 
## Attaching package: 'xtable'
## The following objects are masked from 'package:Hmisc':
## 
##     label, label<-
## 
## Attaching package: 'likert'
## The following object is masked from 'package:dplyr':
## 
##     recode
if(!require("naniar")){install.packages("naniar");  library(naniar)}
## Loading required package: naniar
if(!require("ggthemes")){install.packages("ggthemes");  library(ggthemes)}
## Loading required package: ggthemes
knitr::opts_chunk$set(echo = FALSE, knitr.kable.NA = "", cache = FALSE, warning = FALSE, message = FALSE, error = TRUE, echo = FALSE)

2.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
         )  

2.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))

2.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