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

8.1 Load packages or install them if not already installed

if(!require("ggplot2")){install.packages("ggplot2");  library(ggplot2)}
if(!require("ggthemes")){install.packages("ggthemes");  library(ggthemes)}
## Loading required package: ggthemes
if(!require("haven")){install.packages("haven");  library(haven)}
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("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
if(!require("knitr")){install.packages("knitr");  library(knitr)}
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)}
if(!require("readxl")){install.packages("readxl");  library(readxl)}
## Loading required package: readxl
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}

## Utils.
source("goodloser-utils.R")

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

8.2 Load raw NCP data

Select variables of interest, and create new data set in .sav and .csv formats

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

d  <- ncp_raw %>% 
                     select(
                       responseid,
                       r9pad1, 
                       r9pad2, 
                       r9pad3, 
                       r10panelpad, 
                       r10pad1, 
                       r10pad2, 
                       r10pad3_mobil, 
                       r10pad3a_ran, 
                       r10pad3b_ran, 
                       r10pad3ended, 
                       r10pad3error, 
                       r10pad3paused,
                       r10pad3played,
                       r10pad3_timespent, 
                       r10pad4, 
                       r10pad4_comment,
                       r10pad5, 
                       r10pad6, 
                       r10pad7, 
                       r10pad8, 
                       r10pad9, 
                       r10pad1_9_backward_1, 
                       r10pad1_9_backward_2, 
                       r10pad1_9_backward_3, 
                       r10pad1_9_backward_4, 
                       r10pad1_9_backward_5, 
                       r10pad1_9_backward_6, 
                       r10pad1_9_backward_7, 
                       r10pad1_9_backward_8 
                     ) 

#Create data file, .csv format
  write.csv(d, "Data/Goodloser-exp2.csv") 
  #Create data file, .sav format
  write_sav(d, "Data/Goodloser-exp2.sav", compress = FALSE)