# Setup
#setwd("/Volumes/GoogleDrive/My Drive/Green Patents/green_patents")
setwd("C:/Users/James/My Drive/Green Patents/green_patents")
library(pacman)
## Warning: package 'pacman' was built under R version 4.2.2
p_load(dplyr, ggplot2, glue, countrycode)

data <- read.csv2("data/WV5_Data_csv_v20180912.csv")

data$COW <- countrycode(data$COW, origin = 'cown', destination = 'iso3c')
## Warning in countrycode_convert(sourcevar = sourcevar, origin = origin, destination = dest, : Some values were not matched unambiguously: 345, 714
# won't include 345: Yugoslavia, 714: ?
# V29 Membership in environmental organization:
#   2: Active member
#   1: Inactive member
#   0: Don't belong

datnm <- "member"

member <- data %>% 
  select(COW, V29) %>% 
  group_by(COW, V29) %>% 
  filter(V29 > -1) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
member
# V88 How similar the individual is to a person who values looking after the environment, care for nature:
# 1: Very much like me
# 2: Like me
# 3: Somewhat like me
# 4: A little like me
# 5: Not like me
# 6: Not at all like me

env_person <- data %>% 
  select(COW, V88) %>% 
  group_by(COW, V88) %>% 
  filter(V88 > -1) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
env_person
# V104 Prioritize economic growth vs. environmental protection:
# 1: Protecting environment prioritized over economic growth and jobs
# 2: Economic growth and jobs prioritized over environment
# 3: Other

growth <- data %>% 
  select(COW, V104) %>% 
  group_by(COW, V104) %>% 
  filter(V104 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
growth
# V105 Would give part of income to prevent environmental pollution. 
#   1: Strongly Agree
#   2: Agree
#   3: Disagree
#   4: Strongly Disagree

income <- data %>% 
  select(COW, V105) %>% 
  group_by(COW, V105) %>% 
  filter(V105 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
income
# V106 Would pay higher taxes to prevent environmental pollution. 
#   1: Strongly Agree
#   2: Agree
#   3: Disagree
#   4: Strongly Disagree

taxes <- data %>% 
  select(COW, V106) %>% 
  group_by(COW, V106) %>% 
  filter(V106 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
taxes
# V107 The government should reduce environmental pollution at no extra cost to the respondent.
#   1: Strongly Agree
#   2: Agree
#   3: Disagree
#   4: Strongly Disagree

nocost <- data %>% 
  select(COW, V107) %>% 
  group_by(COW, V107) %>% 
  filter(V107 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
nocost
# V108 Poor water quality is a problem in respondent's own community.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

water <- data %>%
  select(COW, V108) %>%
  group_by(COW, V108) %>%
  filter(V108 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
water
# V109 Poor air quality is a problem in respondent's own community.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

air <- data %>%
  select(COW, V109) %>%
  group_by(COW, V109) %>%
  filter(V109 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
air
# V110 Poor sanitation and sewage is a problem in respondent's own community.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

sani <- data %>%
  select(COW, V110) %>%
  group_by(COW, V110) %>%
  filter(V110 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
sani
# V111 Global warming is a serious problem facing the whole world.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

warm <- data %>%
  select(COW, V111) %>%
  group_by(COW, V111) %>%
  filter(V111 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
warm
# V112 Loss of biodiversity is a serious problem facing the whole world.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

biod <- data %>%
  select(COW, V112) %>%
  group_by(COW, V112) %>%
  filter(V112 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
biod
# V113 Pollution of waterways is a serious problem facing the whole world.
# 1: Very serious
# 2: Somewhat serious
# 3: Not very serious
# 4: Not serious at all

pollute <- data %>%
  select(COW, V113) %>%
  group_by(COW, V113) %>%
  filter(V113 > 0) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
pollute
# V143 how confident the respondent has in environmental organizations.
# 1. A great deal
# 2. Quite a lot
# 3. Not very much
# 4. None at all

confident <- data %>% 
  select(COW, V143) %>% 
  group_by(COW, V143) %>% 
  filter(V143 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
confident
# V166 Five options for the most serious issue facing the whole world
# 1. People living in poverty and need
# 2. Discrimination against girls and women
# 3. Poor sanitation and infectious diseases
# 4. Inadequate education
# 5: Environmental pollution

ser_wld <- data %>% 
  select(COW, V166) %>% 
  group_by(COW, V166) %>% 
  filter(V166 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
ser_wld
# V167 Five options for the second most serious issue facing the whole world
# 1. People living in poverty and need
# 2. Discrimination against girls and women
# 3. Poor sanitation and infectious diseases
# 4. Inadequate education
# 5: Environmental pollution

ser_wld2 <- data %>% 
  select(COW, V167) %>% 
  group_by(COW, V167) %>% 
  filter(V167 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
ser_wld2
# V168 Five options for the most serious issue facing the respondent's country.
# 1. People living in poverty and need
# 2. Discrimination against girls and women
# 3. Poor sanitation and infectious diseases
# 4. Inadequate education
# 5: Environmental pollution

ser_loc <- data %>% 
  select(COW, V168) %>% 
  group_by(COW, V168) %>% 
  filter(V168 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
ser_loc
# V169 Five options for the second most serious issue facing the  respondent's country.
# 1. People living in poverty and need
# 2. Discrimination against girls and women
# 3. Poor sanitation and infectious diseases
# 4. Inadequate education
# 5: Environmental pollution

ser_loc2 <- data %>% 
  select(COW, V169) %>% 
  group_by(COW, V169) %>% 
  filter(V169 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
ser_loc2
# V180 Which organization is best suited to protect the environment?
# 1. National Governments
# 2. Regional Organizations
# 3. United Nations

pro_org <- data %>% 
  select(COW, V180) %>% 
  group_by(COW, V180) %>% 
  filter(V180 > 0) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n))
## `summarise()` has grouped output by 'COW'. You can override using the `.groups`
## argument.
pro_org