##################################################################################################################
##################################################################################################################
######################################################2018########################################################
##################################################################################################################
##################################################################################################################


################################################
#############PREPARING THE DATA#################
################################################
library(foreign)
library(memisc)

rm (list=ls())

#AB5
AB5 <-  read.spss("C:/Uni/Data/AB wave 5.sav",use.value.labels=T, to.data.frame = T)
#AB5 <-  read.spss("C:/Users/u265173/OneDrive/AB v WVS w Veronica/AB wave 5.sav",use.value.labels=T, to.data.frame = T)
table(AB5$country)
dmAB5 <- subset(AB5, AB5$country== "Egypt" | AB5$country == "Iraq" | AB5$country == "Jordan" | AB5$country == "Lebanon" | AB5$country == "Tunisia")
dmAB5$country<-droplevels(dmAB5$country)
table(dmAB5$country)

dmAB5$Surveytype <- 1
table(dmAB5$Surveytype)
table(dmAB5$country)
#12601 in AB.

#WVS7
WV7 <-  read.spss("C:/Uni/Data/WVS wave 7.sav",use.value.labels=T, to.data.frame = T)
#WV7 <-  read.spss("C:/Users/u265173/OneDrive/AB v WVS w Veronica/WVS wave 7.sav",use.value.labels=T, to.data.frame = T)
table(WV7$B_COUNTRY)
dmWV7 <- subset(WV7, WV7$B_COUNTRY=="Egypt" | WV7$B_COUNTRY=="Iraq"| WV7$B_COUNTRY=="Jordan"| 
                  WV7$B_COUNTRY=="Lebanon"| WV7$B_COUNTRY== "Tunisia")
dmWV7$B_COUNTRY <- droplevels(dmWV7$B_COUNTRY)
table(dmWV7$B_COUNTRY)

dmWV7$Surveytype <- 0
table(dmWV7$Surveytype)
table(dmWV7$B_COUNTRY)
#6,011 in WVS.




##################################################################################################################
##################################################################################################################
##############################################PREPARING ATTITUDES#################################################
##################################################################################################################
##################################################################################################################

###############################################################
#################VARIABLE 1: GENERALIZED TRUST#################
###############################################################

######trust AB3
#Generally speaking, would you say that most people can be trusted?
#1 = Most people can be trusted
#2 = You must be very careful in dealing with people
#98 = Cant Choose/Don't know
#99 = Decline to Answer

summary(dmAB5$Q103)

dmAB5$trustab <- as.numeric(dmAB5$Q103)
table(dmAB5$trustab)
dmAB5$Trust[dmAB5$trustab == 1] <- 1
dmAB5$Trust[dmAB5$trustab == 2] <- 0
dmAB5$Trust[dmAB5$trustab == 3] <- NA
dmAB5$Trust[dmAB5$trustab == 4] <- NA
table(dmAB5$Trust)

table(dmAB5$Trust, dmAB5$Q103)

# dmAB5$Trust: 0 - Most people are not trustworthy
# 1 - Most people are trustworthy

######trust WV6
#Generally speaking, would you say that most people
#can be trusted or that you need to be very careful in dealing with people?
#Most people can be trusted
#Need to be very careful
#No answer -> NA
#Don't know -> NA

summary(dmWV7$Q57)

dmWV7$trustwvs <- as.numeric(dmWV7$Q57)
table(dmWV7$trustwvs)
dmWV7$Trust[dmWV7$trustwvs == 1] <- 1
dmWV7$Trust[dmWV7$trustwvs == 2] <- 0
table(dmWV7$Trust)
#0 - Need to be very careful
# 1 - Most people can be trusted



###############################################################
#################VARIABLE 2: EDUCATIONAL GE####################
###############################################################

#AB#: q6014: A university education is more important 
#for a boy than a girl

summary(dmAB5$Q601_4)

dmAB5$unieducab <- as.numeric(dmAB5$Q601_4)
table(dmAB5$unieducab)
dmAB5$Unieduc[dmAB5$unieducab == 1] <- 0
dmAB5$Unieduc[dmAB5$unieducab == 2] <- 0.33
dmAB5$Unieduc[dmAB5$unieducab == 3] <- 0.67
dmAB5$Unieduc[dmAB5$unieducab == 4] <- 1
dmAB5$Unieduc[dmAB5$unieducab == 5] <- NA
dmAB5$Unieduc[dmAB5$unieducab == 6] <- NA
dmAB5$Unieduc[dmAB5$unieducab == 7] <- NA
table(dmAB5$Unieduc)
# Unieduc: 0 - Strongly agree, 1 - Strongly disagree

#WVS6 educge.
#V52: A university education is more 
#important for a boy than for a girl

summary(dmWV7$Q30)

dmWV7$Unieduc <- as.numeric(dmWV7$Q30)
table(dmWV7$Unieduc)
dmWV7$Unieduc[dmWV7$Unieduc == 1] <- 0
dmWV7$Unieduc[dmWV7$Unieduc == 2] <- 0.33
dmWV7$Unieduc[dmWV7$Unieduc == 3] <- 0.67
dmWV7$Unieduc[dmWV7$Unieduc == 4] <- 1

table(dmWV7$Unieduc)




###############################################################
#################VARIABLE 3: POLITICAL GE######################
###############################################################

#AB3 
#q6013: On the whole, men make better political leaders than women do
summary(dmAB5$Q601_3)

dmAB5$polleadab <- as.numeric(dmAB5$Q601_3)
table(dmAB5$polleadab)
dmAB5$PolLead[dmAB5$polleadab == 1] <- 0
dmAB5$PolLead[dmAB5$polleadab == 2] <- 0.33
dmAB5$PolLead[dmAB5$polleadab == 3] <- 0.67
dmAB5$PolLead[dmAB5$polleadab == 4] <- 1
dmAB5$PolLead[dmAB5$polleadab == 5] <- NA
dmAB5$PolLead[dmAB5$polleadab == 6] <- NA
dmAB5$PolLead[dmAB5$polleadab == 7] <- NA
table(dmAB5$PolLead)

#WVS6
#political GE wvs6.
#V51: On the whole, men make better political leaders than women do

#V51
summary(dmWV7$Q29)

dmWV7$poleducwvs <- as.numeric(dmWV7$Q29)
table(dmWV7$poleduc)
dmWV7$PolLead[dmWV7$poleducwvs == 1] <- 0
dmWV7$PolLead[dmWV7$poleducwvs == 2] <- 0.33
dmWV7$PolLead[dmWV7$poleducwvs == 3] <- 0.67
dmWV7$PolLead[dmWV7$poleducwvs == 4] <- 1

table(dmWV7$PolLead)




###############################################################
##############VARIABLE 4: TRUST IN POLICE######################
###############################################################
#AB3 201: 4.
#I will name a number of institutions, and I would like you to tell me to 
#what extent you trust each of them:
#public security(the police)

summary(dmAB5$Q201A_42)
dmAB5$Trustpol[dmAB5$Q201A_42 == "great trust"] <- 1
dmAB5$Trustpol[dmAB5$Q201A_42 == "some trust"] <- 0.67
dmAB5$Trustpol[dmAB5$Q201A_42 == "little trust"] <- 0.33
dmAB5$Trustpol[dmAB5$Q201A_42 == "no trust"] <- 0
dmAB5$Trustpol[dmAB5$Q201A_42 == "don't know"] <- NA
dmAB5$Trustpol[dmAB5$Q201A_42 == "refused"] <- NA

#dmAB5$Trustpol <-recode(as.numeric(dmAB5$Q201A_42), "1=1; 2=0.67; 3=0.33; 4=0; 5=NA; 6=NA")
table(dmAB5$Trustpol,dmAB5$Q201A_42)
table(dmAB5$Trustpol)
#0 - don't trust; 1 - trust to great extent

#WVS6
#ConfidencE: The police
summary(dmWV7$Q69)
dmWV7$Trustpol[dmWV7$Q69 == "A great deal"] <- 1
dmWV7$Trustpol[dmWV7$Q69 == "Quite a lot"] <- 0.67
dmWV7$Trustpol[dmWV7$Q69 == "Not very much"] <- 0.33
dmWV7$Trustpol[dmWV7$Q69 == "None at all"] <- 0
table(dmWV7$Trustpol)
#0 - no trust at all; 1 - trust to great extent

table(dmWV7$Trustpol, dmWV7$country)
#not in egypt.

##################################################################################################################
##################################################################################################################
##############################################PREPARING DEMOGRAPHICS##############################################
##################################################################################################################
##################################################################################################################

################################################
#################COUNTRY########################
################################################

table(dmAB5$country)
dmWV7$country <- as.factor(dmWV7$B_COUNTRY)

table (dmAB5$country)
table (dmWV7$country)




################################################
#################GENDER#########################
################################################

table(dmAB5$Q1002)
dmAB5$gender[dmAB5$Q1002 == "male"] <- 0
dmAB5$gender[dmAB5$Q1002 == "female"] <- 1
table(dmAB5$Q1002, dmAB5$gender)
#0 - male, 1 - female

table(dmWV7$Q260)
dmWV7$gender[dmWV7$Q260 == "Male"] <- 0
dmWV7$gender[dmWV7$Q260 == "Female"] <- 1
table(dmWV7$Q260, dmWV7$gender)


################################################
###################AGE##########################
################################################

summary(dmWV7$Q262)
table(dmWV7$Q262)
#this one is not numeric.

dmWV7$age_short <- as.numeric(paste(dmWV7$Q262))
summary(dmWV7$age_short)
table(dmWV7$age_short)

dmWV7$agecats[dmWV7$age_short < 30] <- 0
dmWV7$agecats[29 < dmWV7$age_short & dmWV7$age_short < 50] <- 1
dmWV7$agecats[dmWV7$age_short > 49] <- 2
table(dmWV7$agecats)
table(dmWV7$age_short, dmWV7$agecats)


summary(dmAB5$Q1001)
table(dmAB5$Q1001)
#this one is numeric.

dmAB5$age_short <- dmAB5$Q1001
dmAB5$age_short[dmAB5$Q1001 == 99999] <- NA
summary(dmAB5$age_short)

dmAB5$agecats[dmAB5$age_short < 30] <- 0
dmAB5$agecats[29 < dmAB5$age_short & dmAB5$age_short < 50] <- 1
dmAB5$agecats[dmAB5$age_short > 49] <- 2
table(dmAB5$agecats)
table(dmAB5$age_short, dmAB5$agecats)



#remove.packages("rlang")
#remove.packages("dplyr")

#install.packages("rlang")
#install.packages("dplyr")



library(dplyr)

################################################
###################EDUCATION####################
################################################

table(dmAB5$Q1003)
table(dmAB5$Q1003, dmAB5$country)

dmAB5$education <- as.numeric(dmAB5$Q1003)
table(dmAB5$education)
dmAB5$Educ[dmAB5$education == 1] <- 0
dmAB5$Educ[dmAB5$education == 2] <- 1
dmAB5$Educ[dmAB5$education == 3] <- 1
dmAB5$Educ[dmAB5$education == 4] <- 2
dmAB5$Educ[dmAB5$education == 5] <- 3
dmAB5$Educ[dmAB5$education == 6] <- 3
dmAB5$Educ[dmAB5$education == 7] <- 3
dmAB5$Educ[dmAB5$education == 8] <- NA
dmAB5$Educ[dmAB5$education == 9] <- NA

table(dmAB5$Educ)
summary(dmAB5$Educ)
table(dmAB5$country, dmAB5$Educ)

# 0 - No, 1 - Primary, 2 - Secondary, 3 - Tertiary

dmAB5$Educcats[dmAB5$Educ < 3] <- 0
dmAB5$Educcats[dmAB5$Educ == 3] <- 1
table(dmAB5$Educcats, dmAB5$Educ)


table(dmWV7$Q275)

dmWV7$educ <- as.numeric(dmWV7$Q275)
table(dmWV7$educ)
dmWV7$Educ[dmWV7$educ == 1] <- 0
dmWV7$Educ[dmWV7$educ == 2] <- 1
dmWV7$Educ[dmWV7$educ == 3] <- 2
dmWV7$Educ[dmWV7$educ == 4] <- 2
dmWV7$Educ[dmWV7$educ == 5] <- 2
dmWV7$Educ[dmWV7$educ == 6] <- 3
dmWV7$Educ[dmWV7$educ == 7] <- 3
dmWV7$Educ[dmWV7$educ == 8] <- 3
dmWV7$Educ[dmWV7$educ == 9] <- 3

table(dmWV7$Educ)
summary(dmWV7$Educ)

# 0 - No, 1 - Primary, 2 - Secondary, 3 - Tertiary

dmWV7$Educcats[dmWV7$Educ < 3] <- 0
dmWV7$Educcats[dmWV7$Educ == 3] <- 1
table(dmWV7$Educcats, dmWV7$Educ)



################################################
###################MARITAL STATUS###############
################################################

table(dmAB5$Q1010)
dmAB5$marit <- as.numeric(dmAB5$Q1010)
table(dmAB5$marit)
dmAB5$Mar[dmAB5$marit == 1] <- 1
dmAB5$Mar[dmAB5$marit == 2] <- 2
dmAB5$Mar[dmAB5$marit == 3] <- 2
dmAB5$Mar[dmAB5$marit == 4] <- 0
dmAB5$Mar[dmAB5$marit == 5] <- 2
dmAB5$Mar[dmAB5$marit == 6] <- 2
dmAB5$Mar[dmAB5$marit == 7] <- 2
dmAB5$Mar[dmAB5$marit == 8] <- NA
dmAB5$Mar[dmAB5$marit == 9] <- NA

table(dmAB5$Mar)

dmAB5$singled[dmAB5$Mar == 1] <- 1
dmAB5$singled[dmAB5$Mar == 0] <- 0
dmAB5$singled[dmAB5$Mar == 2] <- 0

dmAB5$othermaritald[dmAB5$Mar == 2] <- 1
dmAB5$othermaritald[dmAB5$Mar == 0] <- 0
dmAB5$othermaritald[dmAB5$Mar == 1] <- 0

table(dmAB5$singled)
table(dmAB5$othermaritald)

# 0 - married, 1 - single, 2 other

table(dmWV7$Q273)
dmWV7$marit <- as.numeric(dmWV7$Q273)
table(dmWV7$marit)
dmWV7$Mar[dmWV7$marit == 1] <- 0
dmWV7$Mar[dmWV7$marit == 2] <- 2
dmWV7$Mar[dmWV7$marit == 3] <- 2
dmWV7$Mar[dmWV7$marit == 4] <- 2
dmWV7$Mar[dmWV7$marit == 5] <- 2
dmWV7$Mar[dmWV7$marit == 6] <- 1
table(dmWV7$Mar)

dmWV7$singled[dmWV7$Mar == 1] <- 1
dmWV7$singled[dmWV7$Mar == 0] <- 0
dmWV7$singled[dmWV7$Mar == 2] <- 0

dmWV7$othermaritald[dmWV7$Mar == 2] <- 1
dmWV7$othermaritald[dmWV7$Mar == 0] <- 0
dmWV7$othermaritald[dmWV7$Mar == 1] <- 0

table(dmWV7$singled)
table(dmWV7$othermaritald)

# 0 - married, 1 - single, 2 other

################################################
#################EMPLOYMENT STATUS##############
################################################

table(dmAB5$Q1005)
dmAB5$empl <- as.numeric(dmAB5$Q1005)
table(dmAB5$empl)
dmAB5$Empl[dmAB5$empl == 1] <- 1
dmAB5$Empl[dmAB5$empl == 2] <- 1
dmAB5$Empl[dmAB5$empl == 3] <- 0
dmAB5$Empl[dmAB5$empl == 4] <- 0
dmAB5$Empl[dmAB5$empl == 5] <- 0
dmAB5$Empl[dmAB5$empl == 6] <- 0
dmAB5$Empl[dmAB5$empl == 7] <- 0
dmAB5$Empl[dmAB5$empl == 8] <- NA
dmAB5$Empl[dmAB5$empl == 9] <- NA

table(dmAB5$Empl)

table(dmWV7$Q279)
dmWV7$empl <- as.numeric(dmWV7$Q279)
table(dmWV7$empl)
dmWV7$Empl[dmWV7$empl == 1] <- 1
dmWV7$Empl[dmWV7$empl == 2] <- 1
dmWV7$Empl[dmWV7$empl == 3] <- 1
dmWV7$Empl[dmWV7$empl == 4] <- 0
dmWV7$Empl[dmWV7$empl == 5] <- 0
dmWV7$Empl[dmWV7$empl == 6] <- 0
dmWV7$Empl[dmWV7$empl == 7] <- 0
dmWV7$Empl[dmWV7$empl == 8] <- 0

table(dmWV7$Empl)

################################################
#################ID#############################
################################################

table(dmAB5$Survey)
dmAB5$Survey <- rep("AB", 12061)
table(dmWV7$Survey)
dmWV7$Survey <- rep("WVS", 6011)

dmAB5$id <- c(1:12061)
summary(dmAB5$id)
length(dmWV7$Survey)
dmWV7$id <- c(12062:18072)
summary(dmWV7$id)






















##################################################################################################################
##################################################################################################################
######################################################2013########################################################
##################################################################################################################
##################################################################################################################




################################################
#############PREPARING THE DATA#################
################################################

#AB3
AB3 <-  read.spss("C:/Uni/Data/ABIII_English.sav",use.value.labels=T, to.data.frame = T)
#AB3 <-  read.spss("C:/Users/u265173/OneDrive/AB v WVS w Veronica/ABIII_English.sav",use.value.labels=T, to.data.frame = T)

table(AB3$country)
dmAB3 <- subset(AB3, AB3$country!= "Sudan")
dmAB3$country<-droplevels(dmAB3$country)
table(dmAB3$country)

dmAB3$Surveytype <- 1
table(dmAB3$Surveytype)

#WVS6
WV6 <-  read.spss("C:/Uni/Data/WV6_full.sav",use.value.labels=T, to.data.frame = T)
#WV6 <-  read.spss("C:/Users/u265173/OneDrive/AB v WVS w Veronica/WV6_full.sav",use.value.labels=T, to.data.frame = T)
table(WV6$V2)
dmWV6 <- subset(WV6, WV6$V2=="Algeria" |WV6$V2=="Egypt" | WV6$V2=="Iraq"| WV6$V2=="Jordan"| 
                  WV6$V2=="Kuwait"| WV6$V2=="Lebanon"| WV6$V2=="Libya" |
                  WV6$V2=="Morocco" |WV6$V2== "Palestine"| WV6$V2== "Tunisia" | WV6$V2=="Yemen")
dmWV6$V2 <- droplevels(dmWV6$V2)
table(dmWV6$V2)

dmWV6$Surveytype <- 0
table(dmWV6$Surveytype)



##################################################################################################################
##################################################################################################################
##############################################PREPARING ATTITUDES#################################################
##################################################################################################################
##################################################################################################################

###############################################################
#################VARIABLE 1: GENERALIZED TRUST#################
###############################################################

######trust AB3
#Generally speaking, would you say that most people can be trusted?
#1 = Most people can be trusted
#2 = You must be very careful in dealing with people
#98 = Cant Choose/Don't know
#99 = Decline to Answer

summary(dmAB3$q103)

dmAB3$trustab <- as.numeric(dmAB3$q103)
table(dmAB3$trustab)
dmAB3$Trust[dmAB3$trustab == 2] <- 1
dmAB3$Trust[dmAB3$trustab == 3] <- 0
dmAB3$Trust[dmAB3$trustab == 1] <- NA
dmAB3$Trust[dmAB3$trustab == 4] <- NA
dmAB3$Trust[dmAB3$trustab == 5] <- NA
table(dmAB3$Trust)

# dmAB3$Trust: 0 - Most people are not trustworthy
# 1 - Most people are trustworthy

######trust WV6
#Generally speaking, would you say that most people
#can be trusted or that you need to be very careful in dealing with people?
#Most people can be trusted
#Need to be very careful
#No answer -> NA
#Don't know -> NA

summary(dmWV6$V24)

dmWV6$trustwvs <- as.numeric(dmWV6$V24)
table(dmWV6$trustwvs)
dmWV6$Trust[dmWV6$trustwvs == 1] <- 1
dmWV6$Trust[dmWV6$trustwvs == 2] <- 0
table(dmWV6$Trust)
#0 - Need to be very careful
# 1 - Most people can be trusted



###############################################################
#################VARIABLE 2: EDUCATIONAL GE####################
###############################################################

#AB#: q6014: A university education is more important 
#for a boy than a girl

summary(dmAB3$q6014)

dmAB3$unieducab <- as.numeric(dmAB3$q6014)
table(dmAB3$unieducab)
dmAB3$Unieduc[dmAB3$unieducab == 1] <- NA
dmAB3$Unieduc[dmAB3$unieducab == 2] <- 0
dmAB3$Unieduc[dmAB3$unieducab == 3] <- 0.33
dmAB3$Unieduc[dmAB3$unieducab == 4] <- 0.67
dmAB3$Unieduc[dmAB3$unieducab == 5] <- 1
dmAB3$Unieduc[dmAB3$unieducab == 6] <- NA
dmAB3$Unieduc[dmAB3$unieducab == 7] <- NA
table(dmAB3$Unieduc)
# Unieduc: 0 - Strongly agree, 1 - Strongly disagree

#WVS6 educge.
#V52: A university education is more 
#important for a boy than for a girl

summary(dmWV6$V52)

dmWV6$Unieduc <- as.numeric(dmWV6$V52)
table(dmWV6$Unieduc)
dmWV6$Unieduc[dmWV6$Unieduc == 1] <- 0
dmWV6$Unieduc[dmWV6$Unieduc == 2] <- 0.33
dmWV6$Unieduc[dmWV6$Unieduc == 3] <- 0.67
dmWV6$Unieduc[dmWV6$Unieduc == 4] <- 1

table(dmWV6$Unieduc)




###############################################################
#################VARIABLE 3: POLITICAL GE######################
###############################################################

#AB3 
#q6013: On the whole, men make better political leaders than women do
summary(dmAB3$q6013)

dmAB3$polleadab <- as.numeric(dmAB3$q6013)
table(dmAB3$polleadab)
dmAB3$PolLead[dmAB3$polleadab == 1] <- NA
dmAB3$PolLead[dmAB3$polleadab == 2] <- 0
dmAB3$PolLead[dmAB3$polleadab == 3] <- 0.33
dmAB3$PolLead[dmAB3$polleadab == 4] <- 0.67
dmAB3$PolLead[dmAB3$polleadab == 5] <- 1
dmAB3$PolLead[dmAB3$polleadab == 6] <- NA
dmAB3$PolLead[dmAB3$polleadab == 7] <- NA
table(dmAB3$PolLead)

#WVS6
#political GE wvs6.
#V51: On the whole, men make better political leaders than women do

#V51
summary(dmWV6$V51)

dmWV6$poleducwvs <- as.numeric(dmWV6$V51)
table(dmWV6$poleduc)
dmWV6$PolLead[dmWV6$poleducwvs == 1] <- 0
dmWV6$PolLead[dmWV6$poleducwvs == 2] <- 0.33
dmWV6$PolLead[dmWV6$poleducwvs == 3] <- 0.67
dmWV6$PolLead[dmWV6$poleducwvs == 4] <- 1

table(dmWV6$PolLead)




###############################################################
##############VARIABLE 4: TRUST IN POLICE######################
###############################################################
#AB3 201: 4.
#I will name a number of institutions, and I would like you to tell me to 
#what extent you trust each of them:
#public security(the police)

summary(dmAB3$q2014)
dmAB3$trustpol <-as.numeric(dmAB3$q2014)
table(dmAB3$trustpol)
dmAB3$Trustpol[dmAB3$trustpol == 1] <- NA
dmAB3$Trustpol[dmAB3$trustpol == 2] <- 1
dmAB3$Trustpol[dmAB3$trustpol == 3] <- 0.67
dmAB3$Trustpol[dmAB3$trustpol == 4] <- 0.33
dmAB3$Trustpol[dmAB3$trustpol == 5] <- 0
dmAB3$Trustpol[dmAB3$trustpol == 6] <- NA
dmAB3$Trustpol[dmAB3$trustpol == 7] <- NA
table(dmAB3$Trustpol)
table(dmAB3$Trustpol,dmAB3$q2014)
#0 - don't trust; 1 - trust to great extent

#WVS6
#ConfidencE: The police
summary(dmWV6$V113)
dmWV6$trustpol <- as.numeric(dmWV6$V113)
table(dmWV6$trustpol)
dmWV6$Trustpol[dmWV6$trustpol == 1] <- 1
dmWV6$Trustpol[dmWV6$trustpol == 2] <- 0.67
dmWV6$Trustpol[dmWV6$trustpol == 3] <- 0.33
dmWV6$Trustpol[dmWV6$trustpol == 4] <- 0
table(dmWV6$Trustpol)
#0 - no trust at all; 1 - trust to great extent





##################################################################################################################
##################################################################################################################
##############################################PREPARING DEMOGRAPHICS##############################################
##################################################################################################################
##################################################################################################################

################################################
#################COUNTRY########################
################################################

table(dmAB3$country)
dmWV6$country <- as.factor(dmWV6$V2)

table (dmAB3$country)
table (dmWV6$country)




################################################
#################GENDER#########################
################################################

table(dmAB3$sex)
dmAB3$gender[dmAB3$sex == "Male"] <- 0
dmAB3$gender[dmAB3$sex == "Female"] <- 1
table(dmAB3$sex, dmAB3$gender)

#0 - male, 1 - female

table(dmWV6$V240)
dmWV6$gender[dmWV6$V240 == "Male"] <- 0
dmWV6$gender[dmWV6$V240 == "Female"] <- 1
table(dmWV6$V240, dmWV6$gender)


################################################
###################AGE##########################
################################################

table(dmWV6$V242)
summary(dmWV6$V242)
#not numeric again.

dmWV6$age_short <- as.numeric(paste(dmWV6$V242))
summary(dmWV6$age_short)

dmWV6$agecats[dmWV6$age_short < 30] <- 0
dmWV6$agecats[29 < dmWV6$age_short & dmWV6$age_short < 50] <- 1
dmWV6$agecats[dmWV6$age_short > 49] <- 2
table(dmWV6$agecats)
table(dmWV6$age_short, dmWV6$agecats)


table(dmAB3$q1001)
summary(dmAB3$q1001)
#also not numeric

dmAB3$age_short <- as.numeric(paste(dmAB3$q1001))
summary(dmAB3$age_short)

dmAB3$agecats[dmAB3$age_short < 30] <- 0
dmAB3$agecats[29 < dmAB3$age_short & dmAB3$age_short < 50] <- 1
dmAB3$agecats[dmAB3$age_short > 49] <- 2
table(dmAB3$agecats)
table(dmAB3$age_short, dmAB3$agecats)

#library(rlang)
#library(dplyr)


################################################
###################EDUCATION####################
################################################

table(dmAB3$q1003)
dmAB3$education <- as.numeric(dmAB3$q1003)
table(dmAB3$education)
dmAB3$edunew <- rep(NA,13609)
dmAB3$edunew <-
  case_when(
    dmAB3$education == 1 ~ 99, 
    dmAB3$education == 2 ~ 0,
    dmAB3$education == 3 ~ 1,
    dmAB3$education == 4 ~ 1,
    dmAB3$education == 5 ~ 2,
    dmAB3$education == 6 ~ 2,
    dmAB3$education == 7 ~ 3, 
    dmAB3$education == 8 ~ 3,
    dmAB3$education == 9 ~ 99)

table(dmAB3$edunew)
table(dmAB3$country, dmAB3$edunew)

# 0 - No, 1 - Primary, 2 - Secondary, 3 - Tertiary

# Tunisia
table(dmAB3$q1003t)
dmAB3$eductun <- as.numeric(dmAB3$q1003t)
table(dmAB3$eductun)
dmAB3$edunewtun <-
  case_when(
    dmAB3$eductun == 2 ~ 0,
    dmAB3$eductun == 3 ~ 1,
    dmAB3$eductun == 4 ~ 1,
    dmAB3$eductun == 5 ~ 2,
    dmAB3$eductun == 6 ~ 3)

table(dmAB3$edunewtun)
table(dmAB3$eductun, dmAB3$q1003t)
table(dmAB3$edunewtun, dmAB3$q1003t)


#Yemen
table(dmAB3$q1003yem)

dmAB3$educyem <- as.numeric(dmAB3$q1003yem)
table(dmAB3$educyem)
dmAB3$edunewyem <-
  case_when(
    dmAB3$educyem == 1 ~ 99, 
    dmAB3$educyem == 2 ~ 0,
    dmAB3$educyem == 3 ~ 1,
    dmAB3$educyem == 4 ~ 1,
    dmAB3$educyem == 5 ~ 1,
    dmAB3$educyem == 6 ~ 2,
    dmAB3$educyem == 7 ~ 2,
    dmAB3$educyem == 8 ~ 3,
    dmAB3$educyem == 9 ~ 3)

table(dmAB3$edunewyem)

#Adding info on educ in Yemen and Tunisia to edunew variable in dmAB3
table(dmAB3$country, dmAB3$edunew)
table(dmAB3$country, dmAB3$edunewyem)
table(dmAB3$country, dmAB3$edunewtun)
is.factor(dmAB3$edunewtun)

dmAB3$edunew <- as.factor(dmAB3$edunew)
dmAB3$edunewyem <- as.factor(dmAB3$edunewyem)
dmAB3$edunewtun <- as.factor(dmAB3$edunewtun)
levels(dmAB3$edunew) 
levels(dmAB3$edunewyem)
levels(dmAB3$edunewtun)

table(dmAB3$edunewyem)
table(dmAB3$edunewtun)
dmAB3$Educ <- dmAB3$edunew
table(dmAB3$Educ)
dmAB3$Educ[dmAB3$edunewtun == "0"] <- "0"
dmAB3$Educ[dmAB3$edunewtun == "1"] <- "1"
dmAB3$Educ[dmAB3$edunewtun == "2"] <- "2"
dmAB3$Educ[dmAB3$edunewtun == "3"] <- "3"
dmAB3$Educ[dmAB3$edunewyem == "0"] <- "0"
dmAB3$Educ[dmAB3$edunewyem == "1"] <- "1"
dmAB3$Educ[dmAB3$edunewyem == "2"] <- "2"
dmAB3$Educ[dmAB3$edunewyem == "3"] <- "3"
dmAB3$Educ[dmAB3$edunewyem == "99"] <- "99"
table(dmAB3$country, dmAB3$Educ)
table(dmAB3$country,dmAB3$edunewyem)
table(dmAB3$country,dmAB3$edunewtun)

table(dmAB3$Educ)
dmAB3$Educ[dmAB3$Educ == 99] <- NA
table(dmAB3$Educ)

summary(dmAB3$Educ)
dmAB3$Educ <- (as.numeric(dmAB3$Educ) - 1)
table(dmAB3$Educ)
summary(dmAB3$Educ)

dmAB3$Educcats[dmAB3$Educ < 3] <- 0
dmAB3$Educcats[dmAB3$Educ == 3] <- 1
table(dmAB3$Educcats, dmAB3$Educ)



###WVS

table(dmWV6$V248)
#no 0s in NA scores in MENA sample.

summary(dmWV6$V248)


dmWV6$educ <- as.numeric(dmWV6$V248)
table(dmWV6$educ)
dmWV6$Educ <-
  case_when(
    dmWV6$educ == 1 ~ 0, 
    dmWV6$educ == 2 ~ 0,
    dmWV6$educ == 3 ~ 1,
    dmWV6$educ == 4 ~ 1,
    dmWV6$educ == 5 ~ 2,
    dmWV6$educ == 6 ~ 1,
    dmWV6$educ == 7 ~ 2,
    dmWV6$educ == 8 ~ 2,
    dmWV6$educ == 9 ~ 3)

table(dmWV6$Educ)
summary(dmWV6$Educ)

dmWV6$Educcats[dmWV6$Educ < 3] <- 0
dmWV6$Educcats[dmWV6$Educ == 3] <- 1
table(dmWV6$Educcats, dmWV6$Educ)


########Not changed
#educational categories for descriptives.
#dmAB3$Educcats[dmAB3$Education == 0] <- 0
#dmAB3$Educcats[dmAB3$Education == 1] <- 0
#dmAB3$Educcats[dmAB3$Education == 2] <- 0
#dmAB3$Educcats[dmAB3$Education == 3] <- 1
#table(dmAB3$Educcats)
#table(dmAB3$Education, dmAB3$Educcats)

#educational category with secondary and tertiary to check for tertiary small sample size.
#dmAB3$Educcats2[dmAB3$Education == 0] <- 0
#dmAB3$Educcats2[dmAB3$Education == 1] <- 0
#dmAB3$Educcats2[dmAB3$Education == 2] <- 1
#dmAB3$Educcats2[dmAB3$Education == 3] <- 1
#table(dmAB3$Educcats2)
#table(dmAB3$Education, dmAB3$Educcats2)


################################################
###################MARITAL STATUS###############
################################################

table(dmAB3$q1010)
dmAB3$marit <- as.numeric(dmAB3$q1010)
table(dmAB3$marit)
dmAB3$Mar <-
  case_when(
    dmAB3$marit == 1 ~ 99, 
    dmAB3$marit == 2 ~ 1,
    dmAB3$marit == 3 ~ 0,
    dmAB3$marit == 4 ~ 2,
    dmAB3$marit == 5 ~ 2,
    dmAB3$marit == 6 ~ 2,
    dmAB3$marit == 7 ~ 99)

table(dmAB3$Mar)
dmAB3$Mar[dmAB3$Mar == 99] <- NA
table(dmAB3$Mar)
summary(dmAB3$Mar)
dmAB3$Mar <- as.factor(dmAB3$Mar)


table(dmWV6$V57)
dmWV6$marit <- as.numeric(dmWV6$V57)
table(dmWV6$marit)
dmWV6$Mar <-
  case_when(
    dmWV6$marit == 1 ~ 0, 
    dmWV6$marit == 2 ~ 2,
    dmWV6$marit == 3 ~ 2,
    dmWV6$marit == 4 ~ 2,
    dmWV6$marit == 5 ~ 2,
    dmWV6$marit == 6 ~ 1)

table(dmWV6$Mar)
summary(dmWV6$Mar)
dmWV6$Mar <- as.factor(dmWV6$Mar)

# 0 - married, 1 - single, 2 other

dmAB3$singled[dmAB3$Mar == 1] <- 1
dmAB3$singled[dmAB3$Mar == 0] <- 0
dmAB3$singled[dmAB3$Mar == 2] <- 0

dmAB3$othermaritald[dmAB3$Mar == 2] <- 1
dmAB3$othermaritald[dmAB3$Mar == 0] <- 0
dmAB3$othermaritald[dmAB3$Mar == 1] <- 0


dmWV6$singled[dmWV6$Mar == 1] <- 1
dmWV6$singled[dmWV6$Mar == 0] <- 0
dmWV6$singled[dmWV6$Mar == 2] <- 0

dmWV6$othermaritald[dmWV6$Mar == 2] <- 1
dmWV6$othermaritald[dmWV6$Mar == 0] <- 0
dmWV6$othermaritald[dmWV6$Mar == 1] <- 0


################################################
#################EMPLOYMENT STATUS##############
################################################

table(dmAB3$q1004)
dmAB3$empl <- as.numeric(dmAB3$q1004)
table(dmAB3$empl)
dmAB3$Empl <-
  case_when(
    dmAB3$empl == 1 ~ 99, 
    dmAB3$empl == 2 ~ 1,
    dmAB3$empl == 3 ~ 0,
    dmAB3$empl == 4 ~ 99)

table(dmAB3$Empl)
dmAB3$Empl[dmAB3$Empl == 99] <- NA
table(dmAB3$Empl)

table(dmWV6$V229)
dmWV6$empl <- as.numeric(dmWV6$V229)
table(dmWV6$empl)
dmWV6$Empl <-
  case_when(
    dmWV6$empl == 1 ~ 1, 
    dmWV6$empl  == 2 ~ 1,
    dmWV6$empl  == 3 ~ 1,
    dmWV6$empl  == 4 ~ 0,
    dmWV6$empl  == 5 ~ 0,
    dmWV6$empl  == 6 ~ 0, 
    dmWV6$empl  == 7 ~ 0, 
    dmWV6$empl  == 8 ~ 0)

table(dmWV6$Empl)

################################################
#################ID#############################
################################################

dmAB3$Survey <- rep("AB", 13609)
table(dmAB3$Survey)
dmWV6$Survey <- rep("WVS", 14162)
table(dmWV6$Survey)

dmAB3$id <- c(1:13609)
summary(dmAB3$id)
length(dmWV6$Survey)
dmWV6$id <- c(13610:27771)
summary(dmWV6$id)






##################################################################################################################
##################################################################################################################
##############################################MERGING 2013 AND 2016###############################################
##################################################################################################################
##################################################################################################################

dmAB3$surveyyear <- 1
dmWV6$surveyyear <- 2
dmAB5$surveyyear <- 3
dmWV7$surveyyear <- 4


ABWVS2013 <- merge(dmAB3, dmWV6, by= c("Surveytype", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                       "age_short", "agecats", "Educcats",
                                       "gender", "country", 
                                       "Trust", "Unieduc", "PolLead", "Trustpol", "surveyyear"), all=TRUE)

ABWVS2018 <- merge(dmAB5, dmWV7, by= c("Surveytype", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                   "age_short","agecats", "Educcats",
                                   "gender", "country", 
                                   "Trust", "Unieduc", "PolLead", "Trustpol", "surveyyear"), all=TRUE)

ABWVS20132018 <- merge(ABWVS2013, ABWVS2018, by= c("Surveytype", "Empl", "Mar", "Educ", "singled", "othermaritald",
                                   "age_short","agecats", "Educcats",
                                   "gender", "country", 
                                   "Trust", "Unieduc", "PolLead", "Trustpol", "surveyyear"), all=TRUE)


ABonly <- merge(dmAB3, dmAB5, by= c("Surveytype", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                       "age_short", "agecats", "Educcats",
                                       "gender", "country", 
                                       "Trust", "Unieduc", "PolLead", "Trustpol", "surveyyear"), all=TRUE)

WVSonly <- merge(dmWV7, dmWV6, by= c("Surveytype", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                    "age_short", "agecats", "Educcats",
                                    "gender", "country", 
                                    "Trust", "Unieduc", "PolLead", "Trustpol", "surveyyear"), all=TRUE)


ABWVS20132018$year[ABWVS20132018$surveyyear < 3] <- 2013
ABWVS20132018$year[ABWVS20132018$surveyyear > 2] <- 2018
table(ABWVS20132018$year)

table(ABWVS20132018$surveyyear)
table(ABWVS20132018$Trustpol, ABWVS20132018$Surveytype)

table(ABWVS20132018$Surveytype)
ABWVS20132018$Surveytype2[ABWVS20132018$Surveytype == 0] <- 1
ABWVS20132018$Surveytype2[ABWVS20132018$Surveytype == 1] <- 0
table(ABWVS20132018$Surveytype, ABWVS20132018$Surveytype2)

table(ABWVS2013$Surveytype)
ABWVS2013$Surveytype2[ABWVS2013$Surveytype == 0] <- 1
ABWVS2013$Surveytype2[ABWVS2013$Surveytype == 1] <- 0
table(ABWVS2013$Surveytype, ABWVS2013$Surveytype2)

table(ABWVS20132018$Mar)
ABWVS20132018$Mar2[ABWVS20132018$Mar == 0] <- 0
ABWVS20132018$Mar2[ABWVS20132018$Mar == 1] <- 1
ABWVS20132018$Mar2[ABWVS20132018$Mar == 2] <- 1
table(ABWVS20132018$Mar, ABWVS20132018$Mar2)

table(ABWVS20132018$Trustpol, ABWVS20132018$Surveytype)

##################################################################################################################
##################################################################################################################
###############################################MISSINGNESS PATTERNS###############################################
##################################################################################################################
##################################################################################################################

table(ABWVS20132018$year)
27771+18072
#45843 total.

table(ABWVS20132018$Trust)
36045+8557
sum(is.na(ABWVS20132018$Trust))

table(ABWVS20132018$Trustpol)
6685 + 8991 + 14660 + 13321 
sum(is.na(ABWVS20132018$Trustpol))

table(ABWVS20132018$Unieduc)
5013  + 6335 + 16218 + 17598 
sum(is.na(ABWVS20132018$Unieduc))

table(ABWVS20132018$PolLead)
16631 + 14098 + 9620  + 4416 
sum(is.na(ABWVS20132018$PolLead))


table(WVSonly$Surveytype)
#20173 total

sum(is.na(WVSonly$Trust))
sum(is.na(WVSonly$Trustpol))
sum(is.na(WVSonly$Unieduc))
sum(is.na(WVSonly$PolLead))

table(ABonly$Surveytype)
#25670 total

sum(is.na(ABonly$Trust))
sum(is.na(ABonly$Trustpol))
sum(is.na(ABonly$Unieduc))
sum(is.na(ABonly$PolLead))

table(WVSonly$Trust, WVSonly$country, WVSonly$surveyyear, exclude = NULL)
table(WVSonly$Trustpol, WVSonly$country, WVSonly$surveyyear, exclude = NULL)
table(WVSonly$Unieduc, WVSonly$country, WVSonly$surveyyear, exclude = NULL)
table(WVSonly$PolLead, WVSonly$country, WVSonly$surveyyear, exclude = NULL)

table(ABonly$Trust, ABonly$country, ABonly$surveyyear, exclude = NULL)
table(ABonly$Trustpol, ABonly$country, ABonly$surveyyear, exclude = NULL)
table(ABonly$Unieduc, ABonly$country, ABonly$surveyyear, exclude = NULL)
table(ABonly$PolLead, ABonly$country, ABonly$surveyyear, exclude = NULL)

table(ABWVS20132018$Trust, ABWVS20132018$country, ABWVS20132018$year, exclude = NULL)
table(ABWVS20132018$Trustpol, ABWVS20132018$country, ABWVS20132018$year, exclude = NULL)
table(ABWVS20132018$Unieduc, ABWVS20132018$country, ABWVS20132018$year, exclude = NULL)
table(ABWVS20132018$PolLead, ABWVS20132018$country, ABWVS20132018$year, exclude = NULL)




##################################################################################################################
##################################################################################################################
###########################################RE-CHECKING TUNISIA 2013 MODELS########################################
##################################################################################################################
##################################################################################################################

Tunisia2013 <- ABWVS2013[ABWVS2013$country == "Tunisia",]
table(Tunisia2013$country)
table(Tunisia2013$surveyyear)

library(lme4)

mTunisia20131a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = Tunisia2013, family = binomial)
summary(mTunisia20131a)

mTunisia20131b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = Tunisia2013, family = binomial)
summary(mTunisia20131b)

mTunisia20131c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = Tunisia2013, family = binomial)
summary(mTunisia20131c)

mTunisia20131c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = Tunisia2013, family = binomial)
summary(mTunisia20131c2)

mTunisia20131d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013, family = binomial)
summary(mTunisia20131d)

mTunisia20131d2 <- glm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013, family = binomial)
summary(mTunisia20131d2)

mTunisia20131e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013, family = binomial)
summary(mTunisia20131e)

mTunisia20131f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013, family = binomial)
summary(mTunisia20131f)


table(Tunisia2013$Unieduc)
table(Tunisia2013$country)

mTunisia20132b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132b)

mTunisia20132b2 <- lm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132b2)

mTunisia20132c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132c)

mTunisia20132c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132c2)

mTunisia20132d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132d)

mTunisia20132e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132e)

mTunisia20132f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20132f)

table(Tunisia2013$PolLead)
table(Tunisia2013$country)

mTunisia20133b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133b)

mTunisia20133c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133c)

mTunisia20133c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133c2)

mTunisia20133d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133d)

mTunisia20133d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133d2)

mTunisia20133e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013)
summary(mTunisia20133e)

mTunisia20133f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133f)

mTunisia20133f2 <- lm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20133f2)

table(Tunisia2013$Trustpol)
table(Tunisia2013$country)

mTunisia20134b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134b2)

mTunisia20134b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134b)

mTunisia20134c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134c)

mTunisia20134d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134d)

mTunisia20134d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134d2)

mTunisia20134e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013)
summary(mTunisia20134e)

mTunisia20134f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134f)

mTunisia20134f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = Tunisia2013)
summary(mTunisia20134f2)








##################################################################################################################
##################################################################################################################
################################################WEIGHTED ANALYSES#################################################
##################################################################################################################
##################################################################################################################




##################################################################################################################
##################################################################################################################
######################################CREATING WEIGHTS ALGERIA 2013###############################################
##################################################################################################################
##################################################################################################################



table (ABWVS20132018$country)
table (ABWVS20132018$year)

Algeria2013 <- ABWVS20132018[ABWVS20132018$country == "Algeria" & ABWVS20132018$year == 2013,]
table(Algeria2013$country)
table(Algeria2013$year)

Algeria2013$weightcats <- 99999
table(Algeria2013$weightcats)

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	1
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	2
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	3
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	4
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	5
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	6

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	7
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	8
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	9
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	10
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	11
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	12

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	13
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	14
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	15
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	16
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	17
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	18

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	19
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	20
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	21
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	22
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	23
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 0 ]	<-	24

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	25
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	26
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	27
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	28
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	29
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	30

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	31
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	32
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	33
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	34
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	35
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	36

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	37
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	38
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	39
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	40
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	41
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	42

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	43
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	44
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	45
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	46
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	47
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 0 ]	<-	48



Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	49
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	50
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	51
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	52
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	53
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	54

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	55
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	56
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	57
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	58
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	59
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	60

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	61
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	62
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	63
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	64
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	65
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	66

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	67
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	68
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	69
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	70
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	71
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==0 & Algeria2013$Surveytype == 1 ]	<-	72

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	73
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	74
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	75
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	76
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	77
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	78

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	79
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	80
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	81
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	82
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	83
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==0 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	84

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	85
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	86
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	87
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	88
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	89
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==0 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	90

Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	91
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==0 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	92
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	93
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==1 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	94
Algeria2013$weightcats[Algeria2013$gender == 0 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	95
Algeria2013$weightcats[Algeria2013$gender == 1 & Algeria2013$agecats ==2 & Algeria2013$Educcats ==1 & Algeria2013$Mar2 ==1 & Algeria2013$Empl ==1 & Algeria2013$Surveytype == 1 ]	<-	96

table(Algeria2013$weightcats)

Algeria2013nomiss <- Algeria2013[Algeria2013$weightcats != 99999,]
table(Algeria2013nomiss$weightcats)

prop.table(table(Algeria2013nomiss$weightcats, Algeria2013nomiss$Surveytype))
#cats without respondents: 9	23	24	31	47	48	55	57	59	60	71	72	74	79	84	89	95	96

Algeria2013nomiss$weightcats[Algeria2013nomiss$weightcats == 9 & Algeria2013nomiss$weightcats == 23 & Algeria2013nomiss$weightcats == 24 & Algeria2013nomiss$weightcats == 31 & Algeria2013nomiss$weightcats == 47 & Algeria2013nomiss$weightcats == 48 & Algeria2013nomiss$weightcats == 55 & Algeria2013nomiss$weightcats == 57 & Algeria2013nomiss$weightcats == 59 & Algeria2013nomiss$weightcats == 60 & Algeria2013nomiss$weightcats == 71 & Algeria2013nomiss$weightcats == 72 & Algeria2013nomiss$weightcats == 74 & Algeria2013nomiss$weightcats == 79 & Algeria2013nomiss$weightcats == 84 & Algeria2013nomiss$weightcats == 89 & Algeria2013nomiss$weightcats == 95 & Algeria2013nomiss$weightcats == 96] <- NA
table(Algeria2013nomiss$weightcats)

Algeria13.distribution <- data.frame(weightcats = c("1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"73", 	"75", 	"76", 	"77", 	"78", 	"80", 	"81", 	"82", 	"83", 	"85", 	"86", 	"87", 	"88", 	"90", 	"91", 	"92", 	"93", 	"94"), 
Freq = nrow(Algeria2013nomiss) * c(	0.0008267879, 	0.0070276974, 	0.0057875155, 	0.0442331542, 	0.0198429103, 	0.0322447292, 	0.000413394, 	0.0008267879, 	0.0008267879, 	0.000413394, 	0.000413394, 	0.046713518, 	0.0661430343, 	0.0086812733, 	0.0186027284, 	0.0103348491, 	0.011988425, 	0.0074410914, 	0.0086812733, 	0.0020669698, 	0.0024803638, 	0.0028937578, 	0.0041339396, 	0.0595287309, 	0.0140553948, 	0.0194295163, 	0.0033071517, 	0.0008267879, 	0.0082678793, 	0.0045473336, 	0.0020669698, 	0.000413394, 	0.0202563043, 	0.0099214551, 	0.0252170318, 	0.0099214551, 	0.0049607276, 	0.0012401819, 	0.0024803638, 	0.000413394, 	0.0033071517, 	0.0024803638, 	0.0008267879, 	0.0070276974, 	0.0057875155, 	0.0442331542, 	0.0198429103, 	0.0322447292, 	0.0008267879, 	0.0008267879, 	0.046713518, 	0.0661430343, 	0.0086812733, 	0.0186027284, 	0.0103348491, 	0.011988425, 	0.0074410914, 	0.0086812733, 	0.0020669698, 	0.0024803638, 	0.0028937578, 	0.0595287309, 	0.0140553948, 	0.0194295163, 	0.0033071517, 	0.0008267879, 	0.0082678793, 	0.0045473336, 	0.0020669698, 	0.0202563043, 	0.0099214551, 	0.0252170318, 	0.0099214551, 	0.0012401819, 	0.0024803638, 	0.000413394, 	0.0033071517, 	0.0024803638))

library(survey)

Algeria2013w <- svydesign(ids=~1, data = Algeria2013nomiss)

Algeria2013weighted <- rake(design = Algeria2013w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Algeria13.distribution))

table(Algeria2013nomiss$Surveytype)
svytable(~Surveytype, Algeria2013weighted)
#WORKED.

table(Algeria2013nomiss$gender)
svytable(~gender, Algeria2013weighted)
#worked.

table(Algeria2013nomiss$gender, Algeria2013nomiss$Surveytype)
svytable(~interaction(gender, Surveytype), design = Algeria2013weighted)
#WORKED.

##################################################################################################################
##################################################################################################################
########################################ANALYSES ALGERIA 2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(table(Algeria2013nomiss$Unieduc, Algeria2013nomiss$Surveytype), 2)

prop.table(svytable(~Trust, subset(Algeria2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Algeria2013weighted, Surveytype ==1)))

prop.table(svytable(~Unieduc, subset(Algeria2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Algeria2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Algeria2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Algeria2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Algeria2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Algeria2013weighted, Surveytype ==1))) 



#TRUST
mAlgeria2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21b)

mAlgeria2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21c)

mAlgeria2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21c2)

mAlgeria2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21d)

mAlgeria2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21d2)

mAlgeria2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21e)

mAlgeria2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21e2)

mAlgeria2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21f)

mAlgeria2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted, family = quasibinomial)
summary(mAlgeria2013weighted21f2)


#TRUST POL
mAlgeria20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Algeria2013nomiss)
summary(mAlgeria20132b)

mAlgeria2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24c)

mAlgeria2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24d)

mAlgeria2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24d2)

mAlgeria2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24e)

mAlgeria2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24f)

mAlgeria2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted24f2)


#EDUC GE
mAlgeria2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22b)

mAlgeria2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22b2)

mAlgeria2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22c)

mAlgeria2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22d)

mAlgeria2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22e)

mAlgeria2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22f)

mAlgeria2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted22f2)



#POL GE
mAlgeria20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Algeria2013nomiss)
summary(mAlgeria20132b)

mAlgeria2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted23c)

mAlgeria2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted23d)

mAlgeria2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted23e)

mAlgeria2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Algeria2013weighted)
summary(mAlgeria2013weighted23f)





##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS EGYPT 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Egypt2013 <- ABWVS20132018[ABWVS20132018$country == "Egypt" & ABWVS20132018$year == 2013,]
table(Egypt2013$country)
table(Egypt2013$year)

Egypt2013$weightcats <- 99999
table(Egypt2013$weightcats)

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	1
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	2
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	3
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	4
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	5
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	6

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	7
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	8
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	9
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	10
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	11
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	12

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	13
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	14
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	15
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	16
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	17
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	18

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	19
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	20
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	21
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	22
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	23
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 0 ]	<-	24

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	25
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	26
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	27
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	28
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	29
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	30

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	31
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	32
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	33
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	34
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	35
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	36

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	37
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	38
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	39
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	40
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	41
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	42

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	43
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	44
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	45
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	46
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	47
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 0 ]	<-	48



Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	49
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	50
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	51
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	52
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	53
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	54

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	55
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	56
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	57
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	58
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	59
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	60

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	61
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	62
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	63
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	64
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	65
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	66

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	67
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	68
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	69
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	70
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	71
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==0 & Egypt2013$Surveytype == 1 ]	<-	72

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	73
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	74
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	75
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	76
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	77
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	78

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	79
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	80
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	81
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	82
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	83
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==0 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	84

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	85
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	86
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	87
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	88
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	89
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==0 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	90

Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	91
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==0 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	92
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	93
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==1 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	94
Egypt2013$weightcats[Egypt2013$gender == 0 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	95
Egypt2013$weightcats[Egypt2013$gender == 1 & Egypt2013$agecats ==2 & Egypt2013$Educcats ==1 & Egypt2013$Mar2 ==1 & Egypt2013$Empl ==1 & Egypt2013$Surveytype == 1 ]	<-	96

table(Egypt2013$weightcats)

Egypt2013nomiss <- Egypt2013[Egypt2013$weightcats != 99999,]
table(Egypt2013nomiss$weightcats)

prop.table(table(Egypt2013nomiss$weightcats, Egypt2013nomiss$Surveytype))
#cats without respondents at all: 7	9	21	23	47	55	57	71	84
#cats without respondents in their accompanying WVS/AB countercategory: 69 36 95

Egypt2013nomiss2 <- Egypt2013nomiss[Egypt2013nomiss$weightcats != 69 & Egypt2013nomiss$weightcats != 36 & Egypt2013nomiss$weightcats != 95 ,]
table(Egypt2013nomiss2$weightcats)

#Egypt2013nomiss$weightcats[Egypt2013nomiss$weightcats == 7 & Egypt2013nomiss$weightcats == 9 & Egypt2013nomiss$weightcats == 21 & Egypt2013nomiss$weightcats == 23 & Egypt2013nomiss$weightcats == 47 & Egypt2013nomiss$weightcats == 55 & Egypt2013nomiss$weightcats == 57 & Egypt2013nomiss$weightcats == 71 & Egypt2013nomiss$weightcats == 84 ] <- NA
#table(Egypt2013nomiss$weightcats)

#Egypt2013nomiss$weightcats[Egypt2013nomiss$weightcats == 36 ] <- NA
#Egypt2013nomiss$weightcats[Egypt2013nomiss$weightcats == 69 ] <- NA
#Egypt2013nomiss$weightcats[Egypt2013nomiss$weightcats == 95 ] <- NA
#table(Egypt2013nomiss$weightcats)


Egypt13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"22", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"70", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"96"), 
 Freq = nrow(Egypt2013nomiss2) * c(  0.0007355645, 	0.0639941155, 	0.0033100405, 	0.1187936741, 	0.0158146377, 	0.0415593968, 	0.0055167341, 	0.0091945568, 	0.0022066936, 	0.0025744759, 	0.012136815, 	0.0246414123, 	0.0007355645, 	0.0154468555, 	0.0044133873, 	0.0467083487, 	0.004045605, 	0.0055167341, 	0.0014711291, 	0.0018389114, 	0.00809121, 	0.0018389114, 	0.044501655, 	0.0128723796, 	0.0275836705, 	0.0033100405, 	0.0018389114, 	0.0018389114, 	0.0136079441, 	0.00809121, 	0.0106656859, 	0.0136079441, 	0.0025744759, 	0.0077234277, 	0.0018389114, 	0.0025744759, 	0.0022066936, 	0.0051489518, 	0.0036778227, 	0.0014711291, 	0.0014711291, 	0.0003677823, 	0.0007355645, 	0.0639941155, 	0.0033100405, 	0.1187936741, 	0.0158146377, 	0.0415593968, 	0.0055167341, 	0.0091945568, 	0.0022066936, 	0.0025744759, 	0.012136815, 	0.0246414123, 	0.0007355645, 	0.0154468555, 	0.0044133873, 	0.0467083487, 	0.004045605, 	0.0055167341, 	0.0014711291, 	0.0018389114, 	0.00809121, 	0.0018389114, 	0.044501655, 	0.0128723796, 	0.0275836705, 	0.0033100405, 	0.0018389114, 	0.0018389114, 	0.0136079441, 	0.00809121, 	0.0106656859, 	0.0136079441, 	0.0025744759, 	0.0077234277, 	0.0018389114, 	0.0025744759, 	0.0022066936, 	0.0051489518, 	0.0036778227, 	0.0014711291, 	0.0014711291, 	0.0003677823))


library(survey)

Egypt2013w <- svydesign(ids=~1, data = Egypt2013nomiss2)

Egypt2013weighted <- rake(design = Egypt2013w,
                          sample.margins = list(~weightcats),
                          population.margins = list(Egypt13.distribution))

table(Egypt2013nomiss$Surveytype)
svytable(~Surveytype, Egypt2013weighted)
1523+1196
#WORKED.

table(Egypt2013nomiss$gender)
svytable(~gender, Egypt2013weighted)
#worked.

table(Egypt2013nomiss$gender, Egypt2013nomiss$Surveytype)
svytable(~interaction(gender, Surveytype), design = Egypt2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES EGYPT2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Egypt2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Egypt2013weighted, Surveytype ==1)))

prop.table(svytable(~Unieduc, subset(Egypt2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Egypt2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Egypt2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Egypt2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Egypt2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Egypt2013weighted, Surveytype ==1))) 



#TRUST
mEgypt2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21b)

mEgypt2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21c)

mEgypt2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21c2)

mEgypt2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21d)

mEgypt2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21d2)

mEgypt2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21e)

mEgypt2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21e2)

mEgypt2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21f)

mEgypt2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted, family = quasibinomial)
summary(mEgypt2013weighted21f2)


#TRUST POL
mEgypt20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt2013nomiss)
summary(mEgypt20132b)

mEgypt2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24c)

mEgypt2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24c2)

mEgypt2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24d)

mEgypt2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24d2)

mEgypt2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24e)

mEgypt2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24f)

mEgypt2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted24f2)


#EDUC GE
mEgypt2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22b)

mEgypt2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22b2)

mEgypt2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22c)

mEgypt2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22c2)

mEgypt2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22d)

mEgypt2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22e)

mEgypt2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22e2)

mEgypt2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22f)

mEgypt2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted22f2)



#POL GE
mEgypt20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt2013nomiss)
summary(mEgypt20132b)

mEgypt2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted23c)

mEgypt2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted23d)

mEgypt2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted23e)

mEgypt2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2013weighted)
summary(mEgypt2013weighted23f)






##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS IRAQ 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Iraq2013 <- ABWVS20132018[ABWVS20132018$country == "Iraq" & ABWVS20132018$year == 2013,]
table(Iraq2013$country)
table(Iraq2013$year)

Iraq2013$weightcats <- 99999
table(Iraq2013$weightcats)

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	1
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	2
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	3
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	4
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	5
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	6

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	7
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	8
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	9
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	10
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	11
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	12

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	13
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	14
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	15
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	16
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	17
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	18

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	19
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	20
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	21
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	22
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	23
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 0 ]	<-	24

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	25
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	26
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	27
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	28
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	29
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	30

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	31
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	32
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	33
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	34
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	35
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	36

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	37
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	38
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	39
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	40
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	41
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	42

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	43
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	44
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	45
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	46
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	47
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 0 ]	<-	48



Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	49
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	50
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	51
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	52
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	53
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	54

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	55
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	56
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	57
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	58
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	59
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	60

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	61
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	62
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	63
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	64
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	65
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	66

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	67
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	68
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	69
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	70
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	71
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==0 & Iraq2013$Surveytype == 1 ]	<-	72

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	73
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	74
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	75
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	76
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	77
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	78

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	79
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	80
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	81
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	82
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	83
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==0 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	84

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	85
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	86
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	87
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	88
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	89
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==0 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	90

Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	91
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==0 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	92
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	93
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==1 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	94
Iraq2013$weightcats[Iraq2013$gender == 0 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	95
Iraq2013$weightcats[Iraq2013$gender == 1 & Iraq2013$agecats ==2 & Iraq2013$Educcats ==1 & Iraq2013$Mar2 ==1 & Iraq2013$Empl ==1 & Iraq2013$Surveytype == 1 ]	<-	96

table(Iraq2013$weightcats)

Iraq2013nomiss <- Iraq2013[Iraq2013$weightcats != 99999,]
table(Iraq2013nomiss$weightcats)

prop.table(table(Iraq2013nomiss$weightcats, Iraq2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 24 71 48

Iraq2013nomiss2 <- Iraq2013nomiss[Iraq2013nomiss$weightcats != 24 & Iraq2013nomiss$weightcats != 71 & Iraq2013nomiss$weightcats != 48 ,]
table(Iraq2013nomiss2$weightcats)

Iraq13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"22", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"70", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94"),
                                      Freq = nrow(Iraq2013nomiss2) * c(	0.0074595939, 	0.0273518442, 	0.0165768753, 	0.0799834231, 	0.021135516, 	0.0285951098, 	0.0012432656, 	0.0012432656, 	0.0033153751, 	0.0029009532, 	0.0004144219, 	0.0406133444, 	0.0381268131, 	0.0008288438, 	0.0116038127, 	0.0020721094, 	0.0099461252, 	0.0049730626, 	0.0016576875, 	0.0004144219, 	0.0194778284, 	0.0033153751, 	0.0650642354, 	0.0091172814, 	0.0190634065, 	0.0004144219, 	0.0033153751, 	0.0016576875, 	0.0145047659, 	0.0095317033, 	0.0062163282, 	0.0008288438, 	0.024450891, 	0.0016576875, 	0.0033153751, 	0.0020721094, 	0.0004144219, 	0.0004144219, 	0.0049730626, 	0.0016576875, 	0.0020721094, 	0.0016576875, 	0.0074595939, 	0.0273518442, 	0.0165768753, 	0.0799834231, 	0.021135516, 	0.0285951098, 	0.0012432656, 	0.0012432656, 	0.0033153751, 	0.0029009532, 	0.0004144219, 	0.0406133444, 	0.0381268131, 	0.0008288438, 	0.0116038127, 	0.0020721094, 	0.0099461252, 	0.0049730626, 	0.0016576875, 	0.0004144219, 	0.0194778284, 	0.0033153751, 	0.0650642354, 	0.0091172814, 	0.0190634065, 	0.0004144219, 	0.0033153751, 	0.0016576875, 	0.0145047659, 	0.0095317033, 	0.0062163282, 	0.0008288438, 	0.024450891, 	0.0016576875, 	0.0033153751, 	0.0020721094, 	0.0004144219, 	0.0004144219, 	0.0049730626, 	0.0016576875, 	0.0020721094, 	0.0016576875))

library(survey)

Iraq2013w <- svydesign(ids=~1, data = Iraq2013nomiss2)

Iraq2013weighted <- rake(design = Iraq2013w,
                         sample.margins = list(~weightcats),
                         population.margins = list(Iraq13.distribution))

table(Iraq2013nomiss2$Surveytype)
svytable(~Surveytype, Iraq2013weighted)
#WORKED.

table(Iraq2013nomiss2$gender)
svytable(~gender, Iraq2013weighted)
#worked.

table(Iraq2013nomiss$gender, Iraq2013nomiss$Surveytype)
svytable(~interaction(gender, Surveytype), design = Iraq2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES IRAQ2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Iraq2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Iraq2013weighted, Surveytype ==1)))

prop.table(svytable(~Unieduc, subset(Iraq2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Iraq2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Iraq2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Iraq2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Iraq2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Iraq2013weighted, Surveytype ==1))) 



#TRUST
mIraq2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21b)

mIraq2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21c)

mIraq2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21c2)

mIraq2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21d)

mIraq2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21d2)

mIraq2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21e)

mIraq2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21e2)

mIraq2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21f)

mIraq2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted, family = quasibinomial)
summary(mIraq2013weighted21f2)


#TRUST POL
mIraq20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq2013nomiss)
summary(mIraq20132b)

mIraq20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq2013nomiss)
summary(mIraq20132b2)

mIraq2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24c)

mIraq2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24c2)

mIraq2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24d)

mIraq2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24d2)

mIraq2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24e)

mIraq2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24e2)

mIraq2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24f)

mIraq2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted24f2)


#EDUC GE
mIraq2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22b)

mIraq2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22b2)

mIraq2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22c)

mIraq2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22c2)

mIraq2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22d)

mIraq2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22d2)

mIraq2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22e)

mIraq2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22e2)

mIraq2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22f)

mIraq2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted22f2)



#POL GE
mIraq20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq2013nomiss)
summary(mIraq20132b)

mIraq2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23c)

mIraq2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23d)

mIraq2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23d2)

mIraq2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23e)

mIraq2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23e2)

mIraq2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2013weighted)
summary(mIraq2013weighted23f)








##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS JORDAN 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Jordan2013 <- ABWVS20132018[ABWVS20132018$country == "Jordan" & ABWVS20132018$year == 2013,]
table(Jordan2013$country)
table(Jordan2013$year)

Jordan2013$weightcats <- 99999
table(Jordan2013$weightcats)

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	1
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	2
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	3
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	4
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	5
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	6

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	7
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	8
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	9
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	10
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	11
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	12

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	13
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	14
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	15
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	16
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	17
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	18

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	19
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	20
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	21
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	22
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	23
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 0 ]	<-	24

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	25
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	26
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	27
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	28
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	29
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	30

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	31
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	32
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	33
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	34
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	35
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	36

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	37
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	38
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	39
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	40
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	41
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	42

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	43
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	44
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	45
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	46
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	47
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 0 ]	<-	48



Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	49
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	50
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	51
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	52
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	53
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	54

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	55
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	56
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	57
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	58
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	59
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	60

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	61
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	62
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	63
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	64
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	65
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	66

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	67
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	68
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	69
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	70
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	71
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==0 & Jordan2013$Surveytype == 1 ]	<-	72

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	73
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	74
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	75
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	76
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	77
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	78

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	79
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	80
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	81
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	82
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	83
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==0 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	84

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	85
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	86
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	87
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	88
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	89
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==0 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	90

Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	91
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==0 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	92
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	93
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==1 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	94
Jordan2013$weightcats[Jordan2013$gender == 0 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	95
Jordan2013$weightcats[Jordan2013$gender == 1 & Jordan2013$agecats ==2 & Jordan2013$Educcats ==1 & Jordan2013$Mar2 ==1 & Jordan2013$Empl ==1 & Jordan2013$Surveytype == 1 ]	<-	96

table(Jordan2013$weightcats)

Jordan2013nomiss <- Jordan2013[Jordan2013$weightcats != 99999,]
table(Jordan2013nomiss$weightcats)

prop.table(table(Jordan2013nomiss$weightcats, Jordan2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 57 71 90 95

Jordan2013nomiss2 <- Jordan2013nomiss[Jordan2013nomiss$weightcats != 57 & Jordan2013nomiss$weightcats != 71 & Jordan2013nomiss$weightcats != 90 & Jordan2013nomiss$weightcats != 95 ,]
table(Jordan2013nomiss2$weightcats)

Jordan13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"91", 	"92", 	"93", 	"94"),
Freq = nrow(Jordan2013nomiss2) * c(	0.0016700067, 	0.0250501002, 	0.0146960588, 	0.080494322, 	0.0313961256, 	0.0297261189, 	0.0036740147, 	0.00501002, 	0.006012024, 	0.001002004, 	0.0307281229, 	0.0126920508, 	0.0013360053, 	0.0103540414, 	0.002004008, 	0.0126920508, 	0.0033400134, 	0.0026720107, 	0.0006680027, 	0.0003340013, 	0.0003340013, 	0.0070140281, 	0.0003340013, 	0.044756179, 	0.0043420174, 	0.0136940548, 	0.0003340013, 	0.001002004, 	0.001002004, 	0.0080160321, 	0.00501002, 	0.0023380094, 	0.0003340013, 	0.0197060788, 	0.0006680027, 	0.0043420174, 	0.0033400134, 	0.0003340013, 	0.006012024, 	0.0006680027, 	0.0013360053, 	0.0003340013, 	0.0016700067, 	0.0250501002, 	0.0146960588, 	0.080494322, 	0.0313961256, 	0.0297261189, 	0.0036740147, 	0.00501002, 	0.006012024, 	0.001002004, 	0.0307281229, 	0.0126920508, 	0.0013360053, 	0.0103540414, 	0.002004008, 	0.0126920508, 	0.0033400134, 	0.0026720107, 	0.0006680027, 	0.0003340013, 	0.0003340013, 	0.0070140281, 	0.0003340013, 	0.044756179, 	0.0043420174, 	0.0136940548, 	0.0003340013, 	0.001002004, 	0.001002004, 	0.0080160321, 	0.00501002, 	0.0023380094, 	0.0003340013, 	0.0197060788, 	0.0006680027, 	0.0043420174, 	0.0033400134, 	0.0003340013, 	0.006012024, 	0.0006680027, 	0.0013360053, 	0.0003340013))

#library(survey)

Jordan2013w <- svydesign(ids=~1, data = Jordan2013nomiss2)

Jordan2013weighted <- rake(design = Jordan2013w,
                           sample.margins = list(~weightcats),
                           population.margins = list(Jordan13.distribution))

table(Jordan2013nomiss2$Surveytype)
svytable(~Surveytype, Jordan2013weighted)
#WORKED.

table(Jordan2013nomiss2$gender)
svytable(~gender, Jordan2013weighted)
#worked.

table(Jordan2013nomiss2$gender, Jordan2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Jordan2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES JORDAN2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Jordan2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Jordan2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Jordan2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Jordan2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Jordan2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Jordan2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Jordan2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Jordan2013weighted, Surveytype ==1)))




#TRUST
mJordan2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21b)

mJordan2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21c)

mJordan2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21c2)

mJordan2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21d)

mJordan2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21d2)

mJordan2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21e)

mJordan2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21e2)

mJordan2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21f)

mJordan2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted, family = quasibinomial)
summary(mJordan2013weighted21f2)


#TRUST POL
mJordan20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan2013nomiss)
summary(mJordan20132b)

mJordan20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan2013nomiss)
summary(mJordan20132b2)

mJordan2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24c)

mJordan2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24c2)

mJordan2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24d)

mJordan2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24d2)

mJordan2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24e)

mJordan2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24e2)

mJordan2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24f)

mJordan2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted24f2)


#EDUC GE
mJordan2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22b)

mJordan2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22b2)

mJordan2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22c)

mJordan2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22c2)

mJordan2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22d)

mJordan2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22d2)

mJordan2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22e)

mJordan2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22e2)

mJordan2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22f)

mJordan2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted22f2)



#POL GE
mJordan20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan2013nomiss)
summary(mJordan20132b)

mJordan20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan2013nomiss)
summary(mJordan20132b2)

mJordan2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23c)

mJordan2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23d)

mJordan2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23d2)

mJordan2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23e)

mJordan2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23e2)

mJordan2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23f)

mJordan2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2013weighted)
summary(mJordan2013weighted23f2)







##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS KUWAIT 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Kuwait2013 <- ABWVS20132018[ABWVS20132018$country == "Kuwait" & ABWVS20132018$year == 2013,]
table(Kuwait2013$country)
table(Kuwait2013$year)

Kuwait2013$weightcats <- 99999
table(Kuwait2013$weightcats)

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	1
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	2
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	3
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	4
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	5
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	6

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	7
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	8
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	9
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	10
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	11
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	12

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	13
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	14
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	15
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	16
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	17
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	18

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	19
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	20
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	21
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	22
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	23
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 0 ]	<-	24

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	25
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	26
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	27
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	28
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	29
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	30

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	31
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	32
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	33
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	34
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	35
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	36

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	37
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	38
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	39
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	40
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	41
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	42

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	43
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	44
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	45
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	46
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	47
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 0 ]	<-	48



Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	49
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	50
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	51
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	52
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	53
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	54

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	55
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	56
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	57
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	58
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	59
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	60

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	61
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	62
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	63
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	64
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	65
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	66

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	67
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	68
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	69
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	70
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	71
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==0 & Kuwait2013$Surveytype == 1 ]	<-	72

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	73
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	74
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	75
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	76
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	77
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	78

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	79
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	80
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	81
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	82
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	83
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==0 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	84

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	85
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	86
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	87
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	88
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	89
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==0 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	90

Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	91
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==0 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	92
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	93
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==1 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	94
Kuwait2013$weightcats[Kuwait2013$gender == 0 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	95
Kuwait2013$weightcats[Kuwait2013$gender == 1 & Kuwait2013$agecats ==2 & Kuwait2013$Educcats ==1 & Kuwait2013$Mar2 ==1 & Kuwait2013$Empl ==1 & Kuwait2013$Surveytype == 1 ]	<-	96

table(Kuwait2013$weightcats)
table(Kuwait2013$weightcats, Kuwait2013$Surveytype)
#100 missings in wvs.

Kuwait2013nomiss <- Kuwait2013[Kuwait2013$weightcats != 99999,]
table(Kuwait2013nomiss$weightcats)

prop.table(table(Kuwait2013nomiss$weightcats, Kuwait2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 7	8	22	23	24	84	47	48

Kuwait2013nomiss2 <- Kuwait2013nomiss[Kuwait2013nomiss$weightcats != 7 & Kuwait2013nomiss$weightcats != 8 & Kuwait2013nomiss$weightcats != 22 & Kuwait2013nomiss$weightcats != 23 & Kuwait2013nomiss$weightcats != 24 & Kuwait2013nomiss$weightcats != 84 & Kuwait2013nomiss$weightcats != 47 & Kuwait2013nomiss$weightcats != 48 ,]
table(Kuwait2013nomiss2$weightcats)

Kuwait13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"9", 	"10", 	"11", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"37", 	"38", 	"39", 	"40", 	"41", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"57", 	"58", 	"59", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"85", 	"86", 	"87", 	"88", 	"89", 	"91", 	"92", 	"93", 	"94"), 
Freq = nrow(Kuwait2013nomiss2) * c(	0.00270027, 	0.005850585, 	0.00270027, 	0.01260126, 	0.025652565, 	0.00630063, 	0.00090009, 	0.002250225, 	0.00270027, 	0.03420342, 	0.004950495, 	0.002250225, 	0.013051305, 	0.000450045, 	0.00810081, 	0.00270027, 	0.002250225, 	0.00180018, 	0.02160216, 	0.011251125, 	0.086408641, 	0.03690369, 	0.012151215, 	0.003150315, 	0.013051305, 	0.010351035, 	0.04410441, 	0.029252925, 	0.006750675, 	0.04140414, 	0.013051305, 	0.031053105, 	0.02610261, 	0.00270027, 	0.00270027, 	0.005850585, 	0.003150315, 	0.00360036, 	0.00270027, 	0.005850585, 	0.00270027, 	0.01260126, 	0.025652565, 	0.00630063, 	0.00090009, 	0.002250225, 	0.00270027, 	0.03420342, 	0.004950495, 	0.002250225, 	0.013051305, 	0.000450045, 	0.00810081, 	0.00270027, 	0.002250225, 	0.00180018, 	0.02160216, 	0.011251125, 	0.086408641, 	0.03690369, 	0.012151215, 	0.003150315, 	0.013051305, 	0.010351035, 	0.04410441, 	0.029252925, 	0.006750675, 	0.04140414, 	0.013051305, 	0.031053105, 	0.02610261, 	0.00270027, 	0.00270027, 	0.005850585, 	0.003150315, 	0.00360036))
#library(survey)

Kuwait2013w <- svydesign(ids=~1, data = Kuwait2013nomiss2)

Kuwait2013weighted <- rake(design = Kuwait2013w,
                           sample.margins = list(~weightcats),
                           population.margins = list(Kuwait13.distribution))

table(Kuwait2013nomiss2$Surveytype)
svytable(~Surveytype, Kuwait2013weighted)
#WORKED.

table(Kuwait2013nomiss2$gender)
svytable(~gender, Kuwait2013weighted)
#worked.

table(Kuwait2013nomiss2$gender, Kuwait2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Kuwait2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES KUWAIT2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Kuwait2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Kuwait2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Kuwait2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Kuwait2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Kuwait2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Kuwait2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Kuwait2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Kuwait2013weighted, Surveytype ==1)))




#TRUST
mKuwait2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21b)

mKuwait2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21c)

mKuwait2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21c2)

mKuwait2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21d)

mKuwait2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21d2)

mKuwait2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21e)

mKuwait2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21e2)

mKuwait2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21f)

mKuwait2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted, family = quasibinomial)
summary(mKuwait2013weighted21f2)


#TRUST POL
mKuwait20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Kuwait2013nomiss)
summary(mKuwait20132b)

mKuwait20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Kuwait2013nomiss)
summary(mKuwait20132b2)

mKuwait2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24c)

mKuwait2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24c2)

mKuwait2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24d)

mKuwait2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24d2)

mKuwait2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24e)

mKuwait2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24e2)

mKuwait2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24f)

mKuwait2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted24f2)


#EDUC GE
mKuwait2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22b)

mKuwait2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22b2)

mKuwait2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22c)

mKuwait2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22c2)

mKuwait2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22d)

mKuwait2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22d2)

mKuwait2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22e)

mKuwait2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22e2)

mKuwait2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22f)

mKuwait2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted22f2)



#POL GE
mKuwait20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Kuwait2013nomiss)
summary(mKuwait20132b)

mKuwait20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Kuwait2013nomiss)
summary(mKuwait20132b2)

mKuwait2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23c)

mKuwait2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23d)

mKuwait2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23d2)

mKuwait2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23e)

mKuwait2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23e2)

mKuwait2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23f)

mKuwait2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Kuwait2013weighted)
summary(mKuwait2013weighted23f2)







##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS LEBANON 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Lebanon2013 <- ABWVS20132018[ABWVS20132018$country == "Lebanon" & ABWVS20132018$year == 2013,]
table(Lebanon2013$country)
table(Lebanon2013$year)

Lebanon2013$weightcats <- 99999
table(Lebanon2013$weightcats)

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	1
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	2
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	3
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	4
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	5
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	6

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	7
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	8
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	9
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	10
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	11
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	12

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	13
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	14
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	15
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	16
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	17
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	18

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	19
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	20
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	21
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	22
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	23
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 0 ]	<-	24

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	25
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	26
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	27
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	28
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	29
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	30

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	31
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	32
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	33
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	34
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	35
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	36

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	37
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	38
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	39
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	40
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	41
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	42

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	43
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	44
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	45
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	46
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	47
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 0 ]	<-	48



Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	49
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	50
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	51
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	52
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	53
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	54

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	55
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	56
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	57
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	58
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	59
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	60

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	61
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	62
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	63
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	64
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	65
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	66

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	67
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	68
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	69
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	70
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	71
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==0 & Lebanon2013$Surveytype == 1 ]	<-	72

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	73
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	74
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	75
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	76
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	77
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	78

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	79
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	80
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	81
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	82
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	83
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==0 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	84

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	85
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	86
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	87
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	88
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	89
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==0 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	90

Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	91
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==0 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	92
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	93
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==1 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	94
Lebanon2013$weightcats[Lebanon2013$gender == 0 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	95
Lebanon2013$weightcats[Lebanon2013$gender == 1 & Lebanon2013$agecats ==2 & Lebanon2013$Educcats ==1 & Lebanon2013$Mar2 ==1 & Lebanon2013$Empl ==1 & Lebanon2013$Surveytype == 1 ]	<-	96

table(Lebanon2013$weightcats)

Lebanon2013nomiss <- Lebanon2013[Lebanon2013$weightcats != 99999,]
table(Lebanon2013nomiss$weightcats)

prop.table(table(Lebanon2013nomiss$weightcats, Lebanon2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 1	7	9	15	23

Lebanon2013nomiss2 <- Lebanon2013nomiss[Lebanon2013nomiss$weightcats != 1 & Lebanon2013nomiss$weightcats != 7 & Lebanon2013nomiss$weightcats != 9 & Lebanon2013nomiss$weightcats != 15 & Lebanon2013nomiss$weightcats != 23 ,]
table(Lebanon2013nomiss2$weightcats)

Lebanon13.distribution <- data.frame(weightcats = c(	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"10", 	"11", 	"12", 	"13", 	"14", 	"16", 	"17", 	"18", 	"19", 	"20", 	"22", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"47", 	"48", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"59", 	"60", 	"61", 	"62", 	"64", 	"65", 	"66", 	"67", 	"68", 	"70", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"95", 	"96"),
Freq = nrow(Lebanon2013nomiss2) * c(	0.007569386, 	0.0046257359, 	0.0340622372, 	0.0109335576, 	0.0269133726, 	0.0008410429, 	0.0033641716, 	0.0012615643, 	0.0025231287, 	0.0424726661, 	0.0403700589, 	0.0092514718, 	0.0046257359, 	0.0117746005, 	0.0079899075, 	0.0084104289, 	0.0008410429, 	0.0012615643, 	0.0058873003, 	0.0084104289, 	0.0336417157, 	0.0218671152, 	0.0378469302, 	0.0130361648, 	0.0012615643, 	0.0021026072, 	0.007569386, 	0.0088309504, 	0.0071488646, 	0.0012615643, 	0.0281749369, 	0.0142977292, 	0.0206055509, 	0.012195122, 	0.0054667788, 	0.0079899075, 	0.012195122, 	0.0088309504, 	0.0050462574, 	0.003784693, 	0.0016820858, 	0.0025231287, 	0.007569386, 	0.0046257359, 	0.0340622372, 	0.0109335576, 	0.0269133726, 	0.0008410429, 	0.0033641716, 	0.0012615643, 	0.0025231287, 	0.0424726661, 	0.0403700589, 	0.0092514718, 	0.0046257359, 	0.0117746005, 	0.0079899075, 	0.0084104289, 	0.0008410429, 	0.0012615643, 	0.0058873003, 	0.0084104289, 	0.0336417157, 	0.0218671152, 	0.0378469302, 	0.0130361648, 	0.0012615643, 	0.0021026072, 	0.007569386, 	0.0088309504, 	0.0071488646, 	0.0012615643, 	0.0281749369, 	0.0142977292, 	0.0206055509, 	0.012195122, 	0.0054667788, 	0.0079899075, 	0.012195122, 	0.0088309504, 	0.0050462574, 	0.003784693, 	0.0016820858, 	0.0025231287))

Lebanon2013w <- svydesign(ids=~1, data = Lebanon2013nomiss2)

Lebanon2013weighted <- rake(design = Lebanon2013w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Lebanon13.distribution))

table(Lebanon2013nomiss2$Surveytype)
svytable(~Surveytype, Lebanon2013weighted)
#WORKED.

table(Lebanon2013nomiss2$gender)
svytable(~gender, Lebanon2013weighted)
#worked.

table(Lebanon2013nomiss2$gender, Lebanon2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Lebanon2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES LEBANON2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Lebanon2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Lebanon2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Lebanon2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Lebanon2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Lebanon2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Lebanon2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Lebanon2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Lebanon2013weighted, Surveytype ==1)))




#TRUST
mLebanon2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21b)

mLebanon2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21c)

mLebanon2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21c2)

mLebanon2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21d)

mLebanon2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21d2)

mLebanon2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21e)

mLebanon2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21e2)

mLebanon2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21f)

mLebanon2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted, family = quasibinomial)
summary(mLebanon2013weighted21f2)


#TRUST POL
mLebanon20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2013nomiss)
summary(mLebanon20132b)

mLebanon20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2013nomiss)
summary(mLebanon20132b2)

mLebanon2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24c)

mLebanon2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24c2)

mLebanon2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24d)

mLebanon2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24d2)

mLebanon2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24e)

mLebanon2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24e2)

mLebanon2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24f)

mLebanon2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted24f2)


#EDUC GE
mLebanon2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22b)

mLebanon2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22b2)

mLebanon2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22c)

mLebanon2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22c2)

mLebanon2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22d)

mLebanon2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22d2)

mLebanon2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22e)

mLebanon2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22e2)

mLebanon2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22f)

mLebanon2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted22f2)



#POL GE
mLebanon20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2013nomiss)
summary(mLebanon20132b)

mLebanon20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2013nomiss)
summary(mLebanon20132b2)

mLebanon2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23c)

mLebanon2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23d)

mLebanon2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23d2)

mLebanon2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23e)

mLebanon2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23e2)

mLebanon2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23f)

mLebanon2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2013weighted)
summary(mLebanon2013weighted23f2)






##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS LIBYA 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Libya2013 <- ABWVS20132018[ABWVS20132018$country == "Libya" & ABWVS20132018$year == 2013,]
table(Libya2013$country)
table(Libya2013$year)

Libya2013$weightcats <- 99999
table(Libya2013$weightcats)

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	1
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	2
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	3
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	4
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	5
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	6

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	7
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	8
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	9
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	10
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	11
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	12

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	13
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	14
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	15
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	16
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	17
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	18

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	19
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	20
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	21
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	22
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	23
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 0 ]	<-	24

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	25
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	26
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	27
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	28
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	29
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	30

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	31
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	32
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	33
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	34
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	35
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	36

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	37
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	38
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	39
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	40
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	41
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	42

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	43
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	44
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	45
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	46
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	47
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 0 ]	<-	48



Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	49
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	50
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	51
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	52
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	53
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	54

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	55
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	56
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	57
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	58
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	59
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	60

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	61
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	62
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	63
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	64
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	65
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	66

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	67
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	68
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	69
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	70
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	71
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==0 & Libya2013$Surveytype == 1 ]	<-	72

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	73
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	74
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	75
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	76
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	77
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	78

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	79
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	80
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	81
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	82
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	83
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==0 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	84

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	85
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	86
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	87
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	88
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	89
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==0 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	90

Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	91
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==0 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	92
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	93
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==1 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	94
Libya2013$weightcats[Libya2013$gender == 0 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	95
Libya2013$weightcats[Libya2013$gender == 1 & Libya2013$agecats ==2 & Libya2013$Educcats ==1 & Libya2013$Mar2 ==1 & Libya2013$Empl ==1 & Libya2013$Surveytype == 1 ]	<-	96

table(Libya2013$weightcats)

Libya2013nomiss <- Libya2013[Libya2013$weightcats != 99999,]
table(Libya2013nomiss$weightcats)

prop.table(table(Libya2013nomiss$weightcats, Libya2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 1	7	41

Libya2013nomiss2 <- Libya2013nomiss[Libya2013nomiss$weightcats != 1 & Libya2013nomiss$weightcats != 7 & Libya2013nomiss$weightcats != 41 ,]
table(Libya2013nomiss2$weightcats)

Libya13.distribution <- data.frame(weightcats = c(	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"23", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"42", 	"43", 	"44", 	"45", 	"46", 	"48", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"71", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"90", 	"91", 	"92", 	"93", 	"94", 	"96"), 
Freq = nrow(Libya2013nomiss2) * c(0.0157099698, 	0.0069486405, 	0.0561933535, 	0.0181268882, 	0.0362537764, 	0.0060422961, 	0.0021148036, 	0.0090634441, 	0.0048338369, 	0.0012084592, 	0.0504531722, 	0.035347432, 	0.0024169184, 	0.0190332326, 	0.0027190332, 	0.0160120846, 	0.0054380665, 	0.0048338369, 	0.0012084592, 	0.0027190332, 	0.0006042296, 	0.0003021148, 	0.0084592145, 	0.0042296073, 	0.0628398792, 	0.0326283988, 	0.0259818731, 	0.0102719033, 	0.0054380665, 	0.0033232628, 	0.0359516616, 	0.0208459215, 	0.0087613293, 	0.0012084592, 	0.0332326284, 	0.0042296073, 	0.0163141994, 	0.0114803625, 	0.0036253776, 	0.0105740181, 	0.0048338369, 	0.0111782477, 	0.0117824773, 	0.0018126888, 	0.0157099698, 	0.0069486405, 	0.0561933535, 	0.0181268882, 	0.0362537764, 	0.0060422961, 	0.0021148036, 	0.0090634441, 	0.0048338369, 	0.0012084592, 	0.0504531722, 	0.035347432, 	0.0024169184, 	0.0190332326, 	0.0027190332, 	0.0160120846, 	0.0054380665, 	0.0048338369, 	0.0012084592, 	0.0027190332, 	0.0006042296, 	0.0003021148, 	0.0084592145, 	0.0042296073, 	0.0628398792, 	0.0326283988, 	0.0259818731, 	0.0102719033, 	0.0054380665, 	0.0033232628, 	0.0359516616, 	0.0208459215, 	0.0087613293, 	0.0012084592, 	0.0332326284, 	0.0042296073, 	0.0163141994, 	0.0114803625, 	0.0036253776, 	0.0105740181, 	0.0048338369, 	0.0111782477, 	0.0117824773, 	0.0018126888))

Libya2013w <- svydesign(ids=~1, data = Libya2013nomiss2)

Libya2013weighted <- rake(design = Libya2013w,
                          sample.margins = list(~weightcats),
                          population.margins = list(Libya13.distribution))

table(Libya2013nomiss2$Surveytype)
svytable(~Surveytype, Libya2013weighted)
#WORKED.

table(Libya2013nomiss2$gender)
svytable(~gender, Libya2013weighted)
#worked.

table(Libya2013nomiss2$gender, Libya2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Libya2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES LIBYA2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Libya2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Libya2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Libya2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Libya2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Libya2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Libya2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Libya2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Libya2013weighted, Surveytype ==1)))




#TRUST
mLibya2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21b)

mLibya2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21c)

mLibya2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21c2)

mLibya2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21d)

mLibya2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21d2)

mLibya2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21e)

mLibya2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21e2)

mLibya2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21f)

mLibya2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted, family = quasibinomial)
summary(mLibya2013weighted21f2)


#TRUST POL
mLibya20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Libya2013nomiss)
summary(mLibya20132b)

mLibya20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Libya2013nomiss)
summary(mLibya20132b2)

mLibya2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24c)

mLibya2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24c2)

mLibya2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24d)

mLibya2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24d2)

mLibya2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24e)

mLibya2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24e2)

mLibya2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24f)

mLibya2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted24f2)


#EDUC GE
mLibya2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22b)

mLibya2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22b2)

mLibya2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22c)

mLibya2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22c2)

mLibya2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22d)

mLibya2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22d2)

mLibya2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22e)

mLibya2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22e2)

mLibya2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22f)

mLibya2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted22f2)



#POL GE
mLibya20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Libya2013nomiss)
summary(mLibya20132b)

mLibya20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Libya2013nomiss)
summary(mLibya20132b2)

mLibya2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23c)

mLibya2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23d)

mLibya2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23d2)

mLibya2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23e)

mLibya2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23e2)

mLibya2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23f)

mLibya2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Libya2013weighted)
summary(mLibya2013weighted23f2)






##################################################################################################################
##################################################################################################################
########################################CREATING WEIGHTS MOROCCO 2013###############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Morocco2013 <- ABWVS20132018[ABWVS20132018$country == "Morocco" & ABWVS20132018$year == 2013,]
table(Morocco2013$country)
table(Morocco2013$year)

Morocco2013$weightcats <- 99999
table(Morocco2013$weightcats)

table(Morocco2013$Educcats, Morocco2013$Surveytype)
#Very few people in morocco are educcat 1 (tertiary), in both datasets, but expecially in WVS

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	1
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	2
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	3
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	4
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	5
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	6

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	7
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	8
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	9
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	10
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	11
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	12

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	13
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	14
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	15
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	16
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	17
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	18

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	19
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	20
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	21
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	22
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	23
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 0 ]	<-	24

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	25
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	26
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	27
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	28
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	29
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	30

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	31
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	32
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	33
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	34
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	35
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	36

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	37
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	38
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	39
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	40
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	41
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	42

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	43
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	44
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	45
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	46
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	47
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 0 ]	<-	48



Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	49
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	50
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	51
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	52
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	53
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	54

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	55
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	56
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	57
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	58
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	59
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	60

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	61
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	62
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	63
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	64
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	65
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	66

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	67
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	68
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	69
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	70
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	71
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==0 & Morocco2013$Surveytype == 1 ]	<-	72

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	73
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	74
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	75
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	76
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	77
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	78

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	79
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	80
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	81
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	82
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	83
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==0 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	84

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	85
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	86
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	87
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	88
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	89
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==0 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	90

Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	91
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==0 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	92
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	93
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==1 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	94
Morocco2013$weightcats[Morocco2013$gender == 0 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	95
Morocco2013$weightcats[Morocco2013$gender == 1 & Morocco2013$agecats ==2 & Morocco2013$Educcats ==1 & Morocco2013$Mar2 ==1 & Morocco2013$Empl ==1 & Morocco2013$Surveytype == 1 ]	<-	96

table(Morocco2013$weightcats)

Morocco2013nomiss <- Morocco2013[Morocco2013$weightcats != 99999,]
table(Morocco2013nomiss$weightcats)

#THERE ARE HUGE GAPING HOLES IN MOROCCO IN 7-12 (and 55-60) AND IN 19-24 (and 67-72)
#which are probably due to educ = 1 being very low in morocco in both datasets.
#the educ = 1 ones that there are, are in 31-34 (and 79-84) and in 34, 44, 46 (and 91-95)
#so it's a combo of educ =1 with another thing (and that other thing is not gender or age)
#it's employment. There are almost no people in surveys in morocco (either ab or wvs) who are both tertiary educated AND non-employed.

table(Morocco2013$Educcats, Morocco2013$Empl)

prop.table(table(Morocco2013nomiss$weightcats, Morocco2013nomiss$Surveytype))
#anyways, cats without respondents in their accompanying WVS/AB countercategory: 83	84	93	95

Morocco2013nomiss2 <- Morocco2013nomiss[Morocco2013nomiss$weightcats != 83 & Morocco2013nomiss$weightcats != 84 & Morocco2013nomiss$weightcats != 93 & Morocco2013nomiss$weightcats != 95 ,]
table(Morocco2013nomiss2$weightcats)

Morocco13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"94"), 
Freq = nrow(Morocco2013nomiss2) * c(	0.0004319654, 	0.0012958963, 	0.0021598272, 	0.0107991361, 	0.0025917927, 	0.0172786177, 	0.0177105832, 	0.0168466523, 	0.0030237581, 	0.0051835853, 	0.0034557235, 	0.0064794816, 	0.0250539957, 	0.0194384449, 	0.0678185745, 	0.0613390929, 	0.0410367171, 	0.0220302376, 	0.0021598272, 	0.0012958963, 	0.0021598272, 	0.0021598272, 	0.0596112311, 	0.0652267819, 	0.0211663067, 	0.0198704104, 	0.007775378, 	0.0086393089, 	0.0008639309, 	0.0021598272, 	0.0008639309, 	0.0004319654, 	0.0012958963, 	0.0021598272, 	0.0107991361, 	0.0025917927, 	0.0172786177, 	0.0177105832, 	0.0168466523, 	0.0030237581, 	0.0051835853, 	0.0034557235, 	0.0064794816, 	0.0250539957, 	0.0194384449, 	0.0678185745, 	0.0613390929, 	0.0410367171, 	0.0220302376, 	0.0021598272, 	0.0012958963, 	0.0021598272, 	0.0021598272, 	0.0596112311, 	0.0652267819, 	0.0211663067, 	0.0198704104, 	0.007775378, 	0.0086393089, 	0.0008639309, 	0.0021598272, 	0.0008639309))

Morocco2013w <- svydesign(ids=~1, data = Morocco2013nomiss2)

Morocco2013weighted <- rake(design = Morocco2013w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Morocco13.distribution))

table(Morocco2013nomiss2$Surveytype)
svytable(~Surveytype, Morocco2013weighted)
#WORKED.

table(Morocco2013nomiss2$gender)
svytable(~gender, Morocco2013weighted)
#worked.

table(Morocco2013nomiss2$gender, Morocco2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Morocco2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
###########################################ANALYSES MOROCCO2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Morocco2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Morocco2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Morocco2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Morocco2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Morocco2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Morocco2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Morocco2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Morocco2013weighted, Surveytype ==1)))




#TRUST
mMorocco2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21b)

mMorocco2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21c)

mMorocco2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21c2)

mMorocco2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21d)

mMorocco2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21d2)

mMorocco2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21e)

mMorocco2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21e2)

mMorocco2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21f)

mMorocco2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted, family = quasibinomial)
summary(mMorocco2013weighted21f2)


#TRUST POL
mMorocco20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Morocco2013nomiss)
summary(mMorocco20132b)

mMorocco20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Morocco2013nomiss)
summary(mMorocco20132b2)

mMorocco2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24c)

mMorocco2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24c2)

mMorocco2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24d)

mMorocco2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24d2)

mMorocco2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24e)

mMorocco2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24e2)

mMorocco2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24f)

mMorocco2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted24f2)


#EDUC GE
mMorocco2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22b)

mMorocco2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22b2)

mMorocco2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22c)

mMorocco2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22c2)

mMorocco2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22d)

mMorocco2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22d2)

mMorocco2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22e)

mMorocco2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22e2)

mMorocco2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22f)

mMorocco2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted22f2)



#POL GE
mMorocco20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Morocco2013nomiss)
summary(mMorocco20132b)

mMorocco20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Morocco2013nomiss)
summary(mMorocco20132b2)

mMorocco2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23c)

mMorocco2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23d)

mMorocco2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23d2)

mMorocco2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23e)

mMorocco2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23e2)

mMorocco2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23f)

mMorocco2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Morocco2013weighted)
summary(mMorocco2013weighted23f2)





##################################################################################################################
##################################################################################################################
#######################################CREATING WEIGHTS PALESTINE 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Palestine2013 <- ABWVS20132018[ABWVS20132018$country == "Palestine" & ABWVS20132018$year == 2013,]
table(Palestine2013$country)
table(Palestine2013$year)

Palestine2013$weightcats <- 99999
table(Palestine2013$weightcats)


Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	1
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	2
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	3
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	4
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	5
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	6

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	7
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	8
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	9
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	10
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	11
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	12

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	13
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	14
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	15
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	16
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	17
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	18

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	19
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	20
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	21
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	22
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	23
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 0 ]	<-	24

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	25
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	26
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	27
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	28
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	29
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	30

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	31
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	32
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	33
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	34
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	35
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	36

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	37
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	38
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	39
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	40
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	41
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	42

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	43
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	44
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	45
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	46
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	47
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 0 ]	<-	48



Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	49
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	50
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	51
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	52
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	53
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	54

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	55
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	56
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	57
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	58
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	59
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	60

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	61
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	62
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	63
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	64
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	65
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	66

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	67
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	68
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	69
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	70
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	71
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==0 & Palestine2013$Surveytype == 1 ]	<-	72

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	73
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	74
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	75
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	76
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	77
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	78

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	79
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	80
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	81
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	82
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	83
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==0 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	84

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	85
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	86
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	87
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	88
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	89
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==0 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	90

Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	91
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==0 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	92
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	93
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==1 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	94
Palestine2013$weightcats[Palestine2013$gender == 0 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	95
Palestine2013$weightcats[Palestine2013$gender == 1 & Palestine2013$agecats ==2 & Palestine2013$Educcats ==1 & Palestine2013$Mar2 ==1 & Palestine2013$Empl ==1 & Palestine2013$Surveytype == 1 ]	<-	96

table(Palestine2013$weightcats)

Palestine2013nomiss <- Palestine2013[Palestine2013$weightcats != 99999,]
table(Palestine2013nomiss$weightcats)

prop.table(table(Palestine2013nomiss$weightcats, Palestine2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 55	57	69	22	71	47	48

Palestine2013nomiss2 <- Palestine2013nomiss[Palestine2013nomiss$weightcats != 55 & Palestine2013nomiss$weightcats != 57 & Palestine2013nomiss$weightcats != 69 & Palestine2013nomiss$weightcats != 22 & Palestine2013nomiss$weightcats != 71 & Palestine2013nomiss$weightcats != 47 & Palestine2013nomiss$weightcats != 48,]
table(Palestine2013nomiss2$weightcats)

Palestine13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"10", 	"11", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"59", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94"), 
Freq = nrow(Palestine2013nomiss2) * c(	0.0027422303, 	0.0278793419, 	0.0123400366, 	0.071297989, 	0.0201096892, 	0.018738574, 	0.0073126143, 	0.0054844607, 	0.0027422303, 	0.0319926874, 	0.0383912249, 	0.0004570384, 	0.0114259598, 	0.0027422303, 	0.0114259598, 	0.0054844607, 	0.0073126143, 	0.0013711152, 	0.0118829982, 	0.0031992687, 	0.0557586837, 	0.0050274223, 	0.0169104205, 	0.0009140768, 	0.0059414991, 	0.0045703839, 	0.0214808044, 	0.0095978062, 	0.0045703839, 	0.0004570384, 	0.0173674589, 	0.0009140768, 	0.0018281536, 	0.0018281536, 	0.0009140768, 	0.0004570384, 	0.0059414991, 	0.0036563071, 	0.0009140768, 	0.0013711152, 	0.0027422303, 	0.0278793419, 	0.0123400366, 	0.071297989, 	0.0201096892, 	0.018738574, 	0.0073126143, 	0.0054844607, 	0.0027422303, 	0.0319926874, 	0.0383912249, 	0.0004570384, 	0.0114259598, 	0.0027422303, 	0.0114259598, 	0.0054844607, 	0.0073126143, 	0.0013711152, 	0.0118829982, 	0.0031992687, 	0.0557586837, 	0.0050274223,	0.0169104205, 	0.0009140768, 	0.0059414991, 	0.0045703839, 	0.0214808044, 	0.0095978062, 	0.0045703839, 	0.0004570384, 	0.0173674589, 	0.0009140768, 	0.0018281536, 	0.0018281536, 	0.0009140768, 	0.0004570384, 	0.0059414991, 	0.0036563071, 	0.0009140768, 	0.0013711152))


Palestine2013w <- svydesign(ids=~1, data = Palestine2013nomiss2)

Palestine2013weighted <- rake(design = Palestine2013w,
                              sample.margins = list(~weightcats),
                              population.margins = list(Palestine13.distribution))

table(Palestine2013nomiss2$Surveytype)
svytable(~Surveytype, Palestine2013weighted)
#WORKED.

table(Palestine2013nomiss2$gender)
svytable(~gender, Palestine2013weighted)
#worked.

table(Palestine2013nomiss2$gender, Palestine2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Palestine2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#######################################ANALYSES PALESTINE2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Palestine2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Palestine2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Palestine2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Palestine2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Palestine2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Palestine2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Palestine2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Palestine2013weighted, Surveytype ==1)))


#TRUST
mPalestine2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21b)

mPalestine2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21c)

mPalestine2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21c2)

mPalestine2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21d)

mPalestine2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21d2)

mPalestine2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21e)

mPalestine2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21e2)

mPalestine2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21f)

mPalestine2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted, family = quasibinomial)
summary(mPalestine2013weighted21f2)


#TRUST POL
mPalestine20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Palestine2013nomiss)
summary(mPalestine20132b)

mPalestine20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Palestine2013nomiss)
summary(mPalestine20132b2)

mPalestine2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24c)

mPalestine2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24c2)

mPalestine2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24d)

mPalestine2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24d2)

mPalestine2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24e)

mPalestine2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24e2)

mPalestine2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24f)

mPalestine2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted24f2)


#EDUC GE
mPalestine2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22b)

mPalestine2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22b2)

mPalestine2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22c)

mPalestine2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22c2)

mPalestine2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22d)

mPalestine2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22d2)

mPalestine2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22e)

mPalestine2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22e2)

mPalestine2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22f)

mPalestine2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted22f2)



#POL GE
mPalestine20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Palestine2013nomiss)
summary(mPalestine20132b)

mPalestine20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Palestine2013nomiss)
summary(mPalestine20132b2)

mPalestine2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23c)

mPalestine2013weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23c2)

mPalestine2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23d)

mPalestine2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23d2)

mPalestine2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23e)

mPalestine2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23e2)

mPalestine2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23f)

mPalestine2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Palestine2013weighted)
summary(mPalestine2013weighted23f2)






##################################################################################################################
##################################################################################################################
#########################################CREATING WEIGHTS TUNISIA 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Tunisia2013 <- ABWVS20132018[ABWVS20132018$country == "Tunisia" & ABWVS20132018$year == 2013,]
table(Tunisia2013$country)
table(Tunisia2013$year)

Tunisia2013$weightcats <- 99999
table(Tunisia2013$weightcats)


Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	1
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	2
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	3
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	4
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	5
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	6

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	7
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	8
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	9
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	10
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	11
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	12

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	13
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	14
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	15
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	16
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	17
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	18

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	19
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	20
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	21
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	22
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	23
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 0 ]	<-	24

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	25
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	26
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	27
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	28
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	29
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	30

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	31
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	32
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	33
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	34
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	35
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	36

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	37
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	38
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	39
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	40
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	41
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	42

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	43
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	44
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	45
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	46
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	47
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 0 ]	<-	48



Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	49
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	50
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	51
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	52
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	53
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	54

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	55
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	56
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	57
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	58
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	59
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	60

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	61
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	62
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	63
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	64
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	65
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	66

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	67
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	68
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	69
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	70
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	71
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==0 & Tunisia2013$Surveytype == 1 ]	<-	72

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	73
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	74
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	75
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	76
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	77
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	78

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	79
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	80
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	81
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	82
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	83
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==0 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	84

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	85
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	86
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	87
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	88
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	89
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==0 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	90

Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	91
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==0 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	92
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	93
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==1 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	94
Tunisia2013$weightcats[Tunisia2013$gender == 0 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	95
Tunisia2013$weightcats[Tunisia2013$gender == 1 & Tunisia2013$agecats ==2 & Tunisia2013$Educcats ==1 & Tunisia2013$Mar2 ==1 & Tunisia2013$Empl ==1 & Tunisia2013$Surveytype == 1 ]	<-	96

table(Tunisia2013$weightcats)

Tunisia2013nomiss <- Tunisia2013[Tunisia2013$weightcats != 99999,]
table(Tunisia2013nomiss$weightcats)

prop.table(table(Tunisia2013nomiss$weightcats, Tunisia2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 7	57	12	24	80

Tunisia2013nomiss2 <- Tunisia2013nomiss[Tunisia2013nomiss$weightcats != 7 & Tunisia2013nomiss$weightcats != 57 & Tunisia2013nomiss$weightcats != 12 & Tunisia2013nomiss$weightcats != 24 & Tunisia2013nomiss$weightcats != 80,]
table(Tunisia2013nomiss2$weightcats)

Tunisia13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"10", 	"11", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"33", 	"34", 	"35", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"58", 	"59", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"81", 	"82", 	"83", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94"), 
 Freq = nrow(Tunisia2013nomiss2) * c(	0.0021240442, 	0.0080713679, 	0.0063721325, 	0.0429056924, 	0.0382327952, 	0.0437553101, 	0.0012744265, 	0.002548853, 	0.0004248088, 	0.0586236194, 	0.0458793543, 	0.0114698386, 	0.0118946474, 	0.0012744265, 	0.0144435004, 	0.0084961767, 	0.0046728972, 	0.0029736619, 	0.0008496177, 	0.0021240442, 	0.005097706, 	0.046728972, 	0.0182667799, 	0.0246389125, 	0.0063721325, 	0.0004248088, 	0.0046728972, 	0.0021240442, 	0.0012744265, 	0.0322854715, 	0.0165675446, 	0.0161427358, 	0.0101954121, 	0.0021240442, 	0.0016992353, 	0.0055225149, 	0.0029736619, 	0.002548853, 	0.0021240442, 	0.0021240442, 	0.0080713679, 	0.0063721325, 	0.0429056924, 	0.0382327952, 	0.0437553101, 	0.0012744265, 	0.002548853, 	0.0004248088, 	0.0586236194, 	0.0458793543, 	0.0114698386, 	0.0118946474, 	0.0012744265, 	0.0144435004, 	0.0084961767, 	0.0046728972, 	0.0029736619, 	0.0008496177, 	0.0021240442, 	0.005097706, 	0.046728972, 	0.0182667799,	0.0246389125, 	0.0063721325, 	0.0004248088, 	0.0046728972, 	0.0021240442, 	0.0012744265, 	0.0322854715, 	0.0165675446, 	0.0161427358, 	0.0101954121, 	0.0021240442, 	0.0016992353, 	0.0055225149, 	0.0029736619, 	0.002548853, 	0.0021240442))

Tunisia2013w <- svydesign(ids=~1, data = Tunisia2013nomiss2)

Tunisia2013weighted <- rake(design = Tunisia2013w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Tunisia13.distribution))

table(Tunisia2013nomiss2$Surveytype)
svytable(~Surveytype, Tunisia2013weighted)
#WORKED.

table(Tunisia2013nomiss2$gender)
svytable(~gender, Tunisia2013weighted)
#worked.

table(Tunisia2013nomiss2$gender, Tunisia2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Tunisia2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES TUNISIA2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Tunisia2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Tunisia2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Tunisia2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Tunisia2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Tunisia2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Tunisia2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Tunisia2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Tunisia2013weighted, Surveytype ==1)))


#TRUST
mTunisia2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21b)

mTunisia2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21c)

mTunisia2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21c2)

mTunisia2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21d)

mTunisia2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21d2)

mTunisia2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21e)

mTunisia2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21e2)

mTunisia2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21f)

mTunisia2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted, family = quasibinomial)
summary(mTunisia2013weighted21f2)


#TRUST POL
mTunisia20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013nomiss)
summary(mTunisia20132b)

mTunisia20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013nomiss)
summary(mTunisia20132b2)

mTunisia2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24c)

mTunisia2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24c2)

mTunisia2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24d)

mTunisia2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24d2)

mTunisia2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24e)

mTunisia2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24e2)

mTunisia2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24f)

mTunisia2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted24f2)


#EDUC GE
mTunisia2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22b)

mTunisia2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22b2)

mTunisia2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22c)

mTunisia2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22c2)

mTunisia2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22d)

mTunisia2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22d2)

mTunisia2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22e)

mTunisia2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22e2)

mTunisia2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22f)

mTunisia2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted22f2)



#POL GE
mTunisia20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013nomiss)
summary(mTunisia20132b)

mTunisia20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2013nomiss)
summary(mTunisia20132b2)

mTunisia2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23c)

mTunisia2013weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23c2)

mTunisia2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23d)

mTunisia2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23d2)

mTunisia2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23e)

mTunisia2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23e2)

mTunisia2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23f)

mTunisia2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2013weighted)
summary(mTunisia2013weighted23f2)







##################################################################################################################
##################################################################################################################
#########################################CREATING WEIGHTS YEMEN 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Yemen2013 <- ABWVS20132018[ABWVS20132018$country == "Yemen" & ABWVS20132018$year == 2013,]
table(Yemen2013$country)
table(Yemen2013$year)

Yemen2013$weightcats <- 99999
table(Yemen2013$weightcats)


Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	1
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	2
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	3
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	4
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	5
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	6

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	7
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	8
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	9
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	10
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	11
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	12

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	13
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	14
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	15
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	16
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	17
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	18

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	19
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	20
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	21
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	22
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	23
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 0 ]	<-	24

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	25
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	26
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	27
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	28
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	29
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	30

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	31
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	32
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	33
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	34
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	35
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	36

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	37
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	38
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	39
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	40
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	41
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	42

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	43
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	44
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	45
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	46
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	47
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 0 ]	<-	48



Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	49
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	50
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	51
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	52
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	53
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	54

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	55
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	56
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	57
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	58
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	59
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	60

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	61
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	62
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	63
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	64
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	65
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	66

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	67
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	68
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	69
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	70
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	71
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==0 & Yemen2013$Surveytype == 1 ]	<-	72

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	73
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	74
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	75
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	76
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	77
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	78

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	79
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	80
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	81
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	82
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	83
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==0 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	84

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	85
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	86
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	87
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	88
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	89
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==0 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	90

Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	91
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==0 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	92
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	93
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==1 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	94
Yemen2013$weightcats[Yemen2013$gender == 0 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	95
Yemen2013$weightcats[Yemen2013$gender == 1 & Yemen2013$agecats ==2 & Yemen2013$Educcats ==1 & Yemen2013$Mar2 ==1 & Yemen2013$Empl ==1 & Yemen2013$Surveytype == 1 ]	<-	96

table(Yemen2013$weightcats)

Yemen2013nomiss <- Yemen2013[Yemen2013$weightcats != 99999,]
table(Yemen2013nomiss$weightcats)

prop.table(table(Yemen2013nomiss$weightcats, Yemen2013nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 11	20	22	80

Yemen2013nomiss2 <- Yemen2013nomiss[Yemen2013nomiss$weightcats != 11 & Yemen2013nomiss$weightcats != 20 & Yemen2013nomiss$weightcats != 22 & Yemen2013nomiss$weightcats != 80,]
table(Yemen2013nomiss2$weightcats)

Yemen13.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"9", 	"10", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"21", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"33", 	"34", 	"35", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"55", 	"56", 	"57", 	"58", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"69", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"81", 	"82", 	"83", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94"), 
 Freq = nrow(Yemen2013nomiss2) * c(	0.0068399453, 	0.0560875513, 	0.0127678979, 	0.0793433653, 	0.0196078431, 	0.0205198358, 	0.0018239854, 	0.0004559964, 	0.0022799818, 	0.0013679891, 	0.0186958504, 	0.0287277702, 	0.0009119927, 	0.0104879161, 	0.0022799818, 	0.0109439124, 	0.0009119927, 	0.0009119927, 	0.0269037848, 	0.0018239854, 	0.07250342, 	0.0054719562, 	0.0205198358, 	0.0004559964, 	0.0031919745, 	0.0200638395, 	0.0022799818, 	0.0009119927, 	0.0127678979, 	0.0027359781, 	0.0009119927, 	0.0031919745, 	0.0009119927, 	0.0004559964, 	0.0004559964, 	0.0013679891, 	0.0004559964, 	0.0004559964, 	0.0068399453, 	0.0560875513, 	0.0127678979, 	0.0793433653, 	0.0196078431, 	0.0205198358, 	0.0018239854, 	0.0004559964, 	0.0022799818, 	0.0013679891, 	0.0186958504, 	0.0287277702, 	0.0009119927, 	0.0104879161, 	0.0022799818, 	0.0109439124, 	0.0009119927, 	0.0009119927, 	0.0269037848, 	0.0018239854, 	0.07250342, 	0.0054719562, 	0.0205198358, 	0.0004559964,	0.0031919745, 	0.0200638395, 	0.0022799818, 	0.0009119927, 	0.0127678979, 	0.0027359781, 	0.0009119927, 	0.0031919745, 	0.0009119927, 	0.0004559964, 	0.0004559964, 	0.0013679891, 	0.0004559964, 	0.0004559964))

Yemen2013w <- svydesign(ids=~1, data = Yemen2013nomiss2)

Yemen2013weighted <- rake(design = Yemen2013w,
                          sample.margins = list(~weightcats),
                          population.margins = list(Yemen13.distribution))

table(Yemen2013nomiss2$Surveytype)
svytable(~Surveytype, Yemen2013weighted)
#WORKED.

table(Yemen2013nomiss2$gender)
svytable(~gender, Yemen2013weighted)
#worked.

table(Yemen2013nomiss2$gender, Yemen2013nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Yemen2013weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES YEMEN2013 WEIGHTED############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Yemen2013weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Yemen2013weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Yemen2013weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Yemen2013weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Yemen2013weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Yemen2013weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Yemen2013weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Yemen2013weighted, Surveytype ==1)))


#TRUST
mYemen2013weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21b)

mYemen2013weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21c)

mYemen2013weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21c2)

mYemen2013weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21d)

mYemen2013weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21d2)

mYemen2013weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21e)

mYemen2013weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21e2)

mYemen2013weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21f)

mYemen2013weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted, family = quasibinomial)
summary(mYemen2013weighted21f2)


#TRUST POL
mYemen20132b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Yemen2013nomiss)
summary(mYemen20132b)

mYemen20132b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Yemen2013nomiss)
summary(mYemen20132b2)

mYemen2013weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24c)

mYemen2013weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24c2)

mYemen2013weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24d)

mYemen2013weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24d2)

mYemen2013weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24e)

mYemen2013weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24e2)

mYemen2013weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24f)

mYemen2013weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted24f2)


#EDUC GE
mYemen2013weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22b)

mYemen2013weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22b2)

mYemen2013weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22c)

mYemen2013weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22c2)

mYemen2013weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22d)

mYemen2013weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22d2)

mYemen2013weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22e)

mYemen2013weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22e2)

mYemen2013weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22f)

mYemen2013weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted22f2)



#POL GE
mYemen20132b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Yemen2013nomiss)
summary(mYemen20132b)

mYemen20132b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Yemen2013nomiss)
summary(mYemen20132b2)

mYemen2013weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23c)

mYemen2013weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23c2)

mYemen2013weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23d)

mYemen2013weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23d2)

mYemen2013weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23e)

mYemen2013weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23e2)

mYemen2013weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23f)

mYemen2013weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Yemen2013weighted)
summary(mYemen2013weighted23f2)









##################################################################################################################
##################################################################################################################
###########################################CREATING WEIGHTS EGYPT 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Egypt2018 <- ABWVS20132018[ABWVS20132018$country == "Egypt" & ABWVS20132018$year == 2018,]
table(Egypt2018$country)
table(Egypt2018$year)

Egypt2018$weightcats <- 99999
table(Egypt2018$weightcats)


Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	1
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	2
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	3
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	4
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	5
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	6

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	7
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	8
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	9
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	10
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	11
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	12

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	13
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	14
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	15
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	16
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	17
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	18

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	19
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	20
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	21
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	22
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	23
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 0 ]	<-	24

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	25
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	26
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	27
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	28
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	29
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	30

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	31
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	32
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	33
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	34
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	35
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	36

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	37
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	38
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	39
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	40
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	41
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	42

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	43
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	44
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	45
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	46
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	47
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 0 ]	<-	48



Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	49
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	50
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	51
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	52
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	53
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	54

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	55
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	56
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	57
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	58
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	59
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	60

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	61
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	62
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	63
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	64
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	65
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	66

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	67
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	68
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	69
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	70
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	71
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==0 & Egypt2018$Surveytype == 1 ]	<-	72

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	73
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	74
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	75
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	76
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	77
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	78

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	79
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	80
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	81
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	82
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	83
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==0 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	84

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	85
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	86
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	87
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	88
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	89
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==0 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	90

Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	91
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==0 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	92
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	93
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==1 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	94
Egypt2018$weightcats[Egypt2018$gender == 0 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	95
Egypt2018$weightcats[Egypt2018$gender == 1 & Egypt2018$agecats ==2 & Egypt2018$Educcats ==1 & Egypt2018$Mar2 ==1 & Egypt2018$Empl ==1 & Egypt2018$Surveytype == 1 ]	<-	96

table(Egypt2018$weightcats)

Egypt2018nomiss <- Egypt2018[Egypt2018$weightcats != 99999,]
table(Egypt2018nomiss$weightcats)

prop.table(table(Egypt2018nomiss$weightcats, Egypt2018nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 47	69

Egypt2018nomiss2 <- Egypt2018nomiss[Egypt2018nomiss$weightcats != 47 & Egypt2018nomiss$weightcats != 69,]
table(Egypt2018nomiss2$weightcats)

Egypt18.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"22", 	"23", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"55", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"70", 	"71", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"96"), 
Freq = nrow(Egypt2018nomiss2) * c(	0.0005621135, 	0.0168634064, 	0.0036537381, 	0.0472175379, 	0.0081506464, 	0.0154581225, 	0.0002810568, 	0.0059021922, 	0.0002810568, 	0.00871276, 	0.0016863406, 	0.0019673974, 	0.0129286116, 	0.0106801574, 	0.0002810568, 	0.0092748735, 	0.0019673974, 	0.0163012929, 	0.0028105677, 	0.0016863406, 	0.0014052839, 	0.0005621135, 	0.0005621135, 	0.0075885329, 	0.0011242271, 	0.0486228218, 	0.0047779651, 	0.0269814503, 	0.002529511, 	0.0016863406, 	0.0019673974, 	0.0137717819, 	0.0047779651, 	0.00871276, 	0.0008431703, 	0.0151770658, 	0.0011242271, 	0.0059021922, 	0.0036537381, 	0.0030916245, 	0.0022484542, 	0.0053400787, 	0.0014052839, 	0.0036537381, 	0.0016863406, 	0.0005621135, 	0.0005621135, 	0.0168634064, 	0.0036537381, 	0.0472175379, 	0.0081506464, 	0.0154581225, 	0.0002810568, 	0.0059021922, 	0.0002810568, 	0.00871276, 	0.0016863406, 	0.0019673974, 	0.0129286116, 	0.0106801574, 	0.0002810568, 	0.0092748735,	0.0019673974, 	0.0163012929, 	0.0028105677, 	0.0016863406, 	0.0014052839, 	0.0005621135, 	0.0005621135, 	0.0075885329, 	0.0011242271, 	0.0486228218, 	0.0047779651, 	0.0269814503, 	0.002529511, 	0.0016863406, 	0.0019673974, 	0.0137717819,	0.0047779651, 	0.00871276,	0.0008431703, 	0.0151770658, 	0.0011242271, 	0.0059021922, 	0.0036537381, 	0.0030916245, 	0.0022484542, 	0.0053400787, 	0.0014052839, 	0.0036537381, 	0.0016863406, 	0.0005621135))

Egypt2018w <- svydesign(ids=~1, data = Egypt2018nomiss2)

Egypt2018weighted <- rake(design = Egypt2018w,
                          sample.margins = list(~weightcats),
                          population.margins = list(Egypt18.distribution))

table(Egypt2018nomiss2$Surveytype)
svytable(~Surveytype, Egypt2018weighted)
#WORKED.

table(Egypt2018nomiss2$gender)
svytable(~gender, Egypt2018weighted)
#worked.

table(Egypt2018nomiss2$gender, Egypt2018nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Egypt2018weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES EGYPT2018 WEIGHTED##############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Egypt2018weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Egypt2018weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Egypt2018weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Egypt2018weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Egypt2018weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Egypt2018weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Egypt2018weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Egypt2018weighted, Surveytype ==1)))


#TRUST
mEgypt2018weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21b)

mEgypt2018weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21c)

mEgypt2018weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21c2)

mEgypt2018weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21d)

mEgypt2018weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21d2)

mEgypt2018weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21e)

mEgypt2018weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21e2)

mEgypt2018weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21f)

mEgypt2018weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted, family = quasibinomial)
summary(mEgypt2018weighted21f2)


#TRUST POL
mEgypt20182b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt2018nomiss)
summary(mEgypt20182b)

mEgypt20182b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt2018nomiss)
summary(mEgypt20182b2)

mEgypt2018weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24c)

mEgypt2018weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24c2)

mEgypt2018weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24d)

mEgypt2018weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24d2)

mEgypt2018weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24e)

mEgypt2018weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24e2)

mEgypt2018weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24f)

mEgypt2018weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted24f2)


#EDUC GE
mEgypt2018weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22b)

mEgypt2018weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22b2)

mEgypt2018weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22c)

mEgypt2018weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22c2)

mEgypt2018weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22d)

mEgypt2018weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22d2)

mEgypt2018weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22e)

mEgypt2018weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22e2)

mEgypt2018weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22f)

mEgypt2018weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted22f2)



#POL GE
mEgypt20182b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt2018nomiss)
summary(mEgypt20182b)

mEgypt20182b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt2018nomiss)
summary(mEgypt20182b2)

mEgypt2018weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23c)

mEgypt2018weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23c2)

mEgypt2018weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23d)

mEgypt2018weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23d2)

mEgypt2018weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23e)

mEgypt2018weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23e2)

mEgypt2018weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23f)

mEgypt2018weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Egypt2018weighted)
summary(mEgypt2018weighted23f2)





##################################################################################################################
##################################################################################################################
###########################################CREATING WEIGHTS IRAQ 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Iraq2018 <- ABWVS20132018[ABWVS20132018$country == "Iraq" & ABWVS20132018$year == 2018,]
table(Iraq2018$country)
table(Iraq2018$year)

Iraq2018$weightcats <- 99999
table(Iraq2018$weightcats)


Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	1
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	2
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	3
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	4
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	5
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	6

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	7
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	8
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	9
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	10
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	11
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	12

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	13
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	14
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	15
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	16
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	17
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	18

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	19
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	20
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	21
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	22
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	23
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 0 ]	<-	24

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	25
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	26
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	27
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	28
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	29
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	30

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	31
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	32
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	33
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	34
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	35
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	36

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	37
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	38
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	39
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	40
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	41
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	42

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	43
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	44
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	45
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	46
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	47
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 0 ]	<-	48



Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	49
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	50
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	51
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	52
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	53
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	54

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	55
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	56
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	57
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	58
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	59
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	60

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	61
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	62
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	63
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	64
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	65
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	66

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	67
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	68
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	69
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	70
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	71
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==0 & Iraq2018$Surveytype == 1 ]	<-	72

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	73
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	74
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	75
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	76
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	77
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	78

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	79
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	80
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	81
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	82
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	83
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==0 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	84

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	85
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	86
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	87
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	88
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	89
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==0 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	90

Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	91
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==0 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	92
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	93
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==1 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	94
Iraq2018$weightcats[Iraq2018$gender == 0 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	95
Iraq2018$weightcats[Iraq2018$gender == 1 & Iraq2018$agecats ==2 & Iraq2018$Educcats ==1 & Iraq2018$Mar2 ==1 & Iraq2018$Empl ==1 & Iraq2018$Surveytype == 1 ]	<-	96

table(Iraq2018$weightcats)

Iraq2018nomiss <- Iraq2018[Iraq2018$weightcats != 99999,]
table(Iraq2018nomiss$weightcats)

prop.table(table(Iraq2018nomiss$weightcats, Iraq2018nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 23

Iraq2018nomiss2 <- Iraq2018nomiss[Iraq2018nomiss$weightcats != 23,]
table(Iraq2018nomiss2$weightcats)

Iraq18.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"47", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"55", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"95", 	"96"), 
Freq = nrow(Iraq2018nomiss2) * c(	0.0047078372, 	0.0238161174, 	0.0102464691, 	0.0373857657, 	0.0124619219, 	0.0166158959, 	0.0005538632, 	0.0049847688, 	0.0024923844, 	0.0060924952, 	0.0008307948, 	0.001384658, 	0.0168928275, 	0.0155081695, 	0.0016615896, 	0.005538632, 	0.0016615896, 	0.005538632, 	0.0066463583, 	0.005538632, 	0.001384658, 	0.0005538632, 	0.0005538632, 	0.0160620327, 	0.005538632, 	0.0257546386, 	0.0060924952, 	0.0141235115, 	0.0033231792, 	0.004153974, 	0.0030462476, 	0.0210468014, 	0.0124619219, 	0.0024923844, 	0.0002769316, 	0.0099695375, 	0.001384658, 	0.0022154528, 	0.0005538632, 	0.001384658, 	0.0016615896, 	0.004153974, 	0.002769316, 	0.0016615896, 	0.0002769316, 	0.0008307948, 	0.0005538632, 	0.0047078372, 	0.0238161174, 	0.0102464691, 	0.0373857657, 	0.0124619219, 	0.0166158959, 	0.0005538632, 	0.0049847688, 	0.0024923844, 	0.0060924952, 	0.0008307948, 	0.001384658, 	0.0168928275, 	0.0155081695, 	0.0016615896,	0.005538632, 	0.0016615896, 	0.005538632, 	0.0066463583, 	0.005538632, 	0.001384658, 	0.0005538632, 	0.0005538632, 	0.0160620327, 	0.005538632, 	0.0257546386, 	0.0060924952, 	0.0141235115, 	0.0033231792, 	0.004153974, 	0.0030462476,	0.0210468014, 	0.0124619219,	0.0024923844, 	0.0002769316, 	0.0099695375, 	0.001384658, 	0.0022154528, 	0.0005538632, 	0.001384658, 	0.0016615896, 	0.004153974, 	0.002769316, 	0.0016615896, 	0.0002769316, 	0.0008307948, 	0.0005538632))

Iraq2018w <- svydesign(ids=~1, data = Iraq2018nomiss2)

Iraq2018weighted <- rake(design = Iraq2018w,
                         sample.margins = list(~weightcats),
                         population.margins = list(Iraq18.distribution))

table(Iraq2018nomiss2$Surveytype)
svytable(~Surveytype, Iraq2018weighted)
#WORKED.

table(Iraq2018nomiss2$gender)
svytable(~gender, Iraq2018weighted)
#worked.

table(Iraq2018nomiss2$gender, Iraq2018nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Iraq2018weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES IRAQ2018 WEIGHTED##############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Iraq2018weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Iraq2018weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Iraq2018weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Iraq2018weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Iraq2018weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Iraq2018weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Iraq2018weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Iraq2018weighted, Surveytype ==1)))


#TRUST
mIraq2018weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21b)

mIraq2018weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21c)

mIraq2018weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21c2)

mIraq2018weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21d)

mIraq2018weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21d2)

mIraq2018weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21e)

mIraq2018weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21e2)

mIraq2018weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21f)

mIraq2018weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted, family = quasibinomial)
summary(mIraq2018weighted21f2)


#TRUST POL
mIraq20182b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq2018nomiss)
summary(mIraq20182b)

mIraq20182b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq2018nomiss)
summary(mIraq20182b2)

mIraq2018weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24c)

mIraq2018weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24c2)

mIraq2018weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24d)

mIraq2018weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24d2)

mIraq2018weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24e)

mIraq2018weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24e2)

mIraq2018weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24f)

mIraq2018weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted24f2)


#EDUC GE
mIraq2018weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22b)

mIraq2018weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22b2)

mIraq2018weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22c)

mIraq2018weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22c2)

mIraq2018weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22d)

mIraq2018weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22d2)

mIraq2018weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22e)

mIraq2018weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22e2)

mIraq2018weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22f)

mIraq2018weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted22f2)



#POL GE
mIraq20182b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq2018nomiss)
summary(mIraq20182b)

mIraq20182b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq2018nomiss)
summary(mIraq20182b2)

mIraq2018weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23c)

mIraq2018weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23c2)

mIraq2018weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23d)

mIraq2018weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23d2)

mIraq2018weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23e)

mIraq2018weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23e2)

mIraq2018weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23f)

mIraq2018weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Iraq2018weighted)
summary(mIraq2018weighted23f2)









##################################################################################################################
##################################################################################################################
###########################################CREATING WEIGHTS JORDAN 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Jordan2018 <- ABWVS20132018[ABWVS20132018$country == "Jordan" & ABWVS20132018$year == 2018,]
table(Jordan2018$country)
table(Jordan2018$year)

Jordan2018$weightcats <- 99999
table(Jordan2018$weightcats)


Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	1
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	2
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	3
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	4
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	5
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	6

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	7
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	8
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	9
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	10
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	11
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	12

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	13
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	14
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	15
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	16
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	17
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	18

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	19
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	20
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	21
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	22
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	23
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 0 ]	<-	24

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	25
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	26
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	27
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	28
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	29
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	30

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	31
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	32
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	33
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	34
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	35
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	36

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	37
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	38
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	39
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	40
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	41
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	42

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	43
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	44
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	45
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	46
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	47
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 0 ]	<-	48



Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	49
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	50
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	51
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	52
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	53
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	54

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	55
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	56
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	57
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	58
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	59
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	60

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	61
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	62
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	63
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	64
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	65
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	66

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	67
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	68
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	69
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	70
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	71
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==0 & Jordan2018$Surveytype == 1 ]	<-	72

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	73
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	74
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	75
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	76
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	77
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	78

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	79
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	80
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	81
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	82
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	83
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==0 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	84

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	85
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	86
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	87
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	88
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	89
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==0 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	90

Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	91
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==0 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	92
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	93
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==1 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	94
Jordan2018$weightcats[Jordan2018$gender == 0 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	95
Jordan2018$weightcats[Jordan2018$gender == 1 & Jordan2018$agecats ==2 & Jordan2018$Educcats ==1 & Jordan2018$Mar2 ==1 & Jordan2018$Empl ==1 & Jordan2018$Surveytype == 1 ]	<-	96

table(Jordan2018$weightcats)

Jordan2018nomiss <- Jordan2018[Jordan2018$weightcats != 99999,]
table(Jordan2018nomiss$weightcats)

prop.table(table(Jordan2018nomiss$weightcats, Jordan2018nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 26	95

Jordan2018nomiss2 <- Jordan2018nomiss[Jordan2018nomiss$weightcats != 26 & Jordan2018nomiss$weightcats != 95,]
table(Jordan2018nomiss2$weightcats)

Jordan18.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"23", 	"24", 	"25", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"55", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"71", 	"72", 	"73", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"96"), 
Freq = nrow(Jordan2018nomiss2) * c(	0.0005563282, 	0.0105702364, 	0.0091794159, 	0.0436717663, 	0.033379694, 	0.0225312935, 	0.0005563282, 	0.0050069541, 	0.0022253129, 	0.0100139082, 	0.0086230876, 	0.0052851182, 	0.0169680111, 	0.0055632823, 	0.0011126565, 	0.0083449235, 	0.0019471488, 	0.0222531293, 	0.0050069541, 	0.0013908206, 	0.0002781641, 	0.0013908206, 	0.0002781641, 	0.0022253129, 	0.0052851182, 	0.0289290682, 	0.0050069541, 	0.0125173853, 	0.0011126565, 	0.0008344924, 	0.0016689847, 	0.0116828929, 	0.0105702364, 	0.00472879, 	0.0016689847, 	0.0125173853, 	0.0011126565, 	0.0044506259, 	0.0011126565, 	0.0002781641, 	0.0008344924, 	0.0044506259, 	0.0005563282, 	0.0030598053, 	0.0025034771, 	0.0002781641, 	0.0005563282, 	0.0105702364, 	0.0091794159, 	0.0436717663, 	0.033379694, 	0.0225312935, 	0.0005563282, 	0.0050069541, 	0.0022253129, 	0.0100139082, 	0.0086230876, 	0.0052851182, 	0.0169680111, 	0.0055632823, 	0.0011126565, 	0.0083449235,	0.0019471488, 	0.0222531293, 	0.0050069541, 	0.0013908206, 	0.0002781641, 	0.0013908206, 	0.0002781641, 	0.0022253129, 	0.0052851182, 	0.0289290682, 	0.0050069541, 	0.0125173853, 	0.0011126565, 	0.0008344924, 	0.0016689847, 	0.0116828929,	0.0105702364, 	0.00472879,	0.0016689847, 	0.0125173853, 	0.0011126565, 	0.0044506259, 	0.0011126565, 	0.0002781641, 	0.0008344924, 	0.0044506259, 	0.0005563282, 	0.0030598053, 	0.0025034771, 	0.0002781641))

Jordan2018w <- svydesign(ids=~1, data = Jordan2018nomiss2)

Jordan2018weighted <- rake(design = Jordan2018w,
                           sample.margins = list(~weightcats),
                           population.margins = list(Jordan18.distribution))

table(Jordan2018nomiss2$Surveytype)
svytable(~Surveytype, Jordan2018weighted)
#WORKED.

table(Jordan2018nomiss2$gender)
svytable(~gender, Jordan2018weighted)
#worked.

table(Jordan2018nomiss2$gender, Jordan2018nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Jordan2018weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES JORDAN2018 WEIGHTED#############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Jordan2018weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Jordan2018weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Jordan2018weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Jordan2018weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Jordan2018weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Jordan2018weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Jordan2018weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Jordan2018weighted, Surveytype ==1)))


#TRUST
mJordan2018weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21b)

mJordan2018weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21c)

mJordan2018weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21c2)

mJordan2018weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21d)

mJordan2018weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21d2)

mJordan2018weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21e)

mJordan2018weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21e2)

mJordan2018weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21f)

mJordan2018weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted, family = quasibinomial)
summary(mJordan2018weighted21f2)


#TRUST POL
mJordan20182b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan2018nomiss)
summary(mJordan20182b)

mJordan20182b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan2018nomiss)
summary(mJordan20182b2)

mJordan2018weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24c)

mJordan2018weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24c2)

mJordan2018weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24d)

mJordan2018weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24d2)

mJordan2018weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24e)

mJordan2018weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24e2)

mJordan2018weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24f)

mJordan2018weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted24f2)


#EDUC GE
mJordan2018weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22b)

mJordan2018weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22b2)

mJordan2018weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22c)

mJordan2018weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22c2)

mJordan2018weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22d)

mJordan2018weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22d2)

mJordan2018weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22e)

mJordan2018weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22e2)

mJordan2018weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22f)

mJordan2018weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted22f2)



#POL GE
mJordan20182b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan2018nomiss)
summary(mJordan20182b)

mJordan20182b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan2018nomiss)
summary(mJordan20182b2)

mJordan2018weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23c)

mJordan2018weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23c2)

mJordan2018weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23d)

mJordan2018weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23d2)

mJordan2018weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23e)

mJordan2018weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23e2)

mJordan2018weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23f)

mJordan2018weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Jordan2018weighted)
summary(mJordan2018weighted23f2)





##################################################################################################################
##################################################################################################################
###########################################CREATING WEIGHTS LEBANON 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Lebanon2018 <- ABWVS20132018[ABWVS20132018$country == "Lebanon" & ABWVS20132018$year == 2018,]
table(Lebanon2018$country)
table(Lebanon2018$year)

Lebanon2018$weightcats <- 99999
table(Lebanon2018$weightcats)


Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	1
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	2
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	3
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	4
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	5
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	6

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	7
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	8
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	9
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	10
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	11
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	12

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	13
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	14
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	15
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	16
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	17
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	18

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	19
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	20
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	21
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	22
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	23
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 0 ]	<-	24

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	25
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	26
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	27
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	28
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	29
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	30

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	31
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	32
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	33
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	34
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	35
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	36

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	37
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	38
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	39
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	40
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	41
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	42

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	43
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	44
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	45
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	46
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	47
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 0 ]	<-	48



Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	49
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	50
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	51
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	52
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	53
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	54

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	55
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	56
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	57
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	58
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	59
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	60

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	61
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	62
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	63
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	64
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	65
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	66

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	67
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	68
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	69
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	70
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	71
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==0 & Lebanon2018$Surveytype == 1 ]	<-	72

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	73
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	74
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	75
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	76
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	77
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	78

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	79
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	80
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	81
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	82
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	83
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==0 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	84

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	85
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	86
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	87
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	88
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	89
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==0 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	90

Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	91
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==0 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	92
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	93
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==1 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	94
Lebanon2018$weightcats[Lebanon2018$gender == 0 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	95
Lebanon2018$weightcats[Lebanon2018$gender == 1 & Lebanon2018$agecats ==2 & Lebanon2018$Educcats ==1 & Lebanon2018$Mar2 ==1 & Lebanon2018$Empl ==1 & Lebanon2018$Surveytype == 1 ]	<-	96

table(Lebanon2018$weightcats)

Lebanon2018nomiss <- Lebanon2018[Lebanon2018$weightcats != 99999,]
table(Lebanon2018nomiss$weightcats)

prop.table(table(Lebanon2018nomiss$weightcats, Lebanon2018nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 69

Lebanon2018nomiss2 <- Lebanon2018nomiss[Lebanon2018nomiss$weightcats != 69,]
table(Lebanon2018nomiss2$weightcats)

Lebanon18.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"7", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"22", 	"23", 	"24", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"31", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"47", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"55", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"70", 	"71", 	"72", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"79", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"95", 	"96"), 
Freq = nrow(Lebanon2018nomiss2) * c(	0.0005560189, 	0.0044481512, 	0.0005560189, 	0.0247428413, 	0.0047261607, 	0.0161245482, 	0.0002780095, 	0.0016680567, 	0.0002780095, 	0.0066722269, 	0.0022240756, 	0.003058104, 	0.0069502363, 	0.0094523214, 	0.0019460662, 	0.0019460662, 	0.0019460662, 	0.0058381985, 	0.0083402836, 	0.0111203781, 	0.0005560189, 	0.0005560189, 	0.0013900473, 	0.0038921323, 	0.0016680567, 	0.031971087, 	0.0139004726, 	0.0308590492, 	0.0066722269, 	0.0013900473, 	0.0038921323, 	0.0150125104, 	0.0130664443, 	0.0088963025, 	0.0033361134, 	0.0161245482, 	0.0058381985, 	0.008618293, 	0.0033361134, 	0.0027800945, 	0.006116208, 	0.0127884348, 	0.0125104254, 	0.0052821796, 	0.0066722269, 	0.0008340284, 	0.0027800945, 	0.0005560189, 	0.0044481512, 	0.0005560189, 	0.0247428413, 	0.0047261607, 	0.0161245482, 	0.0002780095, 	0.0016680567, 	0.0002780095, 	0.0066722269, 	0.0022240756, 	0.003058104, 	0.0069502363, 	0.0094523214, 	0.0019460662,	0.0019460662, 	0.0019460662, 	0.0058381985, 	0.0083402836, 	0.0111203781, 	0.0005560189, 	0.0005560189, 	0.0013900473, 	0.0038921323, 	0.0016680567, 	0.031971087, 	0.0139004726, 	0.0308590492, 	0.0066722269, 	0.0013900473, 	0.0038921323,	0.0150125104, 	0.0130664443,	0.0088963025, 	0.0033361134, 	0.0161245482, 	0.0058381985, 	0.008618293, 	0.0033361134, 	0.0027800945, 	0.006116208, 	0.0127884348, 	0.0125104254, 	0.0052821796, 	0.0066722269, 	0.0008340284, 	0.0027800945))

Lebanon2018w <- svydesign(ids=~1, data = Lebanon2018nomiss2)

Lebanon2018weighted <- rake(design = Lebanon2018w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Lebanon18.distribution))

table(Lebanon2018nomiss2$Surveytype)
svytable(~Surveytype, Lebanon2018weighted)
#WORKED.

table(Lebanon2018nomiss2$gender)
svytable(~gender, Lebanon2018weighted)
#worked.

table(Lebanon2018nomiss2$gender, Lebanon2018nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Lebanon2018weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES LEBANON2018 WEIGHTED#############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Lebanon2018weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Lebanon2018weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Lebanon2018weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Lebanon2018weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Lebanon2018weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Lebanon2018weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Lebanon2018weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Lebanon2018weighted, Surveytype ==1)))


#TRUST
mLebanon2018weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21b)

mLebanon2018weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21c)

mLebanon2018weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21c2)

mLebanon2018weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21d)

mLebanon2018weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21d2)

mLebanon2018weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21e)

mLebanon2018weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21e2)

mLebanon2018weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21f)

mLebanon2018weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted, family = quasibinomial)
summary(mLebanon2018weighted21f2)


#TRUST POL
mLebanon20182b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2018nomiss)
summary(mLebanon20182b)

mLebanon20182b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2018nomiss)
summary(mLebanon20182b2)

mLebanon2018weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24c)

mLebanon2018weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24c2)

mLebanon2018weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24d)

mLebanon2018weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24d2)

mLebanon2018weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24e)

mLebanon2018weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24e2)

mLebanon2018weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24f)

mLebanon2018weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted24f2)


#EDUC GE
mLebanon2018weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22b)

mLebanon2018weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22b2)

mLebanon2018weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22c)

mLebanon2018weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22c2)

mLebanon2018weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22d)

mLebanon2018weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22d2)

mLebanon2018weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22e)

mLebanon2018weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22e2)

mLebanon2018weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22f)

mLebanon2018weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted22f2)



#POL GE
mLebanon20182b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2018nomiss)
summary(mLebanon20182b)

mLebanon20182b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon2018nomiss)
summary(mLebanon20182b2)

mLebanon2018weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23c)

mLebanon2018weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23c2)

mLebanon2018weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23d)

mLebanon2018weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23d2)

mLebanon2018weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23e)

mLebanon2018weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23e2)

mLebanon2018weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23f)

mLebanon2018weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Lebanon2018weighted)
summary(mLebanon2018weighted23f2)




  

##################################################################################################################
##################################################################################################################
###########################################CREATING WEIGHTS TUNISIA 2013############################################
##################################################################################################################
##################################################################################################################
table (ABWVS20132018$country)
table (ABWVS20132018$year)

Tunisia2018 <- ABWVS20132018[ABWVS20132018$country == "Tunisia" & ABWVS20132018$year == 2018,]
table(Tunisia2018$country)
table(Tunisia2018$year)

Tunisia2018$weightcats <- 99999
table(Tunisia2018$weightcats)


Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	1
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	2
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	3
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	4
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	5
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	6

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	7
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	8
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	9
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	10
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	11
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	12

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	13
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	14
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	15
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	16
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	17
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	18

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	19
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	20
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	21
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	22
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	23
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 0 ]	<-	24

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	25
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	26
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	27
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	28
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	29
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	30

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	31
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	32
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	33
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	34
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	35
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	36

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	37
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	38
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	39
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	40
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	41
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	42

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	43
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	44
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	45
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	46
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	47
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 0 ]	<-	48



Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	49
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	50
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	51
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	52
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	53
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	54

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	55
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	56
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	57
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	58
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	59
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	60

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	61
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	62
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	63
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	64
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	65
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	66

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	67
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	68
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	69
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	70
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	71
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==0 & Tunisia2018$Surveytype == 1 ]	<-	72

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	73
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	74
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	75
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	76
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	77
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	78

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	79
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	80
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	81
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	82
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	83
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==0 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	84

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	85
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	86
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	87
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	88
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	89
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==0 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	90

Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	91
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==0 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	92
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	93
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==1 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	94
Tunisia2018$weightcats[Tunisia2018$gender == 0 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	95
Tunisia2018$weightcats[Tunisia2018$gender == 1 & Tunisia2018$agecats ==2 & Tunisia2018$Educcats ==1 & Tunisia2018$Mar2 ==1 & Tunisia2018$Empl ==1 & Tunisia2018$Surveytype == 1 ]	<-	96

table(Tunisia2018$weightcats)

Tunisia2018nomiss <- Tunisia2018[Tunisia2018$weightcats != 99999,]
table(Tunisia2018nomiss$weightcats)

prop.table(table(Tunisia2018nomiss$weightcats, Tunisia2018nomiss$Surveytype))
#cats without respondents in their accompanying WVS/AB countercategory: 72	79

Tunisia2018nomiss2 <- Tunisia2018nomiss[Tunisia2018nomiss$weightcats != 72 & Tunisia2018nomiss$weightcats != 79,]
table(Tunisia2018nomiss2$weightcats)

Tunisia18.distribution <- data.frame(weightcats = c(	"1", 	"2", 	"3", 	"4", 	"5", 	"6", 	"8", 	"9", 	"10", 	"11", 	"12", 	"13", 	"14", 	"15", 	"16", 	"17", 	"18", 	"19", 	"20", 	"21", 	"22", 	"23", 	"25", 	"26", 	"27", 	"28", 	"29", 	"30", 	"32", 	"33", 	"34", 	"35", 	"36", 	"37", 	"38", 	"39", 	"40", 	"41", 	"42", 	"43", 	"44", 	"45", 	"46", 	"48", 	"49", 	"50", 	"51", 	"52", 	"53", 	"54", 	"56", 	"57", 	"58", 	"59", 	"60", 	"61", 	"62", 	"63", 	"64", 	"65", 	"66", 	"67", 	"68", 	"69", 	"70", 	"71", 	"73", 	"74", 	"75", 	"76", 	"77", 	"78", 	"80", 	"81", 	"82", 	"83", 	"84", 	"85", 	"86", 	"87", 	"88", 	"89", 	"90", 	"91", 	"92", 	"93", 	"94", 	"96"), 
Freq = nrow(Tunisia2018nomiss2) * c(	0.0014156285, 	0.0053793884, 	0.0036806342, 	0.0339750849, 	0.0178369196, 	0.0294450736, 	0.0011325028, 	0.0005662514, 	0.0036806342, 	0.0016987542, 	0.0002831257, 	0.011608154, 	0.0127406569, 	0.0039637599, 	0.0056625142, 	0.0016987542, 	0.0181200453, 	0.0016987542, 	0.0082106455, 	0.0014156285, 	0.0005662514, 	0.0005662514, 	0.0028312571, 	0.0031143828, 	0.0305775764, 	0.0144394111, 	0.025198188, 	0.0090600227, 	0.0008493771, 	0.0082106455, 	0.0045300113, 	0.0014156285, 	0.0008493771, 	0.0172706682, 	0.0059456399, 	0.0144394111, 	0.0076443941, 	0.0016987542, 	0.0042468856, 	0.0031143828, 	0.00198188, 	0.0025481314, 	0.0014156285, 	0.0002831257, 	0.0014156285, 	0.0053793884, 	0.0036806342, 	0.0339750849, 	0.0178369196, 	0.0294450736, 	0.0011325028, 	0.0005662514, 	0.0036806342, 	0.0016987542, 	0.0002831257, 	0.011608154, 	0.0127406569, 	0.0039637599, 	0.0056625142, 	0.0016987542, 	0.0181200453, 	0.0016987542,	0.0082106455, 	0.0014156285, 	0.0005662514, 	0.0005662514, 	0.0028312571, 	0.0031143828, 	0.0305775764, 	0.0144394111, 	0.025198188, 	0.0090600227, 	0.0008493771, 	0.0082106455, 	0.0045300113, 	0.0014156285, 	0.0008493771, 	0.0172706682,	0.0059456399, 	0.0144394111,	0.0076443941, 	0.0016987542, 	0.0042468856, 	0.0031143828, 	0.00198188, 	0.0025481314, 	0.0014156285, 	0.0002831257))

Tunisia2018w <- svydesign(ids=~1, data = Tunisia2018nomiss2)

Tunisia2018weighted <- rake(design = Tunisia2018w,
                            sample.margins = list(~weightcats),
                            population.margins = list(Tunisia18.distribution))

table(Tunisia2018nomiss2$Surveytype)
svytable(~Surveytype, Tunisia2018weighted)
#WORKED.

table(Tunisia2018nomiss2$gender)
svytable(~gender, Tunisia2018weighted)
#worked.

table(Tunisia2018nomiss2$gender, Tunisia2018nomiss2$Surveytype)
svytable(~interaction(gender, Surveytype), design = Tunisia2018weighted)
#WORKED.



##################################################################################################################
##################################################################################################################
#########################################ANALYSES TUNISIA2018 WEIGHTED#############################################
##################################################################################################################
##################################################################################################################

prop.table(svytable(~Trust, subset(Tunisia2018weighted, Surveytype ==0)))
prop.table(svytable(~Trust, subset(Tunisia2018weighted, Surveytype ==1)))

prop.table(svytable(~Trustpol, subset(Tunisia2018weighted, Surveytype ==0)))
prop.table(svytable(~Trustpol, subset(Tunisia2018weighted, Surveytype ==1))) 

prop.table(svytable(~Unieduc, subset(Tunisia2018weighted, Surveytype ==0)))
prop.table(svytable(~Unieduc, subset(Tunisia2018weighted, Surveytype ==1)))

prop.table(svytable(~PolLead, subset(Tunisia2018weighted, Surveytype ==0)))
prop.table(svytable(~PolLead, subset(Tunisia2018weighted, Surveytype ==1)))


#TRUST
mTunisia2018weighted21b <- svyglm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21b)

mTunisia2018weighted21c <- svyglm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21c)

mTunisia2018weighted21c2 <- svyglm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21c2)

mTunisia2018weighted21d <- svyglm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21d)

mTunisia2018weighted21d2 <- svyglm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21d2)

mTunisia2018weighted21e <- svyglm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21e)

mTunisia2018weighted21e2 <- svyglm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21e2)

mTunisia2018weighted21f <- svyglm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21f)

mTunisia2018weighted21f2 <- svyglm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted, family = quasibinomial)
summary(mTunisia2018weighted21f2)


#TRUST POL
mTunisia20182b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2018nomiss)
summary(mTunisia20182b)

mTunisia20182b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2018nomiss)
summary(mTunisia20182b2)

mTunisia2018weighted24c <- svyglm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24c)

mTunisia2018weighted24c2 <- svyglm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24c2)

mTunisia2018weighted24d <- svyglm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24d)

mTunisia2018weighted24d2 <- svyglm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24d2)

mTunisia2018weighted24e <- svyglm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24e)

mTunisia2018weighted24e2 <- svyglm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24e2)

mTunisia2018weighted24f <- svyglm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24f)

mTunisia2018weighted24f2 <- svyglm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted24f2)


#EDUC GE
mTunisia2018weighted22b <- svyglm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22b)

mTunisia2018weighted22b2 <- svyglm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22b2)

mTunisia2018weighted22c <- svyglm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22c)

mTunisia2018weighted22c2 <- svyglm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22c2)

mTunisia2018weighted22d <- svyglm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22d)

mTunisia2018weighted22d2 <- svyglm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22d2)

mTunisia2018weighted22e <- svyglm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22e)

mTunisia2018weighted22e2 <- svyglm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22e2)

mTunisia2018weighted22f <- svyglm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22f)

mTunisia2018weighted22f2 <- svyglm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted22f2)



#POL GE
mTunisia20182b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2018nomiss)
summary(mTunisia20182b)

mTunisia20182b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia2018nomiss)
summary(mTunisia20182b2)

mTunisia2018weighted23c <- svyglm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23c)

mTunisia2018weighted23c2 <- svyglm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23c2)

mTunisia2018weighted23d <- svyglm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23d)

mTunisia2018weighted23d2 <- svyglm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23d2)

mTunisia2018weighted23e <- svyglm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23e)

mTunisia2018weighted23e2 <- svyglm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23e2)

mTunisia2018weighted23f <- svyglm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23f)

mTunisia2018weighted23f2 <- svyglm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, design = Tunisia2018weighted)
summary(mTunisia2018weighted23f2)











##################################################################################################################
##################################################################################################################
#########################################COMPARING DEMOGRAPHIC DISTRIBUTIONS######################################
##################################################################################################################
##################################################################################################################

#########################################DEMOGRAPHICS OVER ALL COUNTRIES##########################################
  
  #gender.
  prop.table(table(ABWVS20132018$gender, ABWVS20132018$Surveytype),2)
  chisq.test(table(ABWVS20132018$gender, ABWVS20132018$Surveytype))
  
  #age.
  aggregate(ABWVS20132018$age_short ~ Surveytype, ABWVS20132018, min)
  aggregate(ABWVS20132018$age_short ~ Surveytype, ABWVS20132018, max)
  aggregate(ABWVS20132018$age_short ~ Surveytype, ABWVS20132018, mean)
  aggregate(ABWVS20132018$age_short ~ Surveytype, ABWVS20132018, sd)
  t.test(ABWVS20132018$age_short ~ ABWVS20132018$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
  
  #education.
  aggregate(ABWVS20132018$Educ ~ Surveytype, ABWVS20132018, min)
  aggregate(ABWVS20132018$Educ ~ Surveytype, ABWVS20132018, max)
  aggregate(ABWVS20132018$Educ ~ Surveytype, ABWVS20132018, mean)
  aggregate(ABWVS20132018$Educ ~ Surveytype, ABWVS20132018, sd)
  t.test(ABWVS20132018$Educ ~ ABWVS20132018$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
  
  #marital status.
  prop.table(table(ABWVS20132018$Mar, ABWVS20132018$Surveytype),2)
  chisq.test(table(ABWVS20132018$Mar, ABWVS20132018$Surveytype))
  
  #employment status.
  prop.table(table(ABWVS20132018$Empl, ABWVS20132018$Surveytype),2)
  chisq.test(table(ABWVS20132018$Empl, ABWVS20132018$Surveytype))

#########################################DEMOGRAPHICS PER SURVEY##################################################

###############################################ALGERIA############################################################
  
table(ABWVS20132018$country)
Algeria <- ABWVS20132018[ABWVS20132018$country == "Algeria",]
table(Algeria$country)
table(ABWVS20132018$country)
table(Algeria$year)

#gender.
prop.table(table(Algeria$gender, Algeria$Surveytype),2)
chisq.test(table(Algeria$gender, Algeria$Surveytype))

#age.
aggregate(Algeria $age_short ~ Surveytype, Algeria, min)
aggregate(Algeria $age_short ~ Surveytype, Algeria, max)
aggregate(Algeria$age_short ~ Surveytype, Algeria, mean)
aggregate(Algeria$age_short ~ Surveytype, Algeria, sd)
t.test(Algeria$age_short ~ Algeria$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Algeria$Educ ~ Surveytype, Algeria, min)
aggregate(Algeria$Educ ~ Surveytype, Algeria, max)
aggregate(Algeria$Educ ~ Surveytype, Algeria, mean)
aggregate(Algeria$Educ ~ Surveytype, Algeria, sd)
t.test(Algeria$Educ ~ Algeria$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Algeria$Mar, Algeria$Surveytype),2)
chisq.test(table(Algeria$Mar, Algeria$Surveytype))

#employment status.
prop.table(table(Algeria$Empl, Algeria$Surveytype),2)
chisq.test(table(Algeria$Empl, Algeria$Surveytype))

#weights
table(Algeria$Surveytype)
prop.table(table(Algeria$Surveytype, Algeria$weightcats),1)



###############################################EGYPT13############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Egypt13 <- ABWVS20132018[ABWVS20132018$country == "Egypt" & ABWVS20132018$year == 2013, ]
table(Egypt13$country)
table(Egypt13$year)

#gender.
prop.table(table(Egypt13$gender, Egypt13$Surveytype),2)
chisq.test(table(Egypt13$gender, Egypt13$Surveytype))

#age.
aggregate(Egypt13 $age_short ~ Surveytype, Egypt13, min)
aggregate(Egypt13 $age_short ~ Surveytype, Egypt13, max)
aggregate(Egypt13$age_short ~ Surveytype, Egypt13, mean)
aggregate(Egypt13$age_short ~ Surveytype, Egypt13, sd)
t.test(Egypt13$age_short ~ Egypt13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Egypt13$Educ ~ Surveytype, Egypt13, min)
aggregate(Egypt13$Educ ~ Surveytype, Egypt13, max)
aggregate(Egypt13$Educ ~ Surveytype, Egypt13, mean)
aggregate(Egypt13$Educ ~ Surveytype, Egypt13, sd)
t.test(Egypt13$Educ ~ Egypt13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Egypt13$Mar, Egypt13$Surveytype),2)
chisq.test(table(Egypt13$Mar, Egypt13$Surveytype))

#employment status.
prop.table(table(Egypt13$Empl, Egypt13$Surveytype),2)
chisq.test(table(Egypt13$Empl, Egypt13$Surveytype))

#weights
table(Egypt13$Surveytype)
prop.table(table(Egypt13$Surveytype, Egypt13$weightcats),1)

###############################################IRAQ13############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Iraq13 <- ABWVS20132018[ABWVS20132018$country == "Iraq" & ABWVS20132018$year == 2013, ]
table(Iraq13$country)
table(Iraq13$year)

#gender.
prop.table(table(Iraq13$gender, Iraq13$Surveytype),2)
chisq.test(table(Iraq13$gender, Iraq13$Surveytype))

#age.
aggregate(Iraq13 $age_short ~ Surveytype, Iraq13, min)
aggregate(Iraq13 $age_short ~ Surveytype, Iraq13, max)
aggregate(Iraq13$age_short ~ Surveytype, Iraq13, mean)
aggregate(Iraq13$age_short ~ Surveytype, Iraq13, sd)
t.test(Iraq13$age_short ~ Iraq13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Iraq13$Educ ~ Surveytype, Iraq13, min)
aggregate(Iraq13$Educ ~ Surveytype, Iraq13, max)
aggregate(Iraq13$Educ ~ Surveytype, Iraq13, mean)
aggregate(Iraq13$Educ ~ Surveytype, Iraq13, sd)
t.test(Iraq13$Educ ~ Iraq13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Iraq13$Mar, Iraq13$Surveytype),2)
chisq.test(table(Iraq13$Mar, Iraq13$Surveytype))

#employment status.
prop.table(table(Iraq13$Empl, Iraq13$Surveytype),2)
chisq.test(table(Iraq13$Empl, Iraq13$Surveytype))

#weights
table(Iraq13$Surveytype)
prop.table(table(Iraq13$Surveytype, Iraq13$weightcats),1)

###############################################JORDAN13############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Jordan13 <- ABWVS20132018[ABWVS20132018$country == "Jordan" & ABWVS20132018$year == 2013, ]
table(Jordan13$country)
table(Jordan13$year)

#gender.
prop.table(table(Jordan13$gender, Jordan13$Surveytype),2)
chisq.test(table(Jordan13$gender, Jordan13$Surveytype))

#age.
aggregate(Jordan13 $age_short ~ Surveytype, Jordan13, min)
aggregate(Jordan13 $age_short ~ Surveytype, Jordan13, max)
aggregate(Jordan13$age_short ~ Surveytype, Jordan13, mean)
aggregate(Jordan13$age_short ~ Surveytype, Jordan13, sd)
t.test(Jordan13$age_short ~ Jordan13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Jordan13$Educ ~ Surveytype, Jordan13, min)
aggregate(Jordan13$Educ ~ Surveytype, Jordan13, max)
aggregate(Jordan13$Educ ~ Surveytype, Jordan13, mean)
aggregate(Jordan13$Educ ~ Surveytype, Jordan13, sd)
t.test(Jordan13$Educ ~ Jordan13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Jordan13$Mar, Jordan13$Surveytype),2)
chisq.test(table(Jordan13$Mar, Jordan13$Surveytype))

#employment status.
prop.table(table(Jordan13$Empl, Jordan13$Surveytype),2)
chisq.test(table(Jordan13$Empl, Jordan13$Surveytype))

#weights
table(Jordan13$Surveytype)
prop.table(table(Jordan13$Surveytype, Jordan13$weightcats),1)

###############################################KUWAIT############################################################

table(ABWVS20132018$country)
Kuwait <- ABWVS20132018[ABWVS20132018$country == "Kuwait", ]
table(Kuwait$country)
table(Kuwait$year)

#gender.
prop.table(table(Kuwait$gender, Kuwait$Surveytype),2)
chisq.test(table(Kuwait$gender, Kuwait$Surveytype))

#age.
aggregate(Kuwait $age_short ~ Surveytype, Kuwait, min)
aggregate(Kuwait $age_short ~ Surveytype, Kuwait, max)
aggregate(Kuwait$age_short ~ Surveytype, Kuwait, mean)
aggregate(Kuwait$age_short ~ Surveytype, Kuwait, sd)
t.test(Kuwait$age_short ~ Kuwait$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Kuwait$Educ ~ Surveytype, Kuwait, min)
aggregate(Kuwait$Educ ~ Surveytype, Kuwait, max)
aggregate(Kuwait$Educ ~ Surveytype, Kuwait, mean)
aggregate(Kuwait$Educ ~ Surveytype, Kuwait, sd)
t.test(Kuwait$Educ ~ Kuwait$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Kuwait$Mar, Kuwait$Surveytype),2)
chisq.test(table(Kuwait$Mar, Kuwait$Surveytype))

#employment status.
prop.table(table(Kuwait$Empl, Kuwait$Surveytype),2)
chisq.test(table(Kuwait$Empl, Kuwait$Surveytype))

#weights
table(Kuwait$Surveytype)
prop.table(table(Kuwait$Surveytype, Kuwait$weightcats),1)

###############################################LEBANON13############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Lebanon13 <- ABWVS20132018[ABWVS20132018$country == "Lebanon" & ABWVS20132018$year == 2013, ]
table(Lebanon13$country)
table(Lebanon13$year)

#gender.
prop.table(table(Lebanon13$gender, Lebanon13$Surveytype),2)
chisq.test(table(Lebanon13$gender, Lebanon13$Surveytype))

#age.
aggregate(Lebanon13 $age_short ~ Surveytype, Lebanon13, min)
aggregate(Lebanon13 $age_short ~ Surveytype, Lebanon13, max)
aggregate(Lebanon13$age_short ~ Surveytype, Lebanon13, mean)
aggregate(Lebanon13$age_short ~ Surveytype, Lebanon13, sd)
t.test(Lebanon13$age_short ~ Lebanon13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Lebanon13$Educ ~ Surveytype, Lebanon13, min)
aggregate(Lebanon13$Educ ~ Surveytype, Lebanon13, max)
aggregate(Lebanon13$Educ ~ Surveytype, Lebanon13, mean)
aggregate(Lebanon13$Educ ~ Surveytype, Lebanon13, sd)
t.test(Lebanon13$Educ ~ Lebanon13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Lebanon13$Mar, Lebanon13$Surveytype),2)
chisq.test(table(Lebanon13$Mar, Lebanon13$Surveytype))

#employment status.
prop.table(table(Lebanon13$Empl, Lebanon13$Surveytype),2)
chisq.test(table(Lebanon13$Empl, Lebanon13$Surveytype))

#weights
table(Lebanon13$Surveytype)
prop.table(table(Lebanon13$Surveytype, Lebanon13$weightcats),1)


###############################################LIBYA############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Libya <- ABWVS20132018[ABWVS20132018$country == "Libya", ]
table(Libya$country)
table(Libya$year)

#gender.
prop.table(table(Libya$gender, Libya$Surveytype),2)
chisq.test(table(Libya$gender, Libya$Surveytype))

#age.
aggregate(Libya $age_short ~ Surveytype, Libya, min)
aggregate(Libya $age_short ~ Surveytype, Libya, max)
aggregate(Libya$age_short ~ Surveytype, Libya, mean)
aggregate(Libya$age_short ~ Surveytype, Libya, sd)
t.test(Libya$age_short ~ Libya$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Libya$Educ ~ Surveytype, Libya, min)
aggregate(Libya$Educ ~ Surveytype, Libya, max)
aggregate(Libya$Educ ~ Surveytype, Libya, mean)
aggregate(Libya$Educ ~ Surveytype, Libya, sd)
t.test(Libya$Educ ~ Libya$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Libya$Mar, Libya$Surveytype),2)
chisq.test(table(Libya$Mar, Libya$Surveytype))

#employment status.
prop.table(table(Libya$Empl, Libya$Surveytype),2)
chisq.test(table(Libya$Empl, Libya$Surveytype))

#weights
table(Libya$Surveytype)
prop.table(table(Libya$Surveytype, Libya$weightcats),1)

###############################################MOROCCO############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Morocco <- ABWVS20132018[ABWVS20132018$country == "Morocco", ]
table(Morocco$country)
table(Morocco$year)

#gender.
prop.table(table(Morocco$gender, Morocco$Surveytype),2)
chisq.test(table(Morocco$gender, Morocco$Surveytype))

#age.
aggregate(Morocco $age_short ~ Surveytype, Morocco, min)
aggregate(Morocco $age_short ~ Surveytype, Morocco, max)
aggregate(Morocco$age_short ~ Surveytype, Morocco, mean)
aggregate(Morocco$age_short ~ Surveytype, Morocco, sd)
t.test(Morocco$age_short ~ Morocco$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Morocco$Educ ~ Surveytype, Morocco, min)
aggregate(Morocco$Educ ~ Surveytype, Morocco, max)
aggregate(Morocco$Educ ~ Surveytype, Morocco, mean)
aggregate(Morocco$Educ ~ Surveytype, Morocco, sd)
t.test(Morocco$Educ ~ Morocco$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Morocco$Mar, Morocco$Surveytype),2)
chisq.test(table(Morocco$Mar, Morocco$Surveytype))

#employment status.
prop.table(table(Morocco$Empl, Morocco$Surveytype),2)
chisq.test(table(Morocco$Empl, Morocco$Surveytype))

#weights
table(Morocco$Surveytype)
prop.table(table(Morocco$Surveytype, Morocco$weightcats),1)

###############################################PALESTINE############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Palestine <- ABWVS20132018[ABWVS20132018$country == "Palestine", ]
table(Palestine$country)
table(Palestine$year)

#gender.
prop.table(table(Palestine$gender, Palestine$Surveytype),2)
chisq.test(table(Palestine$gender, Palestine$Surveytype))

#age.
aggregate(Palestine $age_short ~ Surveytype, Palestine, min)
aggregate(Palestine $age_short ~ Surveytype, Palestine, max)
aggregate(Palestine$age_short ~ Surveytype, Palestine, mean)
aggregate(Palestine$age_short ~ Surveytype, Palestine, sd)
t.test(Palestine$age_short ~ Palestine$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Palestine$Educ ~ Surveytype, Palestine, min)
aggregate(Palestine$Educ ~ Surveytype, Palestine, max)
aggregate(Palestine$Educ ~ Surveytype, Palestine, mean)
aggregate(Palestine$Educ ~ Surveytype, Palestine, sd)
t.test(Palestine$Educ ~ Palestine$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Palestine$Mar, Palestine$Surveytype),2)
chisq.test(table(Palestine$Mar, Palestine$Surveytype))

#employment status.
prop.table(table(Palestine$Empl, Palestine$Surveytype),2)
chisq.test(table(Palestine$Empl, Palestine$Surveytype))

#weights
table(Palestine$Surveytype)
prop.table(table(Palestine$Surveytype, Palestine$weightcats),1)


###############################################TUNISIA13############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Tunisia13 <- ABWVS20132018[ABWVS20132018$country == "Tunisia" & ABWVS20132018$year == 2013, ]
table(Tunisia13$country)
table(Tunisia13$year)

#gender.
prop.table(table(Tunisia13$gender, Tunisia13$Surveytype),2)
chisq.test(table(Tunisia13$gender, Tunisia13$Surveytype))

#age.
aggregate(Tunisia13 $age_short ~ Surveytype, Tunisia13, min)
aggregate(Tunisia13 $age_short ~ Surveytype, Tunisia13, max)
aggregate(Tunisia13$age_short ~ Surveytype, Tunisia13, mean)
aggregate(Tunisia13$age_short ~ Surveytype, Tunisia13, sd)
t.test(Tunisia13$age_short ~ Tunisia13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Tunisia13$Educ ~ Surveytype, Tunisia13, min)
aggregate(Tunisia13$Educ ~ Surveytype, Tunisia13, max)
aggregate(Tunisia13$Educ ~ Surveytype, Tunisia13, mean)
aggregate(Tunisia13$Educ ~ Surveytype, Tunisia13, sd)
t.test(Tunisia13$Educ ~ Tunisia13$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Tunisia13$Mar, Tunisia13$Surveytype),2)
chisq.test(table(Tunisia13$Mar, Tunisia13$Surveytype))

#employment status.
prop.table(table(Tunisia13$Empl, Tunisia13$Surveytype),2)
chisq.test(table(Tunisia13$Empl, Tunisia13$Surveytype))

#weights
table(Tunisia13$Surveytype)
prop.table(table(Tunisia13$Surveytype, Tunisia13$weightcats),1)

###############################################YEMEN############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Yemen <- ABWVS20132018[ABWVS20132018$country == "Yemen", ]
table(Yemen$country)
table(Yemen$year)

#gender.
prop.table(table(Yemen$gender, Yemen$Surveytype),2)
chisq.test(table(Yemen$gender, Yemen$Surveytype))

#age.
aggregate(Yemen $age_short ~ Surveytype, Yemen, min)
aggregate(Yemen $age_short ~ Surveytype, Yemen, max)
aggregate(Yemen$age_short ~ Surveytype, Yemen, mean)
aggregate(Yemen$age_short ~ Surveytype, Yemen, sd)
t.test(Yemen$age_short ~ Yemen$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Yemen$Educ ~ Surveytype, Yemen, min)
aggregate(Yemen$Educ ~ Surveytype, Yemen, max)
aggregate(Yemen$Educ ~ Surveytype, Yemen, mean)
aggregate(Yemen$Educ ~ Surveytype, Yemen, sd)
t.test(Yemen$Educ ~ Yemen$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Yemen$Mar, Yemen$Surveytype),2)
chisq.test(table(Yemen$Mar, Yemen$Surveytype))

#employment status.
prop.table(table(Yemen$Empl, Yemen$Surveytype),2)
chisq.test(table(Yemen$Empl, Yemen$Surveytype))

#weights
table(Yemen$Surveytype)
prop.table(table(Yemen$Surveytype, Yemen$weightcats),1)


###############################################EGYPT18############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Egypt18 <- ABWVS20132018[ABWVS20132018$country == "Egypt" & ABWVS20132018$year == 2018, ]
table(Egypt18$country)
table(Egypt18$year)

#gender.
prop.table(table(Egypt18$gender, Egypt18$Surveytype),2)
chisq.test(table(Egypt18$gender, Egypt18$Surveytype))

#age.
aggregate(Egypt18 $age_short ~ Surveytype, Egypt18, min)
aggregate(Egypt18 $age_short ~ Surveytype, Egypt18, max)
aggregate(Egypt18$age_short ~ Surveytype, Egypt18, mean)
aggregate(Egypt18$age_short ~ Surveytype, Egypt18, sd)
t.test(Egypt18$age_short ~ Egypt18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Egypt18$Educ ~ Surveytype, Egypt18, min)
aggregate(Egypt18$Educ ~ Surveytype, Egypt18, max)
aggregate(Egypt18$Educ ~ Surveytype, Egypt18, mean)
aggregate(Egypt18$Educ ~ Surveytype, Egypt18, sd)
t.test(Egypt18$Educ ~ Egypt18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Egypt18$Mar, Egypt18$Surveytype),2)
chisq.test(table(Egypt18$Mar, Egypt18$Surveytype))

#employment status.
prop.table(table(Egypt18$Empl, Egypt18$Surveytype),2)
chisq.test(table(Egypt18$Empl, Egypt18$Surveytype))

#weights
table(Egypt18$Surveytype)
prop.table(table(Egypt18$Surveytype, Egypt18$weightcats),1)

###############################################IRAQ18############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Iraq18 <- ABWVS20132018[ABWVS20132018$country == "Iraq" & ABWVS20132018$year == 2018, ]
table(Iraq18$country)
table(Iraq18$year)

#gender.
prop.table(table(Iraq18$gender, Iraq18$Surveytype),2)
chisq.test(table(Iraq18$gender, Iraq18$Surveytype))

#age.
aggregate(Iraq18 $age_short ~ Surveytype, Iraq18, min)
aggregate(Iraq18 $age_short ~ Surveytype, Iraq18, max)
aggregate(Iraq18$age_short ~ Surveytype, Iraq18, mean)
aggregate(Iraq18$age_short ~ Surveytype, Iraq18, sd)
t.test(Iraq18$age_short ~ Iraq18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Iraq18$Educ ~ Surveytype, Iraq18, min)
aggregate(Iraq18$Educ ~ Surveytype, Iraq18, max)
aggregate(Iraq18$Educ ~ Surveytype, Iraq18, mean)
aggregate(Iraq18$Educ ~ Surveytype, Iraq18, sd)
t.test(Iraq18$Educ ~ Iraq18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Iraq18$Mar, Iraq18$Surveytype),2)
chisq.test(table(Iraq18$Mar, Iraq18$Surveytype))

#employment status.
prop.table(table(Iraq18$Empl, Iraq18$Surveytype),2)
chisq.test(table(Iraq18$Empl, Iraq18$Surveytype))

#weights
table(Iraq18$Surveytype)
prop.table(table(Iraq18$Surveytype, Iraq18$weightcats),1)


###############################################JORDAN18############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Jordan18 <- ABWVS20132018[ABWVS20132018$country == "Jordan" & ABWVS20132018$year == 2018, ]
table(Jordan18$country)
table(Jordan18$year)

#gender.
prop.table(table(Jordan18$gender, Jordan18$Surveytype),2)
chisq.test(table(Jordan18$gender, Jordan18$Surveytype))

#age.
aggregate(Jordan18 $age_short ~ Surveytype, Jordan18, min)
aggregate(Jordan18 $age_short ~ Surveytype, Jordan18, max)
aggregate(Jordan18$age_short ~ Surveytype, Jordan18, mean)
aggregate(Jordan18$age_short ~ Surveytype, Jordan18, sd)
t.test(Jordan18$age_short ~ Jordan18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Jordan18$Educ ~ Surveytype, Jordan18, min)
aggregate(Jordan18$Educ ~ Surveytype, Jordan18, max)
aggregate(Jordan18$Educ ~ Surveytype, Jordan18, mean)
aggregate(Jordan18$Educ ~ Surveytype, Jordan18, sd)
t.test(Jordan18$Educ ~ Jordan18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Jordan18$Mar, Jordan18$Surveytype),2)
chisq.test(table(Jordan18$Mar, Jordan18$Surveytype))

#employment status.
prop.table(table(Jordan18$Empl, Jordan18$Surveytype),2)
chisq.test(table(Jordan18$Empl, Jordan18$Surveytype))

#weights
table(Jordan18$Surveytype)
prop.table(table(Jordan18$Surveytype, Jordan18$weightcats),1)

###############################################LEBANON18############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Lebanon18 <- ABWVS20132018[ABWVS20132018$country == "Lebanon" & ABWVS20132018$year == 2018, ]
table(Lebanon18$country)
table(Lebanon18$year)

#gender.
prop.table(table(Lebanon18$gender, Lebanon18$Surveytype),2)
chisq.test(table(Lebanon18$gender, Lebanon18$Surveytype))

#age.
aggregate(Lebanon18 $age_short ~ Surveytype, Lebanon18, min)
aggregate(Lebanon18 $age_short ~ Surveytype, Lebanon18, max)
aggregate(Lebanon18$age_short ~ Surveytype, Lebanon18, mean)
aggregate(Lebanon18$age_short ~ Surveytype, Lebanon18, sd)
t.test(Lebanon18$age_short ~ Lebanon18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Lebanon18$Educ ~ Surveytype, Lebanon18, min)
aggregate(Lebanon18$Educ ~ Surveytype, Lebanon18, max)
aggregate(Lebanon18$Educ ~ Surveytype, Lebanon18, mean)
aggregate(Lebanon18$Educ ~ Surveytype, Lebanon18, sd)
t.test(Lebanon18$Educ ~ Lebanon18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Lebanon18$Mar, Lebanon18$Surveytype),2)
chisq.test(table(Lebanon18$Mar, Lebanon18$Surveytype))

#employment status.
prop.table(table(Lebanon18$Empl, Lebanon18$Surveytype),2)
chisq.test(table(Lebanon18$Empl, Lebanon18$Surveytype))

#weights
table(Lebanon18$Surveytype)
prop.table(table(Lebanon18$Surveytype, Lebanon18$weightcats),1)

###############################################TUNISIA18############################################################

table(ABWVS20132018$country)
table(ABWVS20132018$year)
Tunisia18 <- ABWVS20132018[ABWVS20132018$country == "Tunisia" & ABWVS20132018$year == 2018, ]
table(Tunisia18$country)
table(Tunisia18$year)

#gender.
prop.table(table(Tunisia18$gender, Tunisia18$Surveytype),2)
chisq.test(table(Tunisia18$gender, Tunisia18$Surveytype))

#age.
aggregate(Tunisia18 $age_short ~ Surveytype, Tunisia18, min)
aggregate(Tunisia18 $age_short ~ Surveytype, Tunisia18, max)
aggregate(Tunisia18$age_short ~ Surveytype, Tunisia18, mean)
aggregate(Tunisia18$age_short ~ Surveytype, Tunisia18, sd)
t.test(Tunisia18$age_short ~ Tunisia18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#education.
aggregate(Tunisia18$Educ ~ Surveytype, Tunisia18, min)
aggregate(Tunisia18$Educ ~ Surveytype, Tunisia18, max)
aggregate(Tunisia18$Educ ~ Surveytype, Tunisia18, mean)
aggregate(Tunisia18$Educ ~ Surveytype, Tunisia18, sd)
t.test(Tunisia18$Educ ~ Tunisia18$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

#marital status.
prop.table(table(Tunisia18$Mar, Tunisia18$Surveytype),2)
chisq.test(table(Tunisia18$Mar, Tunisia18$Surveytype))

#employment status.
prop.table(table(Tunisia18$Empl, Tunisia18$Surveytype),2)
chisq.test(table(Tunisia18$Empl, Tunisia18$Surveytype))

#weights
table(Tunisia18$Surveytype)
prop.table(table(Tunisia18$Surveytype, Tunisia18$weightcats),1)







##################################################################################################################
##################################################################################################################
#########################################ANALYSIS 1: OVERALL DESCRIPTIVES#########################################
##################################################################################################################
##################################################################################################################

summary(ABWVS20132018$Surveytype)
aggregate(ABWVS20132018$Trust ~ Surveytype, ABWVS20132018, mean)
chisq.test(table(ABWVS20132018$Trust,ABWVS20132018$Surveytype))
t.test(ABWVS20132018$Unieduc ~ ABWVS20132018$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(ABWVS20132018$PolLead ~ ABWVS20132018$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(ABWVS20132018$Trustpol ~ ABWVS20132018$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(ABWVS20132018$Trust, ABWVS20132018$Surveytype), 2)
prop.table (table(ABWVS20132018$Unieduc, ABWVS20132018$Surveytype), 2)
prop.table (table(ABWVS20132018$PolLead, ABWVS20132018$Surveytype), 2)
prop.table (table(ABWVS20132018$Trustpol, ABWVS20132018$Surveytype), 2)

aggregate(ABWVS20132018$Trust ~ Surveytype, ABWVS20132018, length)
aggregate(ABWVS20132018$Unieduc ~ Surveytype, ABWVS20132018, length)
aggregate(ABWVS20132018$PolLead ~ Surveytype, ABWVS20132018, length)
aggregate(ABWVS20132018$Trustpol ~ Surveytype, ABWVS20132018, length)





################################################
####################MEN#########################
################################################

table(ABWVS20132018$gender)
Men <- ABWVS20132018[ABWVS20132018$gender == 0, ]
table(Men$gender)
table(ABWVS20132018$gender)

summary(Men$Surveytype)
aggregate(Men$Trust ~ Surveytype, Men, mean)
chisq.test(table(Men$Trust,Men$Surveytype))
t.test(Men$Unieduc ~ Men$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Men$PolLead ~ Men$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Men$Trustpol ~ Men$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Men$Trust, Men$Surveytype), 2)
prop.table (table(Men$Unieduc, Men$Surveytype), 2)
prop.table (table(Men$PolLead, Men$Surveytype), 2)
prop.table (table(Men$Trustpol, Men$Surveytype), 2)

aggregate(Men$Trust ~ Surveytype, Men, length)
aggregate(Men$Unieduc ~ Surveytype, Men, length)
aggregate(Men$PolLead ~ Surveytype, Men, length)
aggregate(Men$Trustpol ~ Surveytype, Men, length)



################################################
####################WOMEN#######################
################################################

table(ABWVS20132018$gender)
Women <- ABWVS20132018[ABWVS20132018$gender == 1, ]
table(Women$gender)
table(ABWVS20132018$gender)

summary(Women$Surveytype)
aggregate(Women$Trust ~ Surveytype, Women, mean)
chisq.test(table(Women$Trust,Women$Surveytype))
t.test(Women$Unieduc ~ Women$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Women$PolLead ~ Women$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Women$Trustpol ~ Women$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Women$Trust, Women$Surveytype), 2)
prop.table (table(Women$Unieduc, Women$Surveytype), 2)
prop.table (table(Women$PolLead, Women$Surveytype), 2)
prop.table (table(Women$Trustpol, Women$Surveytype), 2)

aggregate(Women$Trust ~ Surveytype, Women, length)
aggregate(Women$Unieduc ~ Surveytype, Women, length)
aggregate(Women$PolLead ~ Surveytype, Women, length)
aggregate(Women$Trustpol ~ Surveytype, Women, length)



################################################
####################UNDER30#####################
################################################

table(ABWVS20132018$age_short)

ABWVS20132018$agecats[ABWVS20132018$age_short < 30] <- 0
ABWVS20132018$agecats[ABWVS20132018$age_short > 29 & ABWVS20132018$age_short < 50] <-1
ABWVS20132018$agecats[ABWVS20132018$age_short > 49] <- 2
table(ABWVS20132018$agecats)
table(ABWVS20132018$age_short, ABWVS20132018$agecats)

table(ABWVS20132018$agecats)
Under30 <- ABWVS20132018[ABWVS20132018$agecats == 0, ]
table(Under30$age_short)
table(ABWVS20132018$age_short)

summary(Under30$Surveytype)
aggregate(Under30$Trust ~ Surveytype, Under30, mean)
chisq.test(table(Under30$Trust,Under30$Surveytype))
t.test(Under30$Unieduc ~ Under30$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Under30$PolLead ~ Under30$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Under30$Trustpol ~ Under30$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Under30$Trust, Under30$Surveytype), 2)
prop.table (table(Under30$Unieduc, Under30$Surveytype), 2)
prop.table (table(Under30$PolLead, Under30$Surveytype), 2)
prop.table (table(Under30$Trustpol, Under30$Surveytype), 2)

aggregate(Under30$Trust ~ Surveytype, Under30, length)
aggregate(Under30$Unieduc ~ Surveytype, Under30, length)
aggregate(Under30$PolLead ~ Surveytype, Under30, length)
aggregate(Under30$Trustpol ~ Surveytype, Under30, length)





################################################
#################From30to49#####################
################################################

table(ABWVS20132018$agecats)
From30to49 <- ABWVS20132018[ABWVS20132018$agecats == 1, ]
table(From30to49$age_short)
table(ABWVS20132018$age_short)

summary(From30to49$Surveytype)
aggregate(From30to49$Trust ~ Surveytype, From30to49, mean)
chisq.test(table(From30to49$Trust,From30to49$Surveytype))
t.test(From30to49$Unieduc ~ From30to49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(From30to49$PolLead ~ From30to49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(From30to49$Trustpol ~ From30to49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(From30to49$Trust, From30to49$Surveytype), 2)
prop.table (table(From30to49$Unieduc, From30to49$Surveytype), 2)
prop.table (table(From30to49$PolLead, From30to49$Surveytype), 2)
prop.table (table(From30to49$Trustpol, From30to49$Surveytype), 2)

aggregate(From30to49$Trust ~ Surveytype, From30to49, length)
aggregate(From30to49$Unieduc ~ Surveytype, From30to49, length)
aggregate(From30to49$PolLead ~ Surveytype, From30to49, length)
aggregate(From30to49$Trustpol ~ Surveytype, From30to49, length)



################################################
#################Over49#########################
################################################

table(ABWVS20132018$agecats)
Over49 <- ABWVS20132018[ABWVS20132018$agecats == 2, ]
table(Over49$age_short)
table(ABWVS20132018$age_short)

summary(Over49$Surveytype)
aggregate(Over49$Trust ~ Surveytype, Over49, mean)
chisq.test(table(Over49$Trust,Over49$Surveytype))
t.test(Over49$Unieduc ~ Over49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Over49$PolLead ~ Over49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Over49$Trustpol ~ Over49$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Over49$Trust, Over49$Surveytype), 2)
prop.table (table(Over49$Unieduc, Over49$Surveytype), 2)
prop.table (table(Over49$PolLead, Over49$Surveytype), 2)
prop.table (table(Over49$Trustpol, Over49$Surveytype), 2)

aggregate(Over49$Trust ~ Surveytype, Over49, length)
aggregate(Over49$Unieduc ~ Surveytype, Over49, length)
aggregate(Over49$PolLead ~ Surveytype, Over49, length)
aggregate(Over49$Trustpol ~ Surveytype, Over49, length)



################################################
#################LowerEducated##################
################################################
table(ABWVS20132018$Educ)
# 0 - No, 1 - Primary, 2 - Secondary, 3 - Tertiary

ABWVS20132018$Educcats[ABWVS20132018$Educ < 3] <- 0
ABWVS20132018$Educcats[ABWVS20132018$Educ == 3] <- 1
table(ABWVS20132018$Educcats)

LowerEducated <- ABWVS20132018[ABWVS20132018$Educcats == 0, ]
table(LowerEducated$Educ)
table(ABWVS20132018$Educ)

summary(LowerEducated$Surveytype)
aggregate(LowerEducated$Trust ~ Surveytype, LowerEducated, mean)
chisq.test(table(LowerEducated$Trust,LowerEducated$Surveytype))
t.test(LowerEducated$Unieduc ~ LowerEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(LowerEducated$PolLead ~ LowerEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(LowerEducated$Trustpol ~ LowerEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(LowerEducated$Trust, LowerEducated$Surveytype), 2)
prop.table (table(LowerEducated$Unieduc, LowerEducated$Surveytype), 2)
prop.table (table(LowerEducated$PolLead, LowerEducated$Surveytype), 2)
prop.table (table(LowerEducated$Trustpol, LowerEducated$Surveytype), 2)

aggregate(LowerEducated$Trust ~ Surveytype, LowerEducated, length)
aggregate(LowerEducated$Unieduc ~ Surveytype, LowerEducated, length)
aggregate(LowerEducated$PolLead ~ Surveytype, LowerEducated, length)
aggregate(LowerEducated$Trustpol ~ Surveytype, LowerEducated, length)



################################################
#################HigherEducated#################
################################################

table(ABWVS20132018$Educcats)
HigherEducated <- ABWVS20132018[ABWVS20132018$Educcats == 1, ]
table(HigherEducated$Educ)
table(ABWVS20132018$Educ)

summary(HigherEducated$Surveytype)
aggregate(HigherEducated$Trust ~ Surveytype, HigherEducated, mean)
chisq.test(table(HigherEducated$Trust,HigherEducated$Surveytype))
t.test(HigherEducated$Unieduc ~ HigherEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(HigherEducated$PolLead ~ HigherEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(HigherEducated$Trustpol ~ HigherEducated$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(HigherEducated$Trust, HigherEducated$Surveytype), 2)
prop.table (table(HigherEducated$Unieduc, HigherEducated$Surveytype), 2)
prop.table (table(HigherEducated$PolLead, HigherEducated$Surveytype), 2)
prop.table (table(HigherEducated$Trustpol, HigherEducated$Surveytype), 2)

aggregate(HigherEducated$Trust ~ Surveytype, HigherEducated, length)
aggregate(HigherEducated$Unieduc ~ Surveytype, HigherEducated, length)
aggregate(HigherEducated$PolLead ~ Surveytype, HigherEducated, length)
aggregate(HigherEducated$Trustpol ~ Surveytype, HigherEducated, length)



################################################
#################HigherEducated NO 2############
################################################

ABWVS20132018$Educcats2[ABWVS20132018$Educ < 2] <- 0
ABWVS20132018$Educcats2[ABWVS20132018$Educ > 1] <- 1
table(ABWVS20132018$Educcats2)
HigherEducated2 <- ABWVS20132018[ABWVS20132018$Educcats2 == 1, ]
table(HigherEducated2$Educ)
table(ABWVS20132018$Educ)

summary(HigherEducated2$Surveytype)
aggregate(HigherEducated2$Trust ~ Surveytype, HigherEducated2, mean)
chisq.test(table(HigherEducated2$Trust,HigherEducated2$Surveytype))
t.test(HigherEducated2$Unieduc ~ HigherEducated2$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(HigherEducated2$PolLead ~ HigherEducated2$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(HigherEducated2$Trustpol ~ HigherEducated2$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(HigherEducated2$Trust, HigherEducated2$Surveytype), 2)
prop.table (table(HigherEducated2$Unieduc, HigherEducated2$Surveytype), 2)
prop.table (table(HigherEducated2$PolLead, HigherEducated2$Surveytype), 2)
prop.table (table(HigherEducated2$Trustpol, HigherEducated2$Surveytype), 2)

aggregate(HigherEducated2$Trust ~ Surveytype, HigherEducated2, length)
aggregate(HigherEducated2$Unieduc ~ Surveytype, HigherEducated2, length)
aggregate(HigherEducated2$PolLead ~ Surveytype, HigherEducated2, length)
aggregate(HigherEducated2$Trustpol ~ Surveytype, HigherEducated2, length)











##################################################################################################################
##################################################################################################################
#########################################PERCENT MATCH ANALYSES 2013##############################################
##################################################################################################################
##################################################################################################################

################################################
#################ID#############################
################################################

dmAB3$Survey <- rep("AB", 13583)
table(dmAB3$Survey)
dmWV6$Survey <- rep("WVS", 14087)
table(dmWV6$Survey)

dmAB3$id <- c(1:13583)
summary(dmAB3$id)
length(dmWV6$Survey)
dmWV6$id <- c(13584:27670)
summary(dmWV6$id)


# Merging AB and WVS, all variables, full datasets---------------------------------------------------

table(dmWV6$id)

ABWVS <- merge(dmAB3, dmWV6, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                   "age_short",
                                   "gender", "country", 
                                   "Trust", "Unieduc", "PolLead", "Trustpol", "id"), all=TRUE)

names(ABWVS)

summary(ABWVS$id)
table(ABWVS$Empl)
table(ABWVS$survey)
table(ABWVS$country)
summary(ABWVS$Surveytype)
ABWVS$Surveytype <- as.factor (ABWVS$Surveytype)
summary(ABWVS$Surveytype)
table(ABWVS$Surveytype)


ABWVS$Surveytype2[ABWVS$Surveytype == 1] <- 0
ABWVS$Surveytype2[ABWVS$Surveytype == 0] <- 1
table(ABWVS$Surveytype2)
#Surveytype has 0 WVS, 1 AB // Surveytype2 has 0 AB, 1 WVS

# Merging AB and WVS, only needed variables, small datasets --------------------------------------------------

names(dmAB3)
AB_short <-
  dmAB3 %>% select(Surveytype, Survey, Empl, Mar, Educ, age_short, gender, country, 
                   Trust, Unieduc, PolLead, Trustpol, id)

names(AB_short)
summary(AB_short)

names(dmWV6)
WVS_short <-
  dmWV6 %>% select(Surveytype, Survey, Empl, Mar, Educ, age_short, gender, country, 
                   Trust, Unieduc, PolLead, Trustpol, id)

names(WVS_short)
summary(WVS_short)

ABWVS_short <- merge(WVS_short, AB_short, all = TRUE)
summary(ABWVS_short)

summary(ABWVS_short$Surveytype)
table(ABWVS_short$Surveytype)
ABWVS_short$Surveytype <- as.factor(ABWVS_short$Surveytype)
summary(ABWVS_short$Surveytype)
table(ABWVS_short$Surveytype)







getwd()
#setwd("C:/R").
library(tidyverse)
library(Matrix)
library(lme4)
library(foreign)
library(ggplot2)
detach("package:memisc", unload = TRUE)

###################################################
#############ALGERIA: PERCENT MATCH################
############################AB#####################
###################################################
names(ABWVS)
table(ABWVS$surveytype)

table(ABWVS$country)
table(ABWVS$V2)

AlgeriaAB <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Algeria")

AlgeriaABmat <- as.matrix(AlgeriaAB)
percent_match_AlgeriaAB <- c()
for(i in seq(nrow(AlgeriaABmat))){
  vec <- AlgeriaABmat[i,]
  dat <- AlgeriaABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_AlgeriaAB[i] <- max(diff)
}

qplot(percent_match_AlgeriaAB)
summary(percent_match_AlgeriaAB)

AlgeriaAB2 <- as_tibble(AlgeriaABmat)

is.numeric(percent_match_AlgeriaAB)

AlgeriaAB2$matchover85AlgeriaAB <- rep(NA,1218)
AlgeriaAB2$matchover85AlgeriaAB[percent_match_AlgeriaAB <= 0.849] <-0
AlgeriaAB2$matchover85AlgeriaAB[percent_match_AlgeriaAB >= 0.850] <-1


table(AlgeriaAB2$matchover85AlgeriaAB) #8 cases have 1 which makes 0.006557377 
prop.table(table(AlgeriaAB2$matchover85AlgeriaAB))


##########ALGERIA: PERCENT MATCH################
###############WVS#####################
names(ABWVS)

table(ABWVS$surveytype)

table(ABWVS$country)
table(ABWVS$V2)

AlgeriaWVS <- ABWVS %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Algeria")

table(AlgeriaWVS$country)
table(AlgeriaWVS$gender)
table(AlgeriaWVS$Surveytype)
#1199 respondents; 608 male, 591 female.

AlgeriaWVSmat <- as.matrix(AlgeriaWVS)
percent_match_AlgeriaWVS <- c()

for(i in seq(nrow(AlgeriaWVSmat))){
  vec <- AlgeriaWVSmat[i,]
  dat <- AlgeriaWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_AlgeriaWVS[i] <- max(diff)
}

qplot(percent_match_AlgeriaWVS)
summary(percent_match_AlgeriaWVS)
detach("package:memisc", unload = TRUE)
AlgeriaWVS2 <- as_tibble(AlgeriaWVSmat)

AlgeriaWVS2$matchover85AlgeriaWVS <- rep(NA,1199)
AlgeriaWVS2$matchover85AlgeriaWVS[percent_match_AlgeriaWVS <= 0.849] <-0
AlgeriaWVS2$matchover85AlgeriaWVS[percent_match_AlgeriaWVS >= 0.850] <-1


table(AlgeriaWVS2$matchover85AlgeriaWVS)
#SASKIA HAS: 229 cases over 85, 19.2%.
prop.table(table(AlgeriaWVS2$matchover85AlgeriaWVS))


##########ALGERIA: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(AlgeriaWVS2)
AlgeriaWVS2$percentmatch <- as.character(AlgeriaWVS2$matchover85AlgeriaWVS)

table(AlgeriaWVS2$percentmatch)
table(AlgeriaWVS2$gender)

#AB.
names(AlgeriaAB2)
AlgeriaAB2$percentmatch <- as.character(AlgeriaAB2$matchover85AlgeriaAB)

table(AlgeriaAB2$percentmatch)
table(AlgeriaAB2$gender)

AlgeriaABWVS <- merge(AlgeriaWVS2, AlgeriaAB2, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                     "age_short",
                                                     "gender", "country", 
                                                     "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(AlgeriaABWVS$country)
table(AlgeriaABWVS$percentmatch)
table(AlgeriaABWVS$Surveytype)

AlgeriaABWVS$Trust <- as.numeric(AlgeriaABWVS$Trust)
table(AlgeriaABWVS$age_short)
AlgeriaABWVS$age_short <- as.numeric(AlgeriaABWVS$age_short)
table(AlgeriaABWVS$age_short)
table(AlgeriaABWVS$Educ)
AlgeriaABWVS$Educ <- as.numeric(AlgeriaABWVS$Educ)
table(AlgeriaABWVS$Educ)


AlgeriaABWVS$Surveytype2[AlgeriaABWVS$Surveytype == 1] <- 0
AlgeriaABWVS$Surveytype2[AlgeriaABWVS$Surveytype == 0] <- 1
table(AlgeriaABWVS$Surveytype2)



#########################################ALGERIA: PERCENT MATCH################
###############re-running regressions ALL CASES IN ALGERIA TO CHECK#####################

library(lmerTest)
library(lmtest)

mAlgeriaABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1a)

mAlgeriaABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1b)

mAlgeriaABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1c)

mAlgeriaABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1c2)

mAlgeriaABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1d)

mAlgeriaABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1e)

mAlgeriaABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1e2)

mAlgeriaABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1f)

mAlgeriaABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVS, family = binomial)
summary(mAlgeriaABWVS1f2)



table(AlgeriaABWVS$Unieduc)
table(AlgeriaABWVS$country)

mAlgeriaABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2a)
mAlgeriaABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2b)

mAlgeriaABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2c)

mAlgeriaABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2d)

mAlgeriaABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2e)

mAlgeriaABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2f)

mAlgeriaABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS2f2)


table(AlgeriaABWVS$PolLead)
table(AlgeriaABWVS$country)

mAlgeriaABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3a)
mAlgeriaABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3b)

mAlgeriaABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3c)

mAlgeriaABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3d)

mAlgeriaABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3e)

mAlgeriaABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS3f)


table(AlgeriaABWVS$Trustpol)
table(AlgeriaABWVS$country)

mAlgeriaABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4a)
mAlgeriaABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4b)

mAlgeriaABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4c)

mAlgeriaABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4d)

mAlgeriaABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4d2)

mAlgeriaABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4e)

mAlgeriaABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4f)

mAlgeriaABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVS)
summary(mAlgeriaABWVS4f2)




#########################################ALGERIA: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(AlgeriaABWVS$country)
table(AlgeriaABWVS$percentmatch)
AlgeriaABWVSwofraude <- subset(AlgeriaABWVS, percentmatch!= "1")
table(AlgeriaABWVSwofraude$percentmatch)
table(AlgeriaABWVSwofraude$country)

table(AlgeriaABWVS$Surveytype)


mAlgeriaABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1a)

mAlgeriaABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1b)

mAlgeriaABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1c)

mAlgeriaABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1c2)

mAlgeriaABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1d)

mAlgeriaABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1e)

mAlgeriaABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1e2)

mAlgeriaABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1f)

mAlgeriaABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude, family = binomial)
summary(mAlgeriaABWVSwofraude1f2)



table(AlgeriaABWVSwofraude$Unieduc)
table(AlgeriaABWVSwofraude$country)

mAlgeriaABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2a)

mAlgeriaABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2b)

mAlgeriaABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2c)

mAlgeriaABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2c2)

mAlgeriaABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2d)

mAlgeriaABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2e)

mAlgeriaABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2f)

mAlgeriaABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude2f2)


table(AlgeriaABWVSwofraude$PolLead)
table(AlgeriaABWVSwofraude$country)

mAlgeriaABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3a)

mAlgeriaABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3b)

mAlgeriaABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3c)

mAlgeriaABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3c2)

mAlgeriaABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3d)

mAlgeriaABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3d2)

mAlgeriaABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3e)

mAlgeriaABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude3f)


table(AlgeriaABWVSwofraude$Trustpol)
table(AlgeriaABWVSwofraude$country)

mAlgeriaABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4a)

mAlgeriaABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4b)

mAlgeriaABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4c)

mAlgeriaABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4d)

mAlgeriaABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4d2)

mAlgeriaABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4e)

mAlgeriaABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4f)

mAlgeriaABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = AlgeriaABWVSwofraude)
summary(mAlgeriaABWVSwofraude4f2)










###################################################
##############EGYPT: PERCENT MATCH#################
###########################AB######################
###################################################
table(dmAB3$country)


Egypt <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Egypt")

EgyptABmat <- as.matrix(Egypt)
percent_match_EgyptAB <- c()
for(i in seq(nrow(EgyptABmat))){
  vec <- EgyptABmat[i,]
  dat <- EgyptABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_EgyptAB[i] <- max(diff)
}

qplot(percent_match_EgyptAB)
summary(percent_match_EgyptAB)

EgyptAB3 <- as_tibble(EgyptABmat)

is.numeric(percent_match_EgyptAB)

EgyptAB3$matchover85EgyptAB <- rep(NA,1196)
EgyptAB3$matchover85EgyptAB[percent_match_EgyptAB <= 0.849] <-0
EgyptAB3$matchover85EgyptAB[percent_match_EgyptAB >= 0.850] <-1


table(EgyptAB3$matchover85EgyptAB) # 210 cases, 17.6%
prop.table(table(EgyptAB3$matchover85EgyptAB))


##########EGYPT: PERCENT MATCH################
###############WVS#####################


EgyptWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Egypt")

EgyptWVSmat <- as.matrix(EgyptWVS)
percent_match_EgyptWVS <- c()

for(i in seq(nrow(EgyptWVSmat))){
  vec <- EgyptWVSmat[i,]
  dat <- EgyptWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_EgyptWVS[i] <- max(diff)
}

qplot(percent_match_EgyptWVS)
summary(percent_match_EgyptWVS)

EgyptWVS2 <- as_tibble(EgyptWVSmat)

EgyptWVS2$matchover85EgyptWVS <- rep(NA,1518)
EgyptWVS2$matchover85EgyptWVS[percent_match_EgyptWVS <= 0.849] <-0
EgyptWVS2$matchover85EgyptWVS[percent_match_EgyptWVS >= 0.850] <-1


table(EgyptWVS2$matchover85EgyptWVS) # 79 cases, 5,2% 
prop.table(table(EgyptWVS2$matchover85EgyptWVS))



##########EGYPT: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(EgyptWVS2)
EgyptWVS2$percentmatch <- as.character(EgyptWVS2$matchover85EgyptWVS)

table(EgyptWVS2$percentmatch)
table(EgyptWVS2$gender)

#AB.
names(EgyptAB3)
EgyptAB3$percentmatch <- as.character(EgyptAB3$matchover85EgyptAB)

table(EgyptAB3$percentmatch)
table(EgyptAB3$gender)

EgyptABWVS <- merge(EgyptWVS2, EgyptAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                               "age_short",
                                               "gender", "country", 
                                               "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(EgyptABWVS$country)
table(EgyptABWVS$percentmatch)
table(EgyptABWVS$Surveytype)

EgyptABWVS$Trust <- as.numeric(EgyptABWVS$Trust)
table(EgyptABWVS$age_short)
EgyptABWVS$age_short <- as.numeric(EgyptABWVS$age_short)
table(EgyptABWVS$age_short)
table(EgyptABWVS$Educ)
EgyptABWVS$Educ <- as.numeric(EgyptABWVS$Educ)
table(EgyptABWVS$Educ)


EgyptABWVS$Surveytype2[EgyptABWVS$Surveytype == 1] <- 0
EgyptABWVS$Surveytype2[EgyptABWVS$Surveytype == 0] <- 1
table(EgyptABWVS$Surveytype2)

#########################################EGYPT: PERCENT MATCH################
###############re-running regressions ALL CASES IN EGYPT TO CHECK#####################

mEgyptABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1a)

mEgyptABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1b)

mEgyptABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1c)

mEgyptABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1c2)

mEgyptABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1d)

mEgyptABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1e)

mEgyptABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1e2)

mEgyptABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1f)

mEgyptABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS, family = binomial)
summary(mEgyptABWVS1f2)



table(EgyptABWVS$Unieduc)
table(EgyptABWVS$country)

mEgyptABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2a)
mEgyptABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2b)

mEgyptABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2c)

mEgyptABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2c2)

mEgyptABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2d)

mEgyptABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2e)

mEgyptABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2f)

mEgyptABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS2f2)


table(EgyptABWVS$PolLead)
table(EgyptABWVS$country)

mEgyptABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3a)
mEgyptABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3b)

mEgyptABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3c)

mEgyptABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3d)

mEgyptABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3e)

mEgyptABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS3f)


table(EgyptABWVS$Trustpol)
table(EgyptABWVS$country)

mEgyptABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4a)
mEgyptABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4b)

mEgyptABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4c)

mEgyptABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4d)

mEgyptABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4d2)

mEgyptABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4e)

mEgyptABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4f)

mEgyptABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVS)
summary(mEgyptABWVS4f2)




#########################################EGYPT: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(EgyptABWVS$country)
table(EgyptABWVS$percentmatch)
EgyptABWVSwofraude <- subset(EgyptABWVS, percentmatch!= "1")
table(EgyptABWVSwofraude$percentmatch)
table(EgyptABWVSwofraude$country)

table(EgyptABWVS$Surveytype)


mEgyptABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1a)

mEgyptABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1b)

mEgyptABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1c)

mEgyptABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1c2)

mEgyptABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1d)

mEgyptABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1e)

mEgyptABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1e2)

mEgyptABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1f)

mEgyptABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1f2)



table(EgyptABWVSwofraude$Unieduc)
table(EgyptABWVSwofraude$country)

mEgyptABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2a)

mEgyptABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2b)

mEgyptABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2c)

mEgyptABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2c2)

mEgyptABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2d)

mEgyptABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2e)

mEgyptABWVSwofraude2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2e2)

mEgyptABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2f)

mEgyptABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2f2)


table(EgyptABWVSwofraude$PolLead)
table(EgyptABWVSwofraude$country)

mEgyptABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3a)

mEgyptABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3b)

mEgyptABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3c)

mEgyptABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3c2)

mEgyptABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3d)

mEgyptABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3d2)

mEgyptABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3e)

mEgyptABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3f)


table(EgyptABWVSwofraude$Trustpol)
table(EgyptABWVSwofraude$country)

mEgyptABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4a)

mEgyptABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4b)

mEgyptABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4c)

mEgyptABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4d)

mEgyptABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4d2)

mEgyptABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4e)

mEgyptABWVSwofraude4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4e2)

mEgyptABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4f)

mEgyptABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude4f2)












###################################################
################IRAQ: PERCENT MATCH################
############################AB#####################
##################################################
table(dmAB3$country)


Iraq <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Iraq")

IraqABmat <- as.matrix(Iraq)
percent_match_IraqAB <- c()
for(i in seq(nrow(IraqABmat))){
  vec <- IraqABmat[i,]
  dat <- IraqABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_IraqAB[i] <- max(diff)
}

qplot(percent_match_IraqAB)
summary(percent_match_IraqAB)

IraqAB3 <- as_tibble(IraqABmat)

is.numeric(percent_match_IraqAB)

IraqAB3$matchover85IraqAB <- rep(NA,1215)
IraqAB3$matchover85IraqAB[percent_match_IraqAB <= 0.849] <-0
IraqAB3$matchover85IraqAB[percent_match_IraqAB >= 0.850] <-1


table(IraqAB3$matchover85IraqAB) # 80 cases, 0.65%
prop.table(table(IraqAB3$matchover85IraqAB))


##########Iraq: PERCENT MATCH################
###############WVS#####################


IraqWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Iraq")

IraqWVSmat <- as.matrix(IraqWVS)
percent_match_IraqWVS <- c()

for(i in seq(nrow(IraqWVSmat))){
  vec <- IraqWVSmat[i,]
  dat <- IraqWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_IraqWVS[i] <- max(diff)
}

qplot(percent_match_IraqWVS)
summary(percent_match_IraqWVS)

IraqWVS2 <- as_tibble(IraqWVSmat)

IraqWVS2$matchover85IraqWVS <- rep(NA,1199)
IraqWVS2$matchover85IraqWVS[percent_match_IraqWVS <= 0.849] <-0
IraqWVS2$matchover85IraqWVS[percent_match_IraqWVS >= 0.850] <-1


table(IraqWVS2$matchover85IraqWVS) # 26 cases, 2 %
prop.table(table(IraqWVS2$matchover85IraqWVS))




##########IRAQ: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(IraqWVS2)
IraqWVS2$percentmatch <- as.character(IraqWVS2$matchover85IraqWVS)

table(IraqWVS2$percentmatch)
table(IraqWVS2$gender)

#AB.
names(IraqAB3)
IraqAB3$percentmatch <- as.character(IraqAB3$matchover85IraqAB)

table(IraqAB3$percentmatch)
table(IraqAB3$gender)

IraqABWVS <- merge(IraqWVS2, IraqAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                            "age_short",
                                            "gender", "country", 
                                            "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(IraqABWVS$country)
table(IraqABWVS$percentmatch)
table(IraqABWVS$Surveytype)

IraqABWVS$Trust <- as.numeric(IraqABWVS$Trust)
table(IraqABWVS$age_short)
IraqABWVS$age_short <- as.numeric(IraqABWVS$age_short)
table(IraqABWVS$age_short)
table(IraqABWVS$Educ)
IraqABWVS$Educ <- as.numeric(IraqABWVS$Educ)
table(IraqABWVS$Educ)


IraqABWVS$Surveytype2[IraqABWVS$Surveytype == 1] <- 0
IraqABWVS$Surveytype2[IraqABWVS$Surveytype == 0] <- 1
table(IraqABWVS$Surveytype2)

#########################################IRAQ: PERCENT MATCH################
###############re-running regressions ALL CASES IN IRAQ TO CHECK#####################

mIraqABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1a)

mIraqABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = IraqABWVS, family = binomial)
summary(mIraqABWVS1b)

mIraqABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = IraqABWVS, family = binomial)
summary(mIraqABWVS1c)

mIraqABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = IraqABWVS, family = binomial)
summary(mIraqABWVS1c2)

mIraqABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1d)

mIraqABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1e)

mIraqABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1e2)

mIraqABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1f)

mIraqABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS, family = binomial)
summary(mIraqABWVS1f2)



table(IraqABWVS$Unieduc)
table(IraqABWVS$country)

mIraqABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2a)
mIraqABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2b)

mIraqABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2c)

mIraqABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2c2)

mIraqABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2d)

mIraqABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2e)

mIraqABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2e2)

mIraqABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2f)

mIraqABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS2f2)


table(IraqABWVS$PolLead)
table(IraqABWVS$country)

mIraqABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3a)
mIraqABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3b)

mIraqABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3c)

mIraqABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3c2)

mIraqABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3d)

mIraqABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3e)

mIraqABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3e2)

mIraqABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS3f)


table(IraqABWVS$Trustpol)
table(IraqABWVS$country)

mIraqABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4a)
mIraqABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4b)

mIraqABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4c)

mIraqABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4d)

mIraqABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4d2)

mIraqABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4e)

mIraqABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4e2)

mIraqABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4f)

mIraqABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVS)
summary(mIraqABWVS4f2)




#########################################IRAQ: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(IraqABWVS$country)
table(IraqABWVS$percentmatch)
IraqABWVSwofraude <- subset(IraqABWVS, percentmatch!= "1")
table(IraqABWVSwofraude$percentmatch)
table(IraqABWVSwofraude$country)

table(IraqABWVS$Surveytype)


mIraqABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1a)

mIraqABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1b)

mIraqABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1c)

mIraqABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1c2)

mIraqABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1d)

mIraqABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1e)

mIraqABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1e2)

mIraqABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1f)

mIraqABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude, family = binomial)
summary(mIraqABWVSwofraude1f2)



table(IraqABWVSwofraude$Unieduc)
table(IraqABWVSwofraude$country)

mIraqABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2a)

mIraqABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2b)

mIraqABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2c)

mIraqABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2c2)

mIraqABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2d)

mIraqABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2e)

mIraqABWVSwofraude2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2e2)

mIraqABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2f)

mIraqABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude2f2)


table(IraqABWVSwofraude$PolLead)
table(IraqABWVSwofraude$country)

mIraqABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3a)

mIraqABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3b)

mIraqABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3c)

mIraqABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3c2)

mIraqABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3d)

mIraqABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3d2)

mIraqABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3e)

mIraqABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude3f)


table(IraqABWVSwofraude$Trustpol)
table(IraqABWVSwofraude$country)

mIraqABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4a)

mIraqABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4b)

mIraqABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4c)

mIraqABWVSwofraude4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4c2)

mIraqABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4d)

mIraqABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4d2)

mIraqABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4e)

mIraqABWVSwofraude4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4e2)

mIraqABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4f)

mIraqABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = IraqABWVSwofraude)
summary(mIraqABWVSwofraude4f2)


###################################################
##########Kuwait: PERCENT MATCH################
######################AB#####################
################################################
table(dmAB3$country)


Kuwait <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Kuwait")

KuwaitABmat <- as.matrix(Kuwait)
percent_match_KuwaitAB <- c()
for(i in seq(nrow(KuwaitABmat))){
  vec <- KuwaitABmat[i,]
  dat <- KuwaitABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_KuwaitAB[i] <- max(diff)
}

qplot(percent_match_KuwaitAB)
summary(percent_match_KuwaitAB)

KuwaitAB3 <- as_tibble(KuwaitABmat)

is.numeric(percent_match_KuwaitAB)

KuwaitAB3$matchover85KuwaitAB <- rep(NA,1019)
KuwaitAB3$matchover85KuwaitAB[percent_match_KuwaitAB <= 0.849] <-0
KuwaitAB3$matchover85KuwaitAB[percent_match_KuwaitAB >= 0.850] <-1


table(KuwaitAB3$matchover85KuwaitAB) # 0%
prop.table(table(KuwaitAB3$matchover85KuwaitAB))


##########Kuwait: PERCENT MATCH################
###############WVS#####################


KuwaitWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Kuwait")

KuwaitWVSmat <- as.matrix(KuwaitWVS)
percent_match_KuwaitWVS <- c()

for(i in seq(nrow(KuwaitWVSmat))){
  vec <- KuwaitWVSmat[i,]
  dat <- KuwaitWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_KuwaitWVS[i] <- max(diff)
}

qplot(percent_match_KuwaitWVS)
summary(percent_match_KuwaitWVS)

KuwaitWVS2 <- as_tibble(KuwaitWVSmat)

KuwaitWVS2$matchover85KuwaitWVS <- rep(NA,1243)
KuwaitWVS2$matchover85KuwaitWVS[percent_match_KuwaitWVS <= 0.849] <-0
KuwaitWVS2$matchover85KuwaitWVS[percent_match_KuwaitWVS >= 0.850] <-1


table(KuwaitWVS2$matchover85KuwaitWVS) #84 cases, 6.7%
prop.table(table(KuwaitWVS2$matchover85KuwaitWVS))




##########KUWAIT: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(KuwaitWVS2)
KuwaitWVS2$percentmatch <- as.character(KuwaitWVS2$matchover85KuwaitWVS)

table(KuwaitWVS2$percentmatch)
table(KuwaitWVS2$gender)

#AB.
names(KuwaitAB3)
KuwaitAB3$percentmatch <- as.character(KuwaitAB3$matchover85KuwaitAB)

table(KuwaitAB3$percentmatch)
table(KuwaitAB3$gender)

KuwaitABWVS <- merge(KuwaitWVS2, KuwaitAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                  "age_short",
                                                  "gender", "country", 
                                                  "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(KuwaitABWVS$country)
table(KuwaitABWVS$percentmatch)
table(KuwaitABWVS$Surveytype)

KuwaitABWVS$Trust <- as.numeric(KuwaitABWVS$Trust)
table(KuwaitABWVS$age_short)
KuwaitABWVS$age_short <- as.numeric(KuwaitABWVS$age_short)
table(KuwaitABWVS$age_short)
table(KuwaitABWVS$Educ)
KuwaitABWVS$Educ <- as.numeric(KuwaitABWVS$Educ)
table(KuwaitABWVS$Educ)

table(KuwaitABWVS$gender)
KuwaitABWVS$gender <- as.numeric(KuwaitABWVS$gender)
table(KuwaitABWVS$gender)

table(KuwaitABWVS$Empl)
KuwaitABWVS$Empl <- as.numeric(KuwaitABWVS$Empl)
table(KuwaitABWVS$Empl)


KuwaitABWVS$Surveytype2[KuwaitABWVS$Surveytype == 1] <- 0
KuwaitABWVS$Surveytype2[KuwaitABWVS$Surveytype == 0] <- 1
table(KuwaitABWVS$Surveytype2)

#########################################KUWAIT: PERCENT MATCH################
###############re-running regressions ALL CASES IN KUWAIT TO CHECK#####################

mKuwaitABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1a)

mKuwaitABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1b)

mKuwaitABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1c)

mKuwaitABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1c2)

mKuwaitABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1d)

mKuwaitABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1e)

mKuwaitABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1e2)

mKuwaitABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1f)

mKuwaitABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS, family = binomial)
summary(mKuwaitABWVS1f2)



table(KuwaitABWVS$Unieduc)
table(KuwaitABWVS$country)

mKuwaitABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2a)
mKuwaitABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2b)

mKuwaitABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2c)

mKuwaitABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2c2)

mKuwaitABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2d)

mKuwaitABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2e)

mKuwaitABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2e2)

mKuwaitABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2f)

mKuwaitABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS2f2)


table(KuwaitABWVS$PolLead)
table(KuwaitABWVS$country)

mKuwaitABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3a)
mKuwaitABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3b)

mKuwaitABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3c)

mKuwaitABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3c2)

mKuwaitABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3d)

mKuwaitABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3e)

mKuwaitABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3e2)

mKuwaitABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS3f)


table(KuwaitABWVS$Trustpol)
table(KuwaitABWVS$country)

mKuwaitABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4a)
mKuwaitABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4b)

mKuwaitABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4c)

mKuwaitABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4d)

mKuwaitABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4d2)

mKuwaitABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4e)

mKuwaitABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4e2)

mKuwaitABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4f)

mKuwaitABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVS)
summary(mKuwaitABWVS4f2)




#########################################KUWAIT: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(KuwaitABWVS$country)
table(KuwaitABWVS$percentmatch)
KuwaitABWVSwofraude <- subset(KuwaitABWVS, percentmatch!= "1")
table(KuwaitABWVSwofraude$percentmatch)
table(KuwaitABWVSwofraude$country)

table(KuwaitABWVS$Surveytype)

table(KuwaitABWVS$gender)


mKuwaitABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1a)

mKuwaitABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1b)

mKuwaitABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1c)

mKuwaitABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1c2)

mKuwaitABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1d)

mKuwaitABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1e)

mKuwaitABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1e2)

mKuwaitABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1f)

mKuwaitABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude, family = binomial)
summary(mKuwaitABWVSwofraude1f2)



table(KuwaitABWVSwofraude$Unieduc)
table(KuwaitABWVSwofraude$country)

mKuwaitABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2a)

mKuwaitABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2b)

mKuwaitABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2c)

mKuwaitABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2c2)

mKuwaitABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2d)

mKuwaitABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2e)

mKuwaitABWVSwofraude2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2e2)

mKuwaitABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2f)

mKuwaitABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude2f2)


table(KuwaitABWVSwofraude$PolLead)
table(KuwaitABWVSwofraude$country)

mKuwaitABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3a)

mKuwaitABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3b)

mKuwaitABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3c)

mKuwaitABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3c2)

mKuwaitABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3d)

mKuwaitABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3d2)

mKuwaitABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3e)

mKuwaitABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude3f)


table(KuwaitABWVSwofraude$Trustpol)
table(KuwaitABWVSwofraude$country)

mKuwaitABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4a)

mKuwaitABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4b)

mKuwaitABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4c)

mKuwaitABWVSwofraude4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4c2)

mKuwaitABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4d)

mKuwaitABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4d2)

mKuwaitABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4e)

mKuwaitABWVSwofraude4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4e2)

mKuwaitABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4f)

mKuwaitABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = KuwaitABWVSwofraude)
summary(mKuwaitABWVSwofraude4f2)













###################################################
##########Morocco: PERCENT MATCH################
######################AB#####################
################################################
table(dmAB3$country)


Morocco <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Morocco")

MoroccoABmat <- as.matrix(Morocco)
percent_match_MoroccoAB <- c()
for(i in seq(nrow(MoroccoABmat))){
  vec <- MoroccoABmat[i,]
  dat <- MoroccoABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_MoroccoAB[i] <- max(diff)
}

qplot(percent_match_MoroccoAB)
summary(percent_match_MoroccoAB)

MoroccoAB3 <- as_tibble(MoroccoABmat)

is.numeric(percent_match_MoroccoAB)

MoroccoAB3$matchover85MoroccoAB <- rep(NA,1116)
MoroccoAB3$matchover85MoroccoAB[percent_match_MoroccoAB <= 0.849] <-0
MoroccoAB3$matchover85MoroccoAB[percent_match_MoroccoAB >= 0.850] <-1


table(MoroccoAB3$matchover85MoroccoAB) #
prop.table(table(MoroccoAB3$matchover85MoroccoAB))


##########Morocco: PERCENT MATCH################
###############WVS#####################


MoroccoWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Morocco")

MoroccoWVSmat <- as.matrix(MoroccoWVS)
percent_match_MoroccoWVS <- c()

for(i in seq(nrow(MoroccoWVSmat))){
  vec <- MoroccoWVSmat[i,]
  dat <- MoroccoWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_MoroccoWVS[i] <- max(diff)
}

qplot(percent_match_MoroccoWVS)
summary(percent_match_MoroccoWVS)

MoroccoWVS2 <- as_tibble(MoroccoWVSmat)

MoroccoWVS2$matchover85MoroccoWVS <- rep(NA,1199)
MoroccoWVS2$matchover85MoroccoWVS[percent_match_MoroccoWVS <= 0.849] <-0
MoroccoWVS2$matchover85MoroccoWVS[percent_match_MoroccoWVS >= 0.850] <-1


table(MoroccoWVS2$matchover85MoroccoWVS) #
prop.table(table(MoroccoWVS2$matchover85MoroccoWVS))

table(MoroccoWVS2$matchover85MoroccoWVS, MoroccoWVS2$Educ)
table(MoroccoWVS2$matchover85MoroccoWVS, MoroccoWVS2$age_short)


##########MOROCCO: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(MoroccoWVS2)
MoroccoWVS2$percentmatch <- as.character(MoroccoWVS2$matchover85MoroccoWVS)

table(MoroccoWVS2$percentmatch)
table(MoroccoWVS2$gender)

#AB.
names(MoroccoAB3)
MoroccoAB3$percentmatch <- as.character(MoroccoAB3$matchover85MoroccoAB)

table(MoroccoAB3$percentmatch)
table(MoroccoAB3$gender)

MoroccoABWVS <- merge(MoroccoWVS2, MoroccoAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                     "age_short",
                                                     "gender", "country", 
                                                     "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(MoroccoABWVS$country)
table(MoroccoABWVS$percentmatch)
table(MoroccoABWVS$Surveytype)

MoroccoABWVS$Trust <- as.numeric(MoroccoABWVS$Trust)
table(MoroccoABWVS$age_short)
MoroccoABWVS$age_short <- as.numeric(MoroccoABWVS$age_short)
table(MoroccoABWVS$age_short)
table(MoroccoABWVS$Educ)
MoroccoABWVS$Educ <- as.numeric(MoroccoABWVS$Educ)
table(MoroccoABWVS$Educ)

table(MoroccoABWVS$gender)
MoroccoABWVS$gender <- as.numeric(MoroccoABWVS$gender)
table(MoroccoABWVS$gender)

table(MoroccoABWVS$Empl)
MoroccoABWVS$Empl <- as.numeric(MoroccoABWVS$Empl)
table(MoroccoABWVS$Empl)


MoroccoABWVS$Surveytype2[MoroccoABWVS$Surveytype == 1] <- 0
MoroccoABWVS$Surveytype2[MoroccoABWVS$Surveytype == 0] <- 1
table(MoroccoABWVS$Surveytype2)

#########################################MOROCCO: PERCENT MATCH################
###############re-running regressions ALL CASES IN MOROCCO TO CHECK#####################

mMoroccoABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1a)

mMoroccoABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1b)

mMoroccoABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1c)

mMoroccoABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1c2)

mMoroccoABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1d)

mMoroccoABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1e)

mMoroccoABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1e2)

mMoroccoABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1f)

mMoroccoABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS, family = binomial)
summary(mMoroccoABWVS1f2)



table(MoroccoABWVS$Unieduc)
table(MoroccoABWVS$country)

mMoroccoABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2a)
mMoroccoABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2b)

mMoroccoABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2c)

mMoroccoABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2c2)

mMoroccoABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2d)

mMoroccoABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2e)

mMoroccoABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2e2)

mMoroccoABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2f)

mMoroccoABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS2f2)


table(MoroccoABWVS$PolLead)
table(MoroccoABWVS$country)

mMoroccoABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3a)
mMoroccoABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3b)

mMoroccoABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3c)

mMoroccoABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3c2)

mMoroccoABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3d)

mMoroccoABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3e)

mMoroccoABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3e2)

mMoroccoABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS3f)


table(MoroccoABWVS$Trustpol)
table(MoroccoABWVS$country)

mMoroccoABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4a)
mMoroccoABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4b)

mMoroccoABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4c)

mMoroccoABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4d)

mMoroccoABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4d2)

mMoroccoABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4e)

mMoroccoABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4e2)

mMoroccoABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4f)

mMoroccoABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVS)
summary(mMoroccoABWVS4f2)




#########################################MOROCCO: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(MoroccoABWVS$country)
table(MoroccoABWVS$percentmatch)
MoroccoABWVSwofraude <- subset(MoroccoABWVS, percentmatch!= "1")
table(MoroccoABWVSwofraude$percentmatch)
table(MoroccoABWVSwofraude$country)

table(MoroccoABWVS$Surveytype)

table(MoroccoABWVS$gender)


mMoroccoABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1a)

mMoroccoABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1b)

mMoroccoABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1c)

mMoroccoABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1c2)

mMoroccoABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1d)

mMoroccoABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1e)

mMoroccoABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1e2)

mMoroccoABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1f)

mMoroccoABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude, family = binomial)
summary(mMoroccoABWVSwofraude1f2)



table(MoroccoABWVSwofraude$Unieduc)
table(MoroccoABWVSwofraude$country)

mMoroccoABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2a)

mMoroccoABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2b)

mMoroccoABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2c)

mMoroccoABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2c2)

mMoroccoABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2d)

mMoroccoABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2e)

mMoroccoABWVSwofraude2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2e2)

mMoroccoABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2f)

mMoroccoABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude2f2)


table(MoroccoABWVSwofraude$PolLead)
table(MoroccoABWVSwofraude$country)

mMoroccoABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3a)

mMoroccoABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3b)

mMoroccoABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3c)

mMoroccoABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3c2)

mMoroccoABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3d)

mMoroccoABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3d2)

mMoroccoABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3e)

mMoroccoABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude3f)


table(MoroccoABWVSwofraude$Trustpol)
table(MoroccoABWVSwofraude$country)

mMoroccoABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4a)

mMoroccoABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4b)

mMoroccoABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4c)

mMoroccoABWVSwofraude4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4c2)

mMoroccoABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4d)

mMoroccoABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4d2)

mMoroccoABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4e)

mMoroccoABWVSwofraude4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4e2)

mMoroccoABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4f)

mMoroccoABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = MoroccoABWVSwofraude)
summary(mMoroccoABWVSwofraude4f2)











###################################################
##############Jordan: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB3$country)


Jordan <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Jordan")

JordanABmat <- as.matrix(Jordan)
percent_match_JordanAB <- c()
for(i in seq(nrow(JordanABmat))){
  vec <- JordanABmat[i,]
  dat <- JordanABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_JordanAB[i] <- max(diff)
}

qplot(percent_match_JordanAB)
summary(percent_match_JordanAB)

JordanAB3 <- as_tibble(JordanABmat)

is.numeric(percent_match_JordanAB)

JordanAB3$matchover85JordanAB <- rep(NA,1795)
JordanAB3$matchover85JordanAB[percent_match_JordanAB <= 0.849] <-0
JordanAB3$matchover85JordanAB[percent_match_JordanAB >= 0.850] <-1


table(JordanAB3$matchover85JordanAB) # 0, 1%
prop.table(table(JordanAB3$matchover85JordanAB))


##########Jordan: PERCENT MATCH################
###############WVS#####################


JordanWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Jordan")

JordanWVSmat <- as.matrix(JordanWVS)
percent_match_JordanWVS <- c()

for(i in seq(nrow(JordanWVSmat))){
  vec <- JordanWVSmat[i,]
  dat <- JordanWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_JordanWVS[i] <- max(diff)
}

qplot(percent_match_JordanWVS)
summary(percent_match_JordanWVS)

JordanWVS2 <- as_tibble(JordanWVSmat)

JordanWVS2$matchover85JordanWVS <- rep(NA,1198)
JordanWVS2$matchover85JordanWVS[percent_match_JordanWVS <= 0.849] <-0
JordanWVS2$matchover85JordanWVS[percent_match_JordanWVS >= 0.850] <-1


table(JordanWVS2$matchover85JordanWVS) # 0%
prop.table(table(JordanWVS2$matchover85JordanWVS))





##########JORDAN: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(JordanWVS2)
JordanWVS2$percentmatch <- as.character(JordanWVS2$matchover85JordanWVS)

table(JordanWVS2$percentmatch)
table(JordanWVS2$gender)

#AB.
names(JordanAB3)
JordanAB3$percentmatch <- as.character(JordanAB3$matchover85JordanAB)

table(JordanAB3$percentmatch)
table(JordanAB3$gender)

JordanABWVS <- merge(JordanWVS2, JordanAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                  "age_short",
                                                  "gender", "country", 
                                                  "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(JordanABWVS$country)
table(JordanABWVS$percentmatch)
table(JordanABWVS$Surveytype)

JordanABWVS$Trust <- as.numeric(JordanABWVS$Trust)
table(JordanABWVS$age_short)
JordanABWVS$age_short <- as.numeric(JordanABWVS$age_short)
table(JordanABWVS$age_short)
table(JordanABWVS$Educ)
JordanABWVS$Educ <- as.numeric(JordanABWVS$Educ)
table(JordanABWVS$Educ)

table(JordanABWVS$gender)
JordanABWVS$gender <- as.numeric(JordanABWVS$gender)
table(JordanABWVS$gender)

table(JordanABWVS$Empl)
JordanABWVS$Empl <- as.numeric(JordanABWVS$Empl)
table(JordanABWVS$Empl)


JordanABWVS$Surveytype2[JordanABWVS$Surveytype == 1] <- 0
JordanABWVS$Surveytype2[JordanABWVS$Surveytype == 0] <- 1
table(JordanABWVS$Surveytype2)

#########################################JORDAN: PERCENT MATCH################
###############re-running regressions ALL CASES IN JORDAN TO CHECK#####################

mJordanABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1a)

mJordanABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = JordanABWVS, family = binomial)
summary(mJordanABWVS1b)

mJordanABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = JordanABWVS, family = binomial)
summary(mJordanABWVS1c)

mJordanABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = JordanABWVS, family = binomial)
summary(mJordanABWVS1c2)

mJordanABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1d)

mJordanABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1e)

mJordanABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1e2)

mJordanABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1f)

mJordanABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS, family = binomial)
summary(mJordanABWVS1f2)



table(JordanABWVS$Unieduc)
table(JordanABWVS$country)

mJordanABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2a)
mJordanABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2b)

mJordanABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2c)

mJordanABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2c2)

mJordanABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2d)

mJordanABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2e)

mJordanABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2e2)

mJordanABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2f)

mJordanABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS2f2)


table(JordanABWVS$PolLead)
table(JordanABWVS$country)

mJordanABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3a)
mJordanABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3b)

mJordanABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3c)

mJordanABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3c2)

mJordanABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3d)

mJordanABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3e)

mJordanABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3e2)

mJordanABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS3f)


table(JordanABWVS$Trustpol)
table(JordanABWVS$country)

mJordanABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4a)
mJordanABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4b)

mJordanABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4c)

mJordanABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4d)

mJordanABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4d2)

mJordanABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4e)

mJordanABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4e2)

mJordanABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4f)

mJordanABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = JordanABWVS)
summary(mJordanABWVS4f2)








###################################################
#############Lebanon: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB3$country)


Lebanon <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Lebanon")

LebanonABmat <- as.matrix(Lebanon)
percent_match_LebanonAB <- c()
for(i in seq(nrow(LebanonABmat))){
  vec <- LebanonABmat[i,]
  dat <- LebanonABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LebanonAB[i] <- max(diff)
}

qplot(percent_match_LebanonAB)
summary(percent_match_LebanonAB)

LebanonAB3 <- as_tibble(LebanonABmat)

is.numeric(percent_match_LebanonAB)

LebanonAB3$matchover85LebanonAB <- rep(NA,1198)
LebanonAB3$matchover85LebanonAB[percent_match_LebanonAB <= 0.849] <-0
LebanonAB3$matchover85LebanonAB[percent_match_LebanonAB >= 0.850] <-1


table(LebanonAB3$matchover85LebanonAB) #
prop.table(table(LebanonAB3$matchover85LebanonAB))


##########Lebanon: PERCENT MATCH################
###############WVS#####################


LebanonWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Lebanon")

LebanonWVSmat <- as.matrix(LebanonWVS)
percent_match_LebanonWVS <- c()

for(i in seq(nrow(LebanonWVSmat))){
  vec <- LebanonWVSmat[i,]
  dat <- LebanonWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LebanonWVS[i] <- max(diff)
}

qplot(percent_match_LebanonWVS)
summary(percent_match_LebanonWVS)

LebanonWVS2 <- as_tibble(LebanonWVSmat)

LebanonWVS2$matchover85LebanonWVS <- rep(NA,1200)
LebanonWVS2$matchover85LebanonWVS[percent_match_LebanonWVS <= 0.849] <-0
LebanonWVS2$matchover85LebanonWVS[percent_match_LebanonWVS >= 0.850] <-1


table(LebanonWVS2$matchover85LebanonWVS) #
prop.table(table(LebanonWVS2$matchover85LebanonWVS))




##########LEBANON: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(LebanonWVS2)
LebanonWVS2$percentmatch <- as.character(LebanonWVS2$matchover85LebanonWVS)

table(LebanonWVS2$percentmatch)
table(LebanonWVS2$gender)

#AB.
names(LebanonAB3)
LebanonAB3$percentmatch <- as.character(LebanonAB3$matchover85LebanonAB)

table(LebanonAB3$percentmatch)
table(LebanonAB3$gender)

LebanonABWVS <- merge(LebanonWVS2, LebanonAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                     "age_short",
                                                     "gender", "country", 
                                                     "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(LebanonABWVS$country)
table(LebanonABWVS$percentmatch)
table(LebanonABWVS$Surveytype)

LebanonABWVS$Trust <- as.numeric(LebanonABWVS$Trust)
table(LebanonABWVS$age_short)
LebanonABWVS$age_short <- as.numeric(LebanonABWVS$age_short)
table(LebanonABWVS$age_short)
table(LebanonABWVS$Educ)
LebanonABWVS$Educ <- as.numeric(LebanonABWVS$Educ)
table(LebanonABWVS$Educ)

table(LebanonABWVS$gender)
LebanonABWVS$gender <- as.numeric(LebanonABWVS$gender)
table(LebanonABWVS$gender)

table(LebanonABWVS$Empl)
LebanonABWVS$Empl <- as.numeric(LebanonABWVS$Empl)
table(LebanonABWVS$Empl)


LebanonABWVS$Surveytype2[LebanonABWVS$Surveytype == 1] <- 0
LebanonABWVS$Surveytype2[LebanonABWVS$Surveytype == 0] <- 1
table(LebanonABWVS$Surveytype2)

#########################################LEBANON: PERCENT MATCH################
###############re-running regressions ALL CASES IN LEBANON TO CHECK#####################

mLebanonABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1a)

mLebanonABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1b)

mLebanonABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1c)

mLebanonABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1c2)

mLebanonABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1d)

mLebanonABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1e)

mLebanonABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1e2)

mLebanonABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1f)

mLebanonABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS, family = binomial)
summary(mLebanonABWVS1f2)



table(LebanonABWVS$Unieduc)
table(LebanonABWVS$country)

mLebanonABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2a)
mLebanonABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2b)

mLebanonABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2c)

mLebanonABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2c2)

mLebanonABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2d)

mLebanonABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2e)

mLebanonABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2e2)

mLebanonABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2f)

mLebanonABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS2f2)


table(LebanonABWVS$PolLead)
table(LebanonABWVS$country)

mLebanonABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3a)
mLebanonABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3b)

mLebanonABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3c)

mLebanonABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3c2)

mLebanonABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3d)

mLebanonABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3e)

mLebanonABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3e2)

mLebanonABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS3f)


table(LebanonABWVS$Trustpol)
table(LebanonABWVS$country)

mLebanonABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4a)
mLebanonABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4b)

mLebanonABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4c)

mLebanonABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4d)

mLebanonABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4d2)

mLebanonABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4e)

mLebanonABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4e2)

mLebanonABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4f)

mLebanonABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LebanonABWVS)
summary(mLebanonABWVS4f2)











###################################################
##########Libya: PERCENT MATCH################
######################AB#####################
################################################
table(dmAB3$country)


Libya <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Libya")

LibyaABmat <- as.matrix(Libya)
percent_match_LibyaAB <- c()
for(i in seq(nrow(LibyaABmat))){
  vec <- LibyaABmat[i,]
  dat <- LibyaABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LibyaAB[i] <- max(diff)
}

qplot(percent_match_LibyaAB)
summary(percent_match_LibyaAB)

LibyaAB3 <- as_tibble(LibyaABmat)

is.numeric(percent_match_LibyaAB)

LibyaAB3$matchover85LibyaAB <- rep(NA,1241)
LibyaAB3$matchover85LibyaAB[percent_match_LibyaAB <= 0.849] <-0
LibyaAB3$matchover85LibyaAB[percent_match_LibyaAB >= 0.850] <-1


table(LibyaAB3$matchover85LibyaAB) #
prop.table(table(LibyaAB3$matchover85LibyaAB))


##########Libya: PERCENT MATCH################
###############WVS#####################


LibyaWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Libya")

LibyaWVSmat <- as.matrix(LibyaWVS)
percent_match_LibyaWVS <- c()

for(i in seq(nrow(LibyaWVSmat))){
  vec <- LibyaWVSmat[i,]
  dat <- LibyaWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LibyaWVS[i] <- max(diff)
}

qplot(percent_match_LibyaWVS)
summary(percent_match_LibyaWVS)

LibyaWVS2 <- as_tibble(LibyaWVSmat)

LibyaWVS2$matchover85LibyaWVS <- rep(NA,2131)
LibyaWVS2$matchover85LibyaWVS[percent_match_LibyaWVS <= 0.849] <-0
LibyaWVS2$matchover85LibyaWVS[percent_match_LibyaWVS >= 0.850] <-1


table(LibyaWVS2$matchover85LibyaWVS) #
prop.table(table(LibyaWVS2$matchover85LibyaWVS))






##########LIBYA: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(LibyaWVS2)
LibyaWVS2$percentmatch <- as.character(LibyaWVS2$matchover85LibyaWVS)

table(LibyaWVS2$percentmatch)
table(LibyaWVS2$gender)

#AB.
names(LibyaAB3)
LibyaAB3$percentmatch <- as.character(LibyaAB3$matchover85LibyaAB)

table(LibyaAB3$percentmatch)
table(LibyaAB3$gender)

LibyaABWVS <- merge(LibyaWVS2, LibyaAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                               "age_short",
                                               "gender", "country", 
                                               "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(LibyaABWVS$country)
table(LibyaABWVS$percentmatch)
table(LibyaABWVS$Surveytype)

LibyaABWVS$Trust <- as.numeric(LibyaABWVS$Trust)
table(LibyaABWVS$age_short)
LibyaABWVS$age_short <- as.numeric(LibyaABWVS$age_short)
table(LibyaABWVS$age_short)
table(LibyaABWVS$Educ)
LibyaABWVS$Educ <- as.numeric(LibyaABWVS$Educ)
table(LibyaABWVS$Educ)

table(LibyaABWVS$gender)
LibyaABWVS$gender <- as.numeric(LibyaABWVS$gender)
table(LibyaABWVS$gender)

table(LibyaABWVS$Empl)
LibyaABWVS$Empl <- as.numeric(LibyaABWVS$Empl)
table(LibyaABWVS$Empl)


LibyaABWVS$Surveytype2[LibyaABWVS$Surveytype == 1] <- 0
LibyaABWVS$Surveytype2[LibyaABWVS$Surveytype == 0] <- 1
table(LibyaABWVS$Surveytype2)

#########################################LIBYA: PERCENT MATCH################
###############re-running regressions ALL CASES IN LIBYA TO CHECK#####################

mLibyaABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1a)

mLibyaABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1b)

mLibyaABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1c)

mLibyaABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1c2)

mLibyaABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1d)

mLibyaABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1e)

mLibyaABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1e2)

mLibyaABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1f)

mLibyaABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS, family = binomial)
summary(mLibyaABWVS1f2)



table(LibyaABWVS$Unieduc)
table(LibyaABWVS$country)

mLibyaABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2a)
mLibyaABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2b)

mLibyaABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2c)

mLibyaABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2c2)

mLibyaABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2d)

mLibyaABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2e)

mLibyaABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2e2)

mLibyaABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2f)

mLibyaABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS2f2)


table(LibyaABWVS$PolLead)
table(LibyaABWVS$country)

mLibyaABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3a)
mLibyaABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3b)

mLibyaABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3c)

mLibyaABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3c2)

mLibyaABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3d)

mLibyaABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3e)

mLibyaABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3e2)

mLibyaABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS3f)


table(LibyaABWVS$Trustpol)
table(LibyaABWVS$country)

mLibyaABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4a)
mLibyaABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4b)

mLibyaABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4c)

mLibyaABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4d)

mLibyaABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4d2)

mLibyaABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4e)

mLibyaABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4e2)

mLibyaABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4f)

mLibyaABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = LibyaABWVS)
summary(mLibyaABWVS4f2)
















###################################################
##########Palestine: PERCENT MATCH################
######################AB#####################
################################################
table(dmAB3$country)


Palestine <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Palestine")

PalestineABmat <- as.matrix(Palestine)
percent_match_PalestineAB <- c()
for(i in seq(nrow(PalestineABmat))){
  vec <- PalestineABmat[i,]
  dat <- PalestineABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_PalestineAB[i] <- max(diff)
}

qplot(percent_match_PalestineAB)
summary(percent_match_PalestineAB)

PalestineAB3 <- as_tibble(PalestineABmat)

is.numeric(percent_match_PalestineAB)

PalestineAB3$matchover85PalestineAB <- rep(NA,1194)
PalestineAB3$matchover85PalestineAB[percent_match_PalestineAB <= 0.849] <-0
PalestineAB3$matchover85PalestineAB[percent_match_PalestineAB >= 0.850] <-1


table(PalestineAB3$matchover85PalestineAB) #
prop.table(table(PalestineAB3$matchover85PalestineAB))


##########Palestine: PERCENT MATCH################
###############WVS#####################


PalestineWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Palestine")

PalestineWVSmat <- as.matrix(PalestineWVS)
percent_match_PalestineWVS <- c()

for(i in seq(nrow(PalestineWVSmat))){
  vec <- PalestineWVSmat[i,]
  dat <- PalestineWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_PalestineWVS[i] <- max(diff)
}

qplot(percent_match_PalestineWVS)
summary(percent_match_PalestineWVS)

PalestineWVS2 <- as_tibble(PalestineWVSmat)

PalestineWVS2$matchover85PalestineWVS <- rep(NA,998)
PalestineWVS2$matchover85PalestineWVS[percent_match_PalestineWVS <= 0.849] <-0
PalestineWVS2$matchover85PalestineWVS[percent_match_PalestineWVS >= 0.850] <-1


table(PalestineWVS2$matchover85PalestineWVS) #
prop.table(table(PalestineWVS2$matchover85PalestineWVS))




##########PALESTINE: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(PalestineWVS2)
PalestineWVS2$percentmatch <- as.character(PalestineWVS2$matchover85PalestineWVS)

table(PalestineWVS2$percentmatch)
table(PalestineWVS2$gender)

#AB.
names(PalestineAB3)
PalestineAB3$percentmatch <- as.character(PalestineAB3$matchover85PalestineAB)

table(PalestineAB3$percentmatch)
table(PalestineAB3$gender)

PalestineABWVS <- merge(PalestineWVS2, PalestineAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                           "age_short",
                                                           "gender", "country", 
                                                           "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(PalestineABWVS$country)
table(PalestineABWVS$percentmatch)
table(PalestineABWVS$Surveytype)

PalestineABWVS$Trust <- as.numeric(PalestineABWVS$Trust)
table(PalestineABWVS$age_short)
PalestineABWVS$age_short <- as.numeric(PalestineABWVS$age_short)
table(PalestineABWVS$age_short)
table(PalestineABWVS$Educ)
PalestineABWVS$Educ <- as.numeric(PalestineABWVS$Educ)
table(PalestineABWVS$Educ)

table(PalestineABWVS$gender)
PalestineABWVS$gender <- as.numeric(PalestineABWVS$gender)
table(PalestineABWVS$gender)

table(PalestineABWVS$Empl)
PalestineABWVS$Empl <- as.numeric(PalestineABWVS$Empl)
table(PalestineABWVS$Empl)


PalestineABWVS$Surveytype2[PalestineABWVS$Surveytype == 1] <- 0
PalestineABWVS$Surveytype2[PalestineABWVS$Surveytype == 0] <- 1
table(PalestineABWVS$Surveytype2)

#########################################PALESTINE: PERCENT MATCH################
###############re-running regressions ALL CASES IN PALESTINE TO CHECK#####################

mPalestineABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1a)

mPalestineABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1b)

mPalestineABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1c)

mPalestineABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1c2)

mPalestineABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1d)

mPalestineABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1e)

mPalestineABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1e2)

mPalestineABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1f)

mPalestineABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS, family = binomial)
summary(mPalestineABWVS1f2)



table(PalestineABWVS$Unieduc)
table(PalestineABWVS$country)

mPalestineABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2a)
mPalestineABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2b)

mPalestineABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2c)

mPalestineABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2c2)

mPalestineABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2d)

mPalestineABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2e)

mPalestineABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2e2)

mPalestineABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2f)

mPalestineABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS2f2)


table(PalestineABWVS$PolLead)
table(PalestineABWVS$country)

mPalestineABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3a)
mPalestineABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3b)

mPalestineABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3c)

mPalestineABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3c2)

mPalestineABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3d)

mPalestineABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3e)

mPalestineABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3e2)

mPalestineABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS3f)


table(PalestineABWVS$Trustpol)
table(PalestineABWVS$country)

mPalestineABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4a)
mPalestineABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4b)

mPalestineABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4c)

mPalestineABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4d)

mPalestineABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4d2)

mPalestineABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4e)

mPalestineABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4e2)

mPalestineABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4f)

mPalestineABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = PalestineABWVS)
summary(mPalestineABWVS4f2)












###################################################
#############Tunisia: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB3$country)


Tunisia <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Tunisia")

TunisiaABmat <- as.matrix(Tunisia)
percent_match_TunisiaAB <- c()
for(i in seq(nrow(TunisiaABmat))){
  vec <- TunisiaABmat[i,]
  dat <- TunisiaABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_TunisiaAB[i] <- max(diff)
}

qplot(percent_match_TunisiaAB)
summary(percent_match_TunisiaAB)

TunisiaAB3 <- as_tibble(TunisiaABmat)

is.numeric(percent_match_TunisiaAB)

TunisiaAB3$matchover85TunisiaAB <- rep(NA,1191)
TunisiaAB3$matchover85TunisiaAB[percent_match_TunisiaAB <= 0.849] <-0
TunisiaAB3$matchover85TunisiaAB[percent_match_TunisiaAB >= 0.850] <-1


table(TunisiaAB3$matchover85TunisiaAB) #
prop.table(table(TunisiaAB3$matchover85TunisiaAB))


##########Tunisia: PERCENT MATCH################
###############WVS#####################


TunisiaWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Tunisia")

TunisiaWVSmat <- as.matrix(TunisiaWVS)
percent_match_TunisiaWVS <- c()

for(i in seq(nrow(TunisiaWVSmat))){
  vec <- TunisiaWVSmat[i,]
  dat <- TunisiaWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_TunisiaWVS[i] <- max(diff)
}

qplot(percent_match_TunisiaWVS)
summary(percent_match_TunisiaWVS)

TunisiaWVS2 <- as_tibble(TunisiaWVSmat)

TunisiaWVS2$matchover85TunisiaWVS <- rep(NA,1204)
TunisiaWVS2$matchover85TunisiaWVS[percent_match_TunisiaWVS <= 0.849] <-0
TunisiaWVS2$matchover85TunisiaWVS[percent_match_TunisiaWVS >= 0.850] <-1


table(TunisiaWVS2$matchover85TunisiaWVS) #
prop.table(table(TunisiaWVS2$matchover85TunisiaWVS))



##########TUNISIA: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(TunisiaWVS2)
TunisiaWVS2$percentmatch <- as.character(TunisiaWVS2$matchover85TunisiaWVS)

table(TunisiaWVS2$percentmatch)
table(TunisiaWVS2$gender)

#AB.
names(TunisiaAB3)
TunisiaAB3$percentmatch <- as.character(TunisiaAB3$matchover85TunisiaAB)

table(TunisiaAB3$percentmatch)
table(TunisiaAB3$gender)

TunisiaABWVS <- merge(TunisiaWVS2, TunisiaAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                                     "age_short",
                                                     "gender", "country", 
                                                     "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(TunisiaABWVS$country)
table(TunisiaABWVS$percentmatch)
table(TunisiaABWVS$Surveytype)

TunisiaABWVS$Trust <- as.numeric(TunisiaABWVS$Trust)
table(TunisiaABWVS$age_short)
TunisiaABWVS$age_short <- as.numeric(TunisiaABWVS$age_short)
table(TunisiaABWVS$age_short)
table(TunisiaABWVS$Educ)
TunisiaABWVS$Educ <- as.numeric(TunisiaABWVS$Educ)
table(TunisiaABWVS$Educ)

table(TunisiaABWVS$gender)
TunisiaABWVS$gender <- as.numeric(TunisiaABWVS$gender)
table(TunisiaABWVS$gender)

table(TunisiaABWVS$Empl)
TunisiaABWVS$Empl <- as.numeric(TunisiaABWVS$Empl)
table(TunisiaABWVS$Empl)


TunisiaABWVS$Surveytype2[TunisiaABWVS$Surveytype == 1] <- 0
TunisiaABWVS$Surveytype2[TunisiaABWVS$Surveytype == 0] <- 1
table(TunisiaABWVS$Surveytype2)

#########################################TUNISIA: PERCENT MATCH################
###############re-running regressions ALL CASES IN TUNISIA TO CHECK#####################

mTunisiaABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1a)

mTunisiaABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1b)

mTunisiaABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1c)

mTunisiaABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1c2)

mTunisiaABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1d)

mTunisiaABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1e)

mTunisiaABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1e2)

mTunisiaABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1f)

mTunisiaABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS, family = binomial)
summary(mTunisiaABWVS1f2)



table(TunisiaABWVS$Unieduc)
table(TunisiaABWVS$country)

mTunisiaABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2a)
mTunisiaABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2b)

mTunisiaABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2c)

mTunisiaABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2c2)

mTunisiaABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2d)

mTunisiaABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2e)

mTunisiaABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2e2)

mTunisiaABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2f)

mTunisiaABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS2f2)


table(TunisiaABWVS$PolLead)
table(TunisiaABWVS$country)

mTunisiaABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3a)
mTunisiaABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3b)

mTunisiaABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3c)

mTunisiaABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3c2)

mTunisiaABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3d)

mTunisiaABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3e)

mTunisiaABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3e2)

mTunisiaABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS3f)


table(TunisiaABWVS$Trustpol)
table(TunisiaABWVS$country)

mTunisiaABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4a)
mTunisiaABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4b)

mTunisiaABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4c)

mTunisiaABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4d)

mTunisiaABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4d2)

mTunisiaABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4e)

mTunisiaABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4e2)

mTunisiaABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4f)

mTunisiaABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = TunisiaABWVS)
summary(mTunisiaABWVS4f2)














###################################################
##########Yemen: PERCENT MATCH################
######################AB#####################
################################################
table(dmAB3$country)


Yemen <- dmAB3 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Yemen")

YemenABmat <- as.matrix(Yemen)
percent_match_YemenAB <- c()
for(i in seq(nrow(YemenABmat))){
  vec <- YemenABmat[i,]
  dat <- YemenABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_YemenAB[i] <- max(diff)
}

qplot(percent_match_YemenAB)
summary(percent_match_YemenAB)

YemenAB3 <- as_tibble(YemenABmat)

is.numeric(percent_match_YemenAB)

YemenAB3$matchover85YemenAB <- rep(NA,1200)
YemenAB3$matchover85YemenAB[percent_match_YemenAB <= 0.849] <-0
YemenAB3$matchover85YemenAB[percent_match_YemenAB >= 0.850] <-1


table(YemenAB3$matchover85YemenAB) #
prop.table(table(YemenAB3$matchover85YemenAB))


##########Yemen: PERCENT MATCH################
###############WVS#####################


YemenWVS <- dmWV6 %>% 
  mutate(country = as.factor(V2)) %>% 
  filter(country == "Yemen")

YemenWVSmat <- as.matrix(YemenWVS)
percent_match_YemenWVS <- c()

for(i in seq(nrow(YemenWVSmat))){
  vec <- YemenWVSmat[i,]
  dat <- YemenWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_YemenWVS[i] <- max(diff)
}

qplot(percent_match_YemenWVS)
summary(percent_match_YemenWVS)

YemenWVS2 <- as_tibble(YemenWVSmat)

YemenWVS2$matchover85YemenWVS <- rep(NA,998)
YemenWVS2$matchover85YemenWVS[percent_match_YemenWVS <= 0.849] <-0
YemenWVS2$matchover85YemenWVS[percent_match_YemenWVS >= 0.850] <-1


table(YemenWVS2$matchover85YemenWVS) 

prop.table(table(YemenWVS2$matchover85YemenWVS))



##########YEMEN: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(YemenWVS2)
YemenWVS2$percentmatch <- as.character(YemenWVS2$matchover85YemenWVS)

table(YemenWVS2$percentmatch)
table(YemenWVS2$gender)

#AB.
names(YemenAB3)
YemenAB3$percentmatch <- as.character(YemenAB3$matchover85YemenAB)

table(YemenAB3$percentmatch)
table(YemenAB3$gender)

YemenABWVS <- merge(YemenWVS2, YemenAB3, by= c("Surveytype", "Survey", "Empl", "Mar", "Educ", 
                                               "age_short",
                                               "gender", "country", 
                                               "Trust", "Unieduc", "PolLead", "Trustpol", "id", "percentmatch"), all=TRUE)


table(YemenABWVS$country)
table(YemenABWVS$percentmatch)
table(YemenABWVS$Surveytype)

YemenABWVS$Trust <- as.numeric(YemenABWVS$Trust)
table(YemenABWVS$age_short)
YemenABWVS$age_short <- as.numeric(YemenABWVS$age_short)
table(YemenABWVS$age_short)
table(YemenABWVS$Educ)
YemenABWVS$Educ <- as.numeric(YemenABWVS$Educ)
table(YemenABWVS$Educ)

table(YemenABWVS$gender)
YemenABWVS$gender <- as.numeric(YemenABWVS$gender)
table(YemenABWVS$gender)

table(YemenABWVS$Empl)
YemenABWVS$Empl <- as.numeric(YemenABWVS$Empl)
table(YemenABWVS$Empl)


YemenABWVS$Surveytype2[YemenABWVS$Surveytype == 1] <- 0
YemenABWVS$Surveytype2[YemenABWVS$Surveytype == 0] <- 1
table(YemenABWVS$Surveytype2)

#########################################YEMEN: PERCENT MATCH################
###############re-running regressions ALL CASES IN YEMEN TO CHECK#####################

mYemenABWVS1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1a)

mYemenABWVS1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = YemenABWVS, family = binomial)
summary(mYemenABWVS1b)

mYemenABWVS1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = YemenABWVS, family = binomial)
summary(mYemenABWVS1c)

mYemenABWVS1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = YemenABWVS, family = binomial)
summary(mYemenABWVS1c2)

mYemenABWVS1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1d)

mYemenABWVS1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1e)

mYemenABWVS1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1e2)

mYemenABWVS1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1f)

mYemenABWVS1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS, family = binomial)
summary(mYemenABWVS1f2)



table(YemenABWVS$Unieduc)
table(YemenABWVS$country)

mYemenABWVS2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2a)
mYemenABWVS2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2b)

mYemenABWVS2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2c)

mYemenABWVS2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2c2)

mYemenABWVS2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2d)

mYemenABWVS2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2e)

mYemenABWVS2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2e2)

mYemenABWVS2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2f)

mYemenABWVS2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS2f2)


table(YemenABWVS$PolLead)
table(YemenABWVS$country)

mYemenABWVS3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3a)
mYemenABWVS3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3b)

mYemenABWVS3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3c)

mYemenABWVS3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3c2)

mYemenABWVS3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3d)

mYemenABWVS3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3e)

mYemenABWVS3e2 <- lm(PolLead ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3e2)

mYemenABWVS3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS3f)


table(YemenABWVS$Trustpol)
table(YemenABWVS$country)

mYemenABWVS4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4a)
mYemenABWVS4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4b)

mYemenABWVS4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4c)

mYemenABWVS4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4d)

mYemenABWVS4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4d2)

mYemenABWVS4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4e)

mYemenABWVS4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4e2)

mYemenABWVS4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4f)

mYemenABWVS4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVS)
summary(mYemenABWVS4f2)




#########################################YEMEN: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

table(YemenABWVS$country)
table(YemenABWVS$percentmatch)
YemenABWVSwofraude <- subset(YemenABWVS, percentmatch!= "1")
table(YemenABWVSwofraude$percentmatch)
table(YemenABWVSwofraude$country)

table(YemenABWVS$Surveytype)

table(YemenABWVS$gender)


mYemenABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1a)

mYemenABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl , data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1b)

mYemenABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl , data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1c)

mYemenABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl , data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1c2)

mYemenABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1d)

mYemenABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1e)

mYemenABWVSwofraude1e2 <- glm(Trust ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1e2)

mYemenABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1f)

mYemenABWVSwofraude1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude, family = binomial)
summary(mYemenABWVSwofraude1f2)



table(YemenABWVSwofraude$Unieduc)
table(YemenABWVSwofraude$country)

mYemenABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2a)

mYemenABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2b)

mYemenABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2c)

mYemenABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2c2)

mYemenABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2d)

mYemenABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2e)

mYemenABWVSwofraude2e2 <- lm(Unieduc ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2e2)

mYemenABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2f)

mYemenABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude2f2)


table(YemenABWVSwofraude$PolLead)
table(YemenABWVSwofraude$country)

mYemenABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3a)

mYemenABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3b)

mYemenABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3c)

mYemenABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3c2)

mYemenABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3d)

mYemenABWVSwofraude3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3d2)

mYemenABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3e)

mYemenABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude3f)


table(YemenABWVSwofraude$Trustpol)
table(YemenABWVSwofraude$country)

mYemenABWVSwofraude4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4a)

mYemenABWVSwofraude4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4b)

mYemenABWVSwofraude4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4c)

mYemenABWVSwofraude4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4c2)

mYemenABWVSwofraude4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4d)

mYemenABWVSwofraude4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4d2)

mYemenABWVSwofraude4e <- lm(Trustpol ~ Surveytype + gender + Mar*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4e)

mYemenABWVSwofraude4e2 <- lm(Trustpol ~ Surveytype2 + gender + Mar*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4e2)

mYemenABWVSwofraude4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4f)

mYemenABWVSwofraude4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + Mar + Empl, data = YemenABWVSwofraude)
summary(mYemenABWVSwofraude4f2)













##################################################################################################################
##################################################################################################################
#########################################PERCENT MATCH ANALYSES 2018##############################################
##################################################################################################################
##################################################################################################################

################################################
#################ID#############################
################################################

table(dmAB5$Survey)
dmAB5$Survey <- rep("AB", 12061)
table(dmWV7$Survey)
dmWV7$Survey <- rep("WVS", 6011)

dmAB5$id <- c(1:12061)
summary(dmAB5$id)
length(dmWV7$Survey)
dmWV7$id <- c(12062:18072)
summary(dmWV7$id)


# Merging AB and WVS, all variables, full datasets---------------------------------------------------

table(dmWV7$id)

ABWVS <- merge(dmAB5, dmWV7, by= c("Surveytype", "Survey", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                   "age_short",
                                   "gender", "country", 
                                   "Trust", "Unieduc", "PolLead", "Trustpol", "id"), all=TRUE)

names(ABWVS)

summary(ABWVS$id)
table(ABWVS$Empl)
table(ABWVS$survey)
table(ABWVS$country)
table(ABWVS$singled)
summary(ABWVS$Surveytype)
ABWVS$Surveytype <- as.factor (ABWVS$Surveytype)
summary(ABWVS$Surveytype)
table(ABWVS$Surveytype)


ABWVS$Surveytype2[ABWVS$Surveytype == 1] <- 0
ABWVS$Surveytype2[ABWVS$Surveytype == 0] <- 1
table(ABWVS$Surveytype2)
#Surveytype has 0 WVS, 1 AB // Surveytype2 has 0 AB, 1 WVS




##################################################################################################################
##################################################################################################################
#####################################ANALYSIS 2: PER-COUNTRY DESCRIPTIVES#########################################
###################################IN EXCEL FILE: "UNIVARIATE ANALYSES PT 1"######################################
##################################################################################################################
##################################################################################################################



################################################
######################EGYPT#####################
################################################

table(ABWVS$country)
Egypt <- ABWVS[ABWVS$country == "Egypt", ]
table(Egypt$country)

summary(Egypt$Surveytype)
aggregate(Egypt$Trust ~ Surveytype, Egypt, mean)
chisq.test(table(Egypt$Trust,Egypt$Surveytype))
t.test(Egypt$Unieduc ~ Egypt$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Egypt$PolLead ~ Egypt$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
#t.test(Egypt$Trustpol ~ Egypt$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Egypt$Trust, Egypt$Surveytype), 2)
prop.table (table(Egypt$Unieduc, Egypt$Surveytype), 2)
prop.table (table(Egypt$PolLead, Egypt$Surveytype), 2)
# prop.table (table(Egypt$Trustpol, Egypt$Surveytype), 2)

aggregate(Egypt$Trust ~ Surveytype, Egypt, length)
aggregate(Egypt$Unieduc ~ Surveytype, Egypt, length)
aggregate(Egypt$PolLead ~ Surveytype, Egypt, length)
#aggregate(Egypt$Trustpol ~ Surveytype, Egypt, length)



################################################
####################IRAQ########################
################################################

table(ABWVS$country)
Iraq <- ABWVS[ABWVS$country == "Iraq", ]
table(Iraq$country)

summary(Iraq$Surveytype)
aggregate(Iraq$Trust ~ Surveytype, Iraq, mean)
chisq.test(table(Iraq$Trust,Iraq$Surveytype))
t.test(Iraq$Unieduc ~ Iraq$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Iraq$PolLead ~ Iraq$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Iraq$Trustpol ~ Iraq$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Iraq$Trust, Iraq$Surveytype), 2)
prop.table (table(Iraq$Unieduc, Iraq$Surveytype), 2)
prop.table (table(Iraq$PolLead, Iraq$Surveytype), 2)
prop.table (table(Iraq$Trustpol, Iraq$Surveytype), 2)

aggregate(Iraq$Trust ~ Surveytype, Iraq, length)
aggregate(Iraq$Unieduc ~ Surveytype, Iraq, length)
aggregate(Iraq$PolLead ~ Surveytype, Iraq, length)
aggregate(Iraq$Trustpol ~ Surveytype, Iraq, length)



################################################
####################JORDAN######################
################################################

table(ABWVS$country)
Jordan <- ABWVS[ABWVS$country == "Jordan", ]
table(Jordan$country)
table(ABWVS$country)

summary(Jordan$Surveytype)
aggregate(Jordan$Trust ~ Surveytype, Jordan, mean)
chisq.test(table(Jordan$Trust,Jordan$Surveytype))
t.test(Jordan$Unieduc ~ Jordan$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Jordan$PolLead ~ Jordan$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Jordan$Trustpol ~ Jordan$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Jordan$Trust, Jordan$Surveytype), 2)
prop.table (table(Jordan$Unieduc, Jordan$Surveytype), 2)
prop.table (table(Jordan$PolLead, Jordan$Surveytype), 2)
prop.table (table(Jordan$Trustpol, Jordan$Surveytype), 2)

aggregate(Jordan$Trust ~ Surveytype, Jordan, length)
aggregate(Jordan$Unieduc ~ Surveytype, Jordan, length)
aggregate(Jordan$PolLead ~ Surveytype, Jordan, length)
aggregate(Jordan$Trustpol ~ Surveytype, Jordan, length)



################################################
####################LEBANON#####################
################################################

table(ABWVS$country)
Lebanon <- ABWVS[ABWVS$country == "Lebanon", ]
table(Lebanon$country)
table(ABWVS$country)

summary(Lebanon$Surveytype)
aggregate(Lebanon$Trust ~ Surveytype, Lebanon, mean)
chisq.test(table(Lebanon$Trust,Lebanon$Surveytype))
t.test(Lebanon$Unieduc ~ Lebanon$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Lebanon$PolLead ~ Lebanon$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Lebanon$Trustpol ~ Lebanon$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Lebanon$Trust, Lebanon$Surveytype), 2)
prop.table (table(Lebanon$Unieduc, Lebanon$Surveytype), 2)
prop.table (table(Lebanon$PolLead, Lebanon$Surveytype), 2)
prop.table (table(Lebanon$Trustpol, Lebanon$Surveytype), 2)

aggregate(Lebanon$Trust ~ Surveytype, Lebanon, length)
aggregate(Lebanon$Unieduc ~ Surveytype, Lebanon, length)
aggregate(Lebanon$PolLead ~ Surveytype, Lebanon, length)
aggregate(Lebanon$Trustpol ~ Surveytype, Lebanon, length)



################################################
####################TUNISIA#####################
################################################

table(ABWVS$country)
Tunisia <- ABWVS[ABWVS$country == "Tunisia", ]
table(Tunisia$country)
table(ABWVS$country)

summary(Tunisia$Surveytype)
aggregate(Tunisia$Trust ~ Surveytype, Tunisia, mean)
chisq.test(table(Tunisia$Trust,Tunisia$Surveytype))
t.test(Tunisia$Unieduc ~ Tunisia$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Tunisia$PolLead ~ Tunisia$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)
t.test(Tunisia$Trustpol ~ Tunisia$Surveytype, mu=0, alt = "two.sided", conf=0.95, var.eq=F, paired=F)

prop.table (table(Tunisia$Trust, Tunisia$Surveytype), 2)
prop.table (table(Tunisia$Unieduc, Tunisia$Surveytype), 2)
prop.table (table(Tunisia$PolLead, Tunisia$Surveytype), 2)
prop.table (table(Tunisia$Trustpol, Tunisia$Surveytype), 2)

aggregate(Tunisia$Trust ~ Surveytype, Tunisia, length)
aggregate(Tunisia$Unieduc ~ Surveytype, Tunisia, length)
aggregate(Tunisia$PolLead ~ Surveytype, Tunisia, length)
aggregate(Tunisia$Trustpol ~ Surveytype, Tunisia, length)









##################################################################################################################
##################################################################################################################
##############################################PERCENT MATCH#######################################################
##################################################################################################################
##################################################################################################################

getwd()
#setwd("C:/R").
library(tidyverse)
library(Matrix)
library(lme4)
library(foreign)
library(ggplot2)
detach("package:memisc", unload = TRUE)


###################################################
##############EGYPT: PERCENT MATCH#################
###########################AB######################
###################################################
table(dmAB5$country)

Egypt <- dmAB5 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Egypt")
table(Egypt$Surveytype)

EgyptABmat <- as.matrix(Egypt)
percent_match_EgyptAB <- c()
for(i in seq(nrow(EgyptABmat))){
  vec <- EgyptABmat[i,]
  dat <- EgyptABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_EgyptAB[i] <- max(diff)
}

qplot(percent_match_EgyptAB)
summary(percent_match_EgyptAB)

EgyptAB3 <- as_tibble(EgyptABmat)

is.numeric(percent_match_EgyptAB)

EgyptAB3$matchover85EgyptAB <- rep(NA,2400)
EgyptAB3$matchover85EgyptAB[percent_match_EgyptAB <= 0.849] <-0
EgyptAB3$matchover85EgyptAB[percent_match_EgyptAB >= 0.850] <-1


table(EgyptAB3$matchover85EgyptAB) # 2 cases.
prop.table(table(EgyptAB3$matchover85EgyptAB))

table(EgyptAB3$singled)

##########EGYPT: PERCENT MATCH################
###############WVS#####################

EgyptWVS <- dmWV7 %>% 
  mutate(country = as.factor(B_COUNTRY)) %>% 
  filter(country == "Egypt")
table(EgyptWVS$country)

EgyptWVSmat <- as.matrix(EgyptWVS)
percent_match_EgyptWVS <- c()

for(i in seq(nrow(EgyptWVSmat))){
  vec <- EgyptWVSmat[i,]
  dat <- EgyptWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_EgyptWVS[i] <- max(diff)
}

qplot(percent_match_EgyptWVS)
summary(percent_match_EgyptWVS)

EgyptWVS2 <- as_tibble(EgyptWVSmat)

EgyptWVS2$matchover85EgyptWVS <- rep(NA,1200)
EgyptWVS2$matchover85EgyptWVS[percent_match_EgyptWVS <= 0.849] <-0
EgyptWVS2$matchover85EgyptWVS[percent_match_EgyptWVS >= 0.850] <-1


table(EgyptWVS2$matchover85EgyptWVS) # 84 cases, 0.07.
prop.table(table(EgyptWVS2$matchover85EgyptWVS))

table(EgyptWVS2$singled)
table(EgyptAB3$gender)

##########EGYPT: PERCENT MATCH################
###############creating percent match var and merging and deselecting#####################

#WVS.
names(EgyptWVS2)
EgyptWVS2$percentmatch <- as.character(EgyptWVS2$matchover85EgyptWVS)

table(EgyptWVS2$percentmatch)
table(EgyptWVS2$gender)

#AB.
names(EgyptAB3)
EgyptAB3$percentmatch <- as.character(EgyptAB3$matchover85EgyptAB)

table(EgyptAB3$percentmatch)
table(EgyptAB3$gender)

EgyptABWVS <- merge(EgyptWVS2, EgyptAB3, by= c("Surveytype", "Empl", "Mar", "singled", "othermaritald", "Educ", 
                                               "age_short",
                                               "gender", "country", 
                                               "Trust", "Unieduc", "PolLead", "id", "percentmatch"), all=TRUE)

table(EgyptWVS2$percentmatch)
table(EgyptAB3$id)

table(EgyptABWVS$country)
table(EgyptABWVS$singled)
table(EgyptABWVS$percentmatch)
table(EgyptABWVS$Surveytype)
table(EgyptABWVS$gender)
table(EgyptABWVS$Mar)
table(EgyptABWVS$Trust)

EgyptABWVS$Trust <- as.numeric(EgyptABWVS$Trust)
table(EgyptABWVS$age_short)
EgyptABWVS$age_short <- as.numeric(EgyptABWVS$age_short)
table(EgyptABWVS$age_short)
table(EgyptABWVS$Educ)
EgyptABWVS$Educ <- as.numeric(EgyptABWVS$Educ)
table(EgyptABWVS$Educ)

EgyptABWVS$Mar <- as.numeric(EgyptABWVS$Mar)
table(EgyptABWVS$Mar)

EgyptABWVS$singled <- as.numeric(EgyptABWVS$singled)
table(EgyptABWVS$singled)

EgyptABWVS$othermaritald <- as.numeric(EgyptABWVS$othermaritald)
table(EgyptABWVS$othermaritald)

EgyptABWVS$Surveytype2[EgyptABWVS$Surveytype == 1] <- 0
EgyptABWVS$Surveytype2[EgyptABWVS$Surveytype == 0] <- 1
table(EgyptABWVS$Surveytype2)




################################################
#########EGYPTABWVSWOFRAUDE#####################
################################################

############UNIVARIATES#########################

table(EgyptABWVS$country)
table(EgyptABWVS$percentmatch)
EgyptABWVSwofraude <- subset(EgyptABWVS, percentmatch!= "1")
table(EgyptABWVSwofraude$percentmatch)
table(EgyptABWVSwofraude$country)
table(EgyptABWVSwofraude$gender)

prop.table (table(EgyptABWVSwofraude$Trust, EgyptABWVSwofraude$Surveytype), 2)
prop.table (table(EgyptABWVSwofraude$Unieduc, EgyptABWVSwofraude$Surveytype), 2)
prop.table (table(EgyptABWVSwofraude$PolLead, EgyptABWVSwofraude$Surveytype), 2)
#prop.table (table(EgyptABWVSwofraude$Trustpol, EgyptABWVSwofraude$Surveytype), 2)

table(Egypt$Trustpol, Egypt$Surveytype)

#########################################EGYPT: PERCENT MATCH################
###############regressions WITHOUT FRAUDULENT CASES#####################

mEgyptABWVSwofraude1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1a)

mEgyptABWVSwofraude1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1b)

mEgyptABWVSwofraude1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1c)

mEgyptABWVSwofraude1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl , data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1c2)

mEgyptABWVSwofraude1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1d)

mEgyptABWVSwofraude1e <- glm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1e)

mEgyptABWVSwofraude1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude, family = binomial)
summary(mEgyptABWVSwofraude1f)




table(EgyptABWVSwofraude$Unieduc)
table(EgyptABWVSwofraude$country)

mEgyptABWVSwofraude2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2a)

mEgyptABWVSwofraude2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2b)

mEgyptABWVSwofraude2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2c)

mEgyptABWVSwofraude2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2c2)

mEgyptABWVSwofraude2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2d)

mEgyptABWVSwofraude2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2e)

mEgyptABWVSwofraude2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2f)

mEgyptABWVSwofraude2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude2f2)


table(EgyptABWVSwofraude$PolLead)
table(EgyptABWVSwofraude$country)

mEgyptABWVSwofraude3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3a)

mEgyptABWVSwofraude3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3b)

mEgyptABWVSwofraude3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3c)

mEgyptABWVSwofraude3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3c2)

mEgyptABWVSwofraude3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3d)

mEgyptABWVSwofraude3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3e)

mEgyptABWVSwofraude3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = EgyptABWVSwofraude)
summary(mEgyptABWVSwofraude3f)



















###################################################
################IRAQ: PERCENT MATCH################
############################AB#####################
##################################################
table(dmAB5$country)


Iraq <- dmAB5 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Iraq")

table(Iraq$Surveytype)

IraqABmat <- as.matrix(Iraq)
percent_match_IraqAB <- c()
for(i in seq(nrow(IraqABmat))){
  vec <- IraqABmat[i,]
  dat <- IraqABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_IraqAB[i] <- max(diff)
}

qplot(percent_match_IraqAB)
summary(percent_match_IraqAB)

IraqAB3 <- as_tibble(IraqABmat)

is.numeric(percent_match_IraqAB)

IraqAB3$matchover85IraqAB <- rep(NA,2461)
IraqAB3$matchover85IraqAB[percent_match_IraqAB <= 0.849] <-0
IraqAB3$matchover85IraqAB[percent_match_IraqAB >= 0.850] <-1


table(IraqAB3$matchover85IraqAB) # 6 cases
prop.table(table(IraqAB3$matchover85IraqAB))


##########Iraq: PERCENT MATCH################
###############WVS#####################

IraqWVS <- dmWV7 %>% 
  mutate(country = as.factor(B_COUNTRY)) %>% 
  filter(country == "Iraq")
table(IraqWVS$Surveytype)

IraqWVSmat <- as.matrix(IraqWVS)
percent_match_IraqWVS <- c()

for(i in seq(nrow(IraqWVSmat))){
  vec <- IraqWVSmat[i,]
  dat <- IraqWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_IraqWVS[i] <- max(diff)
}

qplot(percent_match_IraqWVS)
summary(percent_match_IraqWVS)

IraqWVS2 <- as_tibble(IraqWVSmat)

IraqWVS2$matchover85IraqWVS <- rep(NA,1200)
IraqWVS2$matchover85IraqWVS[percent_match_IraqWVS <= 0.849] <-0
IraqWVS2$matchover85IraqWVS[percent_match_IraqWVS >= 0.850] <-1


table(IraqWVS2$matchover85IraqWVS) # 27.
prop.table(table(IraqWVS2$matchover85IraqWVS))

###################################################
##############Jordan: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB5$country)

Jordan <- dmAB5 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Jordan")

table(Jordan$Surveytype)

JordanABmat <- as.matrix(Jordan)
percent_match_JordanAB <- c()
for(i in seq(nrow(JordanABmat))){
  vec <- JordanABmat[i,]
  dat <- JordanABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_JordanAB[i] <- max(diff)
}

qplot(percent_match_JordanAB)
summary(percent_match_JordanAB)

JordanAB3 <- as_tibble(JordanABmat)

is.numeric(percent_match_JordanAB)

JordanAB3$matchover85JordanAB <- rep(NA,2400)
JordanAB3$matchover85JordanAB[percent_match_JordanAB <= 0.849] <-0
JordanAB3$matchover85JordanAB[percent_match_JordanAB >= 0.850] <-1


table(JordanAB3$matchover85JordanAB) # 
prop.table(table(JordanAB3$matchover85JordanAB))


##########Jordan: PERCENT MATCH################
###############WVS#####################

JordanWVS <- dmWV7 %>% 
  mutate(country = as.factor(B_COUNTRY)) %>% 
  filter(country == "Jordan")
table(Jordan$Surveytype)

JordanWVSmat <- as.matrix(JordanWVS)
percent_match_JordanWVS <- c()

for(i in seq(nrow(JordanWVSmat))){
  vec <- JordanWVSmat[i,]
  dat <- JordanWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_JordanWVS[i] <- max(diff)
}

qplot(percent_match_JordanWVS)
summary(percent_match_JordanWVS)

JordanWVS2 <- as_tibble(JordanWVSmat)

JordanWVS2$matchover85JordanWVS <- rep(NA,2400)
JordanWVS2$matchover85JordanWVS[percent_match_JordanWVS <= 0.849] <-0
JordanWVS2$matchover85JordanWVS[percent_match_JordanWVS >= 0.850] <-1


table(JordanWVS2$matchover85JordanWVS) # 
prop.table(table(JordanWVS2$matchover85JordanWVS))

###################################################
#############Lebanon: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB5$country)

Lebanon <- dmAB5 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Lebanon")

table(Lebanon$country)

LebanonABmat <- as.matrix(Lebanon)
percent_match_LebanonAB <- c()
for(i in seq(nrow(LebanonABmat))){
  vec <- LebanonABmat[i,]
  dat <- LebanonABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LebanonAB[i] <- max(diff)
}

qplot(percent_match_LebanonAB)
summary(percent_match_LebanonAB)

LebanonAB3 <- as_tibble(LebanonABmat)

is.numeric(percent_match_LebanonAB)

LebanonAB3$matchover85LebanonAB <- rep(NA,2400)
LebanonAB3$matchover85LebanonAB[percent_match_LebanonAB <= 0.849] <-0
LebanonAB3$matchover85LebanonAB[percent_match_LebanonAB >= 0.850] <-1


table(LebanonAB3$matchover85LebanonAB) #90.
prop.table(table(LebanonAB3$matchover85LebanonAB))


##########Lebanon: PERCENT MATCH################
###############WVS#####################


LebanonWVS <- dmWV7 %>% 
  mutate(country = as.factor(B_COUNTRY)) %>% 
  filter(country == "Lebanon")
table(LebanonWVS$country)


LebanonWVSmat <- as.matrix(LebanonWVS)
percent_match_LebanonWVS <- c()

for(i in seq(nrow(LebanonWVSmat))){
  vec <- LebanonWVSmat[i,]
  dat <- LebanonWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_LebanonWVS[i] <- max(diff)
}

qplot(percent_match_LebanonWVS)
summary(percent_match_LebanonWVS)

LebanonWVS2 <- as_tibble(LebanonWVSmat)

LebanonWVS2$matchover85LebanonWVS <- rep(NA,1200)
LebanonWVS2$matchover85LebanonWVS[percent_match_LebanonWVS <= 0.849] <-0
LebanonWVS2$matchover85LebanonWVS[percent_match_LebanonWVS >= 0.850] <-1


table(LebanonWVS2$matchover85LebanonWVS) #
prop.table(table(LebanonWVS2$matchover85LebanonWVS))

###################################################
#############Tunisia: PERCENT MATCH################
############################AB#####################
###################################################
table(dmAB5$country)


Tunisia <- dmAB5 %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Tunisia")

table(Tunisia$Surveytype)

TunisiaABmat <- as.matrix(Tunisia)
percent_match_TunisiaAB <- c()
for(i in seq(nrow(TunisiaABmat))){
  vec <- TunisiaABmat[i,]
  dat <- TunisiaABmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_TunisiaAB[i] <- max(diff)
}

qplot(percent_match_TunisiaAB)
summary(percent_match_TunisiaAB)

TunisiaAB3 <- as_tibble(TunisiaABmat)

is.numeric(percent_match_TunisiaAB)

TunisiaAB3$matchover85TunisiaAB <- rep(NA,2400)
TunisiaAB3$matchover85TunisiaAB[percent_match_TunisiaAB <= 0.849] <-0
TunisiaAB3$matchover85TunisiaAB[percent_match_TunisiaAB >= 0.850] <-1


table(TunisiaAB3$matchover85TunisiaAB) #
prop.table(table(TunisiaAB3$matchover85TunisiaAB))


##########Tunisia: PERCENT MATCH################
###############WVS#####################


TunisiaWVS <- dmWV7 %>% 
  mutate(country = as.factor(B_COUNTRY)) %>% 
  filter(country == "Tunisia")

table(TunisiaWVS$Surveytype)

TunisiaWVSmat <- as.matrix(TunisiaWVS)
percent_match_TunisiaWVS <- c()

for(i in seq(nrow(TunisiaWVSmat))){
  vec <- TunisiaWVSmat[i,]
  dat <- TunisiaWVSmat[-i,]
  diff <- c()
  for(j in seq(nrow(dat))){
    diff[j] <- (vec == dat[j,]) %>% mean(na.rm = T)
  }
  percent_match_TunisiaWVS[i] <- max(diff)
}

qplot(percent_match_TunisiaWVS)
summary(percent_match_TunisiaWVS)

TunisiaWVS2 <- as_tibble(TunisiaWVSmat)

TunisiaWVS2$matchover85TunisiaWVS <- rep(NA,1204)
TunisiaWVS2$matchover85TunisiaWVS[percent_match_TunisiaWVS <= 0.849] <-0
TunisiaWVS2$matchover85TunisiaWVS[percent_match_TunisiaWVS >= 0.850] <-1


table(TunisiaWVS2$matchover85TunisiaWVS) #
prop.table(table(TunisiaWVS2$matchover85TunisiaWVS))









##################################################################################################################
##################################################################################################################
####################################ANALYSIS 7: FLAT REGRESSIONS, PER COUNTRY#####################################
######################################IN EXCEL FILE: "RE-CHECKING OLD ANALYSES"###################################
##################################################################################################################
##################################################################################################################

################################################
######################EGYPT#####################
################################################

Egypt <- ABWVS %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Egypt")

table(ABWVS$country)
table(Egypt$country)

mEgypt1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Egypt, family = binomial)
summary(mEgypt1a)

mEgypt1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Egypt, family = binomial)
summary(mEgypt1b)

mEgypt1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Egypt, family = binomial)
summary(mEgypt1c)

mEgypt1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl , data = Egypt, family = binomial)
summary(mEgypt1c2)

mEgypt1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt, family = binomial)
summary(mEgypt1d)

mEgypt1e <- glm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype+ age_short + Educ + singled + othermaritald+ Empl, data = Egypt, family = binomial)
summary(mEgypt1e)

mEgypt1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt, family = binomial)
summary(mEgypt1f)

mEgypt1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt, family = binomial)
summary(mEgypt1f2)


table(Egypt$Unieduc)
table(Egypt$country)

mEgypt2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2a)

mEgypt2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2b)

mEgypt2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2c)

mEgypt2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2c2)

mEgypt2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2d)

mEgypt2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + singled + othermaritald + age_short + Educ + Empl, data = Egypt)
summary(mEgypt2e)

mEgypt2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2f)

mEgypt2f2 <- lm(Unieduc ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt2f2)


table(Egypt$PolLead)
table(Egypt$country)

mEgypt3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3a)
mEgypt3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3b)

mEgypt3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3c)

mEgypt3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3c2)

mEgypt3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3d)

mEgypt3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + singled + othermaritald + age_short + Educ + Empl, data = Egypt)
summary(mEgypt3e)

mEgypt3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt3f)


table(Egypt$Trustpol)
table(Egypt$country)

table(Egypt$Trustpol, Egypt$Surveytype)

mEgypt4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4a)
mEgypt4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4b)

mEgypt4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4c)

mEgypt4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4d)

mEgypt4d2 <- lm(Trustpol ~ surveytype2 + gender + Educ*surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4d2)

mEgypt4e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4e)

mEgypt4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4f)

mEgypt4f2 <- lm(Trustpol ~ surveytype2 + gender + Empl*surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Egypt)
summary(mEgypt4f2)








################################################
#######################IRAQ#####################
################################################

Iraq <- ABWVS %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Iraq")

table(ABWVS$country)
table(Iraq$country)

mIraq1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Iraq, family = binomial)
summary(mIraq1a)

mIraq1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Iraq, family = binomial)
summary(mIraq1b)

mIraq1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Iraq, family = binomial)
summary(mIraq1c)

mIraq1c2 <- glm(Trust ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl , data = Iraq, family = binomial)
summary(mIraq1c2)

mIraq1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq, family = binomial)
summary(mIraq1d)

mIraq1e <- glm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq, family = binomial)
summary(mIraq1e)

mIraq1e2 <- glm(Trust ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq, family = binomial)
summary(mIraq1e2)

mIraq1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq, family = binomial)
summary(mIraq1f)

table(Iraq$Unieduc)
table(Iraq$country)

mIraq2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2a)
mIraq2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2b)

mIraq2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2c)

mIraq2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2d)

mIraq2d2 <- lm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2d2)

mIraq2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2e)

mIraq2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq2f)


table(Iraq$PolLead)
table(Iraq$country)

mIraq3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3a)

mIraq3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3b)

mIraq3b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3b2)

mIraq3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3c)

mIraq3c2 <- lm(PolLead ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3c2)

mIraq3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3d)

mIraq3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3e)

mIraq3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq3f)


table(Iraq$Trustpol)
table(Iraq$country)

mIraq4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4a)
mIraq4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4b)

mIraq4b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4b2)

mIraq4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4c)

mIraq4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4c2)

mIraq4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4d)

mIraq4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4d2)

mIraq4e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4e)

mIraq4e2 <- lm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4e2)

mIraq4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Iraq)
summary(mIraq4f)





################################################
#####################JORDAN#####################
################################################

Jordan <- ABWVS %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Jordan")

table(ABWVS$country)
table(Jordan$country)

mJordan1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Jordan, family = binomial)
summary(mJordan1a)

mJordan1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Jordan, family = binomial)
summary(mJordan1b)

mJordan1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Jordan, family = binomial)
summary(mJordan1c)

mJordan1d2 <- glm(Trust ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan, family = binomial)
summary(mJordan1d2)

mJordan1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan, family = binomial)
summary(mJordan1d)

mJordan1e <- glm(Trust ~ Surveytype + gender + + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan, family = binomial)
summary(mJordan1e)

mJordan1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan, family = binomial)
summary(mJordan1f)


table(Jordan$Unieduc)
table(Jordan$country)

mJordan2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2a)
mJordan2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2b)

mJordan2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2c)

mJordan2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2d)

mJordan2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2e)

mJordan2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan2f)


table(Jordan$PolLead)
table(Jordan$country)

mJordan3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3a)

mJordan3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3b)

mJordan3b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3b2)

mJordan3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3c)

mJordan3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3d)

mJordan3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3e)

mJordan3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan3f)


table(Jordan$Trustpol)
table(Jordan$country)

mJordan4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4a)
mJordan4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4b)

mJordan4b2 <- lm(Trustpol ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4b2)

mJordan4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4c2)

mJordan4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4c)

mJordan4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4d)

mJordan4e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4e)

mJordan4e2 <- lm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4e2)

mJordan4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Jordan)
summary(mJordan4f)






################################################
####################LEBANON#####################
################################################

Lebanon <- ABWVS %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Lebanon")

table(ABWVS$country)
table(Lebanon$country)

mLebanon1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Lebanon, family = binomial)
summary(mLebanon1a)

mLebanon1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Lebanon, family = binomial)
summary(mLebanon1b)

mLebanon1b2 <- glm(Trust ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl , data = Lebanon, family = binomial)
summary(mLebanon1b2)

mLebanon1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Lebanon, family = binomial)
summary(mLebanon1c)

mLebanon1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon, family = binomial)
summary(mLebanon1d)

mLebanon1e <- glm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon, family = binomial)
summary(mLebanon1e)

mLebanon1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon, family = binomial)
summary(mLebanon1f)

mLebanon1f2 <- glm(Trust ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon, family = binomial)
summary(mLebanon1f2)


table(Lebanon$Unieduc)
table(Lebanon$country)

mLebanon2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2a)

mLebanon2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2b)

mLebanon2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2c)

mLebanon2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2d)

mLebanon2d2 <- lm(Unieduc ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2d2)

mLebanon2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2e)

mLebanon2e2 <- lm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2e2)

mLebanon2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon2f)


table(Lebanon$PolLead)
table(Lebanon$country)

mLebanon3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3a)

mLebanon3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3b)

mLebanon3b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3b2)

mLebanon3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3c)

mLebanon3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3d)

mLebanon3d2 <- lm(PolLead ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3d2)

mLebanon3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3e)

mLebanon3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon3f)


table(Lebanon$Trustpol)
table(Lebanon$country)

mLebanon4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4a)

mLebanon4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4b)

mLebanon4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4c)

mLebanon4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4d)

mLebanon4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4d2)

mLebanon4e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4e)

mLebanon4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4f)

mLebanon4f2 <- lm(Trustpol ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Lebanon)
summary(mLebanon4f2)




################################################
####################TUNISIA#####################
################################################

Tunisia <- ABWVS %>% 
  mutate(country = as.factor(country)) %>% 
  filter(country == "Tunisia")

table(ABWVS$country)
table(Tunisia$country)

mTunisia1a <- glm(Trust ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Tunisia, family = binomial)
summary(mTunisia1a)

mTunisia1b <- glm(Trust ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Tunisia, family = binomial)
summary(mTunisia1b)

mTunisia1c <- glm(Trust ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl , data = Tunisia, family = binomial)
summary(mTunisia1c)

mTunisia1d <- glm(Trust ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia, family = binomial)
summary(mTunisia1d)

mTunisia1e <- glm(Trust ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia, family = binomial)
summary(mTunisia1e)

mTunisia1f <- glm(Trust ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia, family = binomial)
summary(mTunisia1f)


table(Tunisia$Unieduc)
table(Tunisia$country)

mTunisia2a <- lm(Unieduc ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2a)

mTunisia2b <- lm(Unieduc ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2b)

mTunisia2b2 <- lm(Unieduc ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2b2)

mTunisia2c <- lm(Unieduc ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2c)

mTunisia2c2 <- lm(Unieduc ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2c2)

mTunisia2d <- lm(Unieduc ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2d)

mTunisia2e <- lm(Unieduc ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2e)

mTunisia2e2 <- lm(Unieduc ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2e2)

mTunisia2f <- lm(Unieduc ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia2f)


table(Tunisia$PolLead)
table(Tunisia$country)

mTunisia3a <- lm(PolLead ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3a)

mTunisia3b <- lm(PolLead ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3b)

mTunisia3b2 <- lm(PolLead ~ Surveytype2 + gender + gender*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3b2)

mTunisia3c <- lm(PolLead ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3c)

mTunisia3d <- lm(PolLead ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3d)

mTunisia3e <- lm(PolLead ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3e)

mTunisia3e2 <- lm(PolLead ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3e2)

mTunisia3f <- lm(PolLead ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3f)

mTunisia3f2 <- lm(PolLead ~ Surveytype2 + gender + Empl*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia3f2)

table(Tunisia$Trustpol)
table(Tunisia$country)

mTunisia4a <- lm(Trustpol ~ Surveytype + gender + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4a)

mTunisia4b <- lm(Trustpol ~ Surveytype + gender + gender*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4b)

mTunisia4c <- lm(Trustpol ~ Surveytype + gender + age_short*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4c)

mTunisia4c2 <- lm(Trustpol ~ Surveytype2 + gender + age_short*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4c2)

mTunisia4d <- lm(Trustpol ~ Surveytype + gender + Educ*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4d)

mTunisia4d2 <- lm(Trustpol ~ Surveytype2 + gender + Educ*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4d2)

mTunisia4e <- lm(Trustpol ~ Surveytype + gender + singled*Surveytype + othermaritald*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4e)

mTunisia4e2 <- lm(Trustpol ~ Surveytype2 + gender + singled*Surveytype2 + othermaritald*Surveytype2 + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4e2)

mTunisia4f <- lm(Trustpol ~ Surveytype + gender + Empl*Surveytype + age_short + Educ + singled + othermaritald + Empl, data = Tunisia)
summary(mTunisia4f)


