63 lines
2.4 KiB
R
63 lines
2.4 KiB
R
|
library(knitr)
|
||
|
library(kableExtra)
|
||
|
knitr::opts_chunk$set(echo = FALSE, results = "hide", message = FALSE, dev = "cairo_pdf", warning = FALSE)
|
||
|
knitr::opts_chunk$set(fig.pos = 'H')
|
||
|
options(knitr.table.format = "latex", knitr.kable.NA = "")
|
||
|
Sys.setlocale("LC_ALL","English")
|
||
|
library(here)
|
||
|
library(foreign)
|
||
|
library(dplyr)
|
||
|
library(psych)
|
||
|
library(ggplot2)
|
||
|
library(lubridate)
|
||
|
library(wesanderson)
|
||
|
library(colortools) # adjacent works
|
||
|
library(ggthemes) # theme_tufte works
|
||
|
library(varhandle) # coercing factor to numeric variables
|
||
|
library(naniar) # for replacing values with missings
|
||
|
library("Gifi") #Implements categorical principal component analysis
|
||
|
library(matrixStats) #High-performing functions operating on rows and columns of matrice
|
||
|
library(cowplot)
|
||
|
library(tibble)
|
||
|
library(reshape2) #!new in tool for FMS
|
||
|
# for tables
|
||
|
library(knitr)
|
||
|
library(kableExtra)
|
||
|
library(formattable) #!new in tool for FMS
|
||
|
source("Utility functions.R")
|
||
|
## More functions
|
||
|
# Response Rate, Non-contact Rate, Refusal Rate, Coop-rate
|
||
|
r1 <- function(net,gross,i) { (net / (gross - i))*100 }
|
||
|
# Rate of Ineligibles
|
||
|
r2 <- function(net,gross){ (net/gross)*100 }
|
||
|
ESSred <- rgb(.91, .20, .32)
|
||
|
ESSgreen <- rgb(.14, .62, .51)
|
||
|
ESSblue <- rgb(0, .25, .48)
|
||
|
ESSColors <- unique(c(adjacent(ESSred, plot = F), square(ESSred, plot = F)))
|
||
|
ESSColors <- c(ESSColors, ESSgreen, ESSblue)
|
||
|
# pizza(ESSColors)
|
||
|
themeESS <- theme_tufte(base_size = 9, base_family = "Calibri") +
|
||
|
theme(axis.title = element_text(size = 9, face = "plain"),
|
||
|
axis.text = element_text(size = 9),
|
||
|
axis.line.x = element_line(),
|
||
|
plot.title = element_blank(),
|
||
|
legend.title = element_blank(),
|
||
|
legend.text = element_text(size = 9),
|
||
|
strip.text = element_text(size = 9, face = "bold"),
|
||
|
legend.position = "none",
|
||
|
legend.direction = "horizontal",
|
||
|
legend.box = "vertical",
|
||
|
legend.spacing = unit(0, "line"),
|
||
|
legend.key.size = unit(.75, "line"))
|
||
|
linebreak <- "\\hspace{\\textwidth}"
|
||
|
# Test data from R9 CF data with Inwer ID (intnum):
|
||
|
CFR9 <- foreign::read.spss("Data/Test R9/ESS9CFe03.sav",
|
||
|
use.value.labels = F,
|
||
|
use.missings = F,
|
||
|
to.data.frame = T)
|
||
|
CFR9singlecountry <- CFR9[CFR9$cntry == "DE",] # Assumes the FMS data used is country file. Change country if necessary for test. All countries needs change of full code
|
||
|
CF <- CFR9singlecountry
|
||
|
write.table(CFR9singlecountry,"DEMO_DATA_R9/ESS9CFe03_DE.csv", sep = ",", row.names = F)
|
||
|
#Example Dataset for single country
|
||
|
CF <- read.csv2("DEMO_DATA_R9/ESS9CFe03_DE.csv", sep = ",", dec=".", stringsAsFactors=F)
|