TourismDeforestationSubmission / 00_DataframeCompilation.Rmd
00_DataframeCompilation.Rmd
Raw
---
title: "02_DataframeCompilation"
author: "Camille"
date: "3/1/2023"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

#replaced ~/Documents with ~/Documents
#replaced dplyr::select with dplyr::select
```

```{r Load Packages and Data}
library(tidyverse)
library(lubridate)

#read confounder data
precipitation <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CleanedConfounders/precipitation2.csv")
commune_precipitation <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CleanedConfounders/precipitation_commune.csv")
PopDensity <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CleanedConfounders/PopDensity.csv")
PopDensityCommune <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CleanedConfounders/PopDensityCommune.csv")
funding <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CleanedConfounders/Funding.csv")
forest <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CommuneForestCover/deforestation_full.csv")
forest_commune <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CommuneForestCover/deforestation_commune.csv")
tourism <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/tourism.csv")
tourism <- tourism %>% filter(Name !="Foret d'Ambre")
forest_funding <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CommuneForestCover/deforestation_full_funding.csv")
forest_commune_funding <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/CommuneForestCover/deforestation_commune_funding.csv")

aggregate_dat <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/aggregate_dat.csv")

```

```{r Compile all variables}
#FULL ANALYSIS
confounders_full <- full_join(precipitation, PopDensity, by=c("Year", "Name"))
confounders_full <- left_join(confounders_full, funding, by=c("Year", "Name"))
deforestation_full <- full_join(confounders_full, forest, by=c("Year", "Name"))
deforestation_full2 <- full_join(deforestation_full, tourism , by=c("Year", "Name"))
deforestation_full2$funding_by_area <- deforestation_full2$funding/ deforestation_full2$area
deforestation_full3 <- deforestation_full2 %>% dplyr::select(Name, PercentDeforest, Tourism, Year, precipitation, PopDensity, funding, funding_by_area, area)
deforestation_full4 <- deforestation_full3 %>% filter(Name !="Sahamalaza", Name!="Mikea")
tsaratanana_dat <- deforestation_full3 %>% filter(Name =="Tsaratanana")
aggregate_dat <- aggregate_dat %>% filter(Name !="Sahamalaza", Name!="Mikea")


#COMMUNE ANALYSIS
confounders_commune <- full_join(commune_precipitation, PopDensityCommune, by=c("Year", "Name"))
confounders_commune <- left_join(confounders_commune, funding, by=c("Year", "Name"))
deforestation_commune <- full_join(confounders_commune, forest_commune, by=c("Year", "Name"))
deforestation_commune2 <- full_join(deforestation_commune, tourism , by=c("Year", "Name"))
deforestation_commune2$funding_by_area <- deforestation_commune2$funding / deforestation_commune2$area
deforestation_commune3 <- deforestation_commune2 %>% dplyr::select(Name, PercentDeforest, Tourism, Year, precipitation, PopDensityCommune, funding, funding_by_area, area)


deforestation_commune4 <- deforestation_commune3 %>% filter(Name !="Tsaratanana")

deforestation_commune5 <- deforestation_commune4 

deforestation_commune5$precipitation[deforestation_commune5$Name=="Andranomena"] <- deforestation_full4$precipitation[deforestation_full4$Name=="Andranomena"]

deforestation_commune5$precipitation[deforestation_commune5$Name=="Andringitra"] <- deforestation_full4$precipitation[deforestation_full4$Name=="Andringitra"]

deforestation_commune5$precipitation[deforestation_commune5$Name=="Pic d'Ivohibe"] <- deforestation_full4$precipitation[deforestation_full4$Name=="Pic d'Ivohibe"]

deforestation_commune5 <- deforestation_commune5%>% filter(Name !="Sahamalaza", Name!="Mikea")
tsaratanana_dat_commune <- deforestation_full3 %>% filter(Name =="Tsaratanana") %>% rename(PopDensityCommune = PopDensity)
deforestation_commune5 <- rbind(deforestation_commune5, tsaratanana_dat_commune)


```

```{r Add oil prices}
oil_dat <- read.csv("~/Documents/GitHub/TourismDeforestation/Data/oil_prices2.csv")
oil_dat$DATE <- as.Date(oil_dat$DATE)
oil_dat$DCOILBRENTEU <- as.numeric(oil_dat$DCOILBRENTEU)
oil_dat2 <- oil_dat %>% rename(Date=DATE, OilPrice = DCOILBRENTEU) %>% mutate(Year = year(Date)) %>%drop_na(OilPrice)%>% group_by(Year) %>% summarise(OilPrice =mean(OilPrice)) %>% filter(Year >=1991)

oil_dat_2000 <- mean(oil_dat2$OilPrice[oil_dat2$Year<2001] )
oil_dat_2010 <- mean(oil_dat2$OilPrice[oil_dat2$Year>1999&oil_dat2$Year<2011] )
oil_dat_2020 <- mean(oil_dat2$OilPrice[oil_dat2$Year>2009] )

deforestation_full4 <- left_join(deforestation_full4, oil_dat2, by="Year")
deforestation_commune5 <- left_join(deforestation_commune5, oil_dat2, by="Year")
aggregate_dat <- left_join(aggregate_dat , oil_dat2, by="Year")

```

```{r Add in region information for each park}
#full dataset
deforestation_full4$Regions <- deforestation_full4$Name
deforestation_full4$Regions[deforestation_full4$Regions=="Ambatovaky"] <- "Analanjorofo"
deforestation_full4$Regions[deforestation_full4$Regions=="Ambohijanahary"] <- "Alaotra Mangoro"
deforestation_full4$Regions[deforestation_full4$Regions=="Ambohitantely"] <- "Analamanga"
deforestation_full4$Regions[deforestation_full4$Regions=="Analamerana"] <- "Diana"
deforestation_full4$Regions[deforestation_full4$Regions=="Andasibe/Analamazaotra"] <- "Alaotra Mangoro"
deforestation_full4$Regions[deforestation_full4$Regions=="Andohahela"] <- "Anosy"
deforestation_full4$Regions[deforestation_full4$Regions=="Andranomena"] <- "Sava"
deforestation_full4$Regions[deforestation_full4$Regions=="Andringitra"] <- "Haute Matsiatra"
deforestation_full4$Regions[deforestation_full4$Regions=="Anjanaharibe-Sud"] <- 
deforestation_full4$Regions[deforestation_full4$Regions=="Ankarafantsika"] <- "Boeny"
deforestation_full4$Regions[deforestation_full4$Regions=="Ankarana"] <- "Sava"
deforestation_full4$Regions[deforestation_full4$Regions=="Bemaraha (combined)"] <- "Melaky" 
deforestation_full4$Regions[deforestation_full4$Regions=="Bemarivo"] <- "Melaky" 
deforestation_full4$Regions[deforestation_full4$Regions=="Betampona"] <- "Atsinanana"
deforestation_full4$Regions[deforestation_full4$Regions=="Bezaha Mahafaly"] <- "Atsimo Andrefana"
deforestation_full4$Regions[deforestation_full4$Regions=="Bora"] <- "Sofia"
deforestation_full4$Regions[deforestation_full4$Regions=="Cap Sainte Marie"] <- "Androy"
deforestation_full4$Regions[deforestation_full4$Regions=="Foret d'Ambre"] <- "Diana"
deforestation_full4$Regions[deforestation_full4$Regions=="Isalo"] <- "Ihorombe"
deforestation_full4$Regions[deforestation_full4$Regions=="Kalambatritra"] <- "Anosy"
deforestation_full4$Regions[deforestation_full4$Regions=="Kasijy"] <- "Betsiboka"
deforestation_full4$Regions[deforestation_full4$Regions=="Kirindy Mitea"] <- "Menabe"
deforestation_full4$Regions[deforestation_full4$Regions=="Lokobe"] <- "Diana"
deforestation_full4$Regions[deforestation_full4$Regions=="Mananara-Nord"] <- "Analanjorofo"
deforestation_full4$Regions[deforestation_full4$Regions=="Mangerivola"] <- "Atsinanana"
deforestation_full4$Regions[deforestation_full4$Regions=="Maningoza"] <- "Melaky"
deforestation_full4$Regions[deforestation_full4$Regions=="Manombo"] <- "Atsimo Atsinanana"
deforestation_full4$Regions[deforestation_full4$Regions=="Manongarivo"] <- "Diana"
deforestation_full4$Regions[deforestation_full4$Regions=="Marojejy"] <- "Sava"
deforestation_full4$Regions[deforestation_full4$Regions=="Marotandrano"] <- "Sofia"
deforestation_full4$Regions[deforestation_full4$Regions=="Masoala"] <- "Sava"
deforestation_full4$Regions[deforestation_full4$Regions=="Midongy du Sud"] <- "Atsimo Atsinanana"
deforestation_full4$Regions[deforestation_full4$Regions=="Pic d'Ivohibe"] <- "Ihorombe"
deforestation_full4$Regions[deforestation_full4$Regions=="Ranomafana"] <- "Haute Matsiatra" #in two regions.. went with the one that has another park prepresented
deforestation_full4$Regions[deforestation_full4$Regions=="Tampoketsa Analamaitso"] <- "Sofia"
deforestation_full4$Regions[deforestation_full4$Regions=="Tsaratanana"] <- "Betsiboka"
deforestation_full4$Regions[deforestation_full4$Regions=="Tsimanampesotse"] <- "Atsimo Andrefana"
deforestation_full4$Regions[deforestation_full4$Regions=="Zahamena"] <- "Alaotra Mangoro"
deforestation_full4$Regions[deforestation_full4$Regions=="Zombitse/Vohibasia"] <- "Atsimo Andrefana"
deforestation_full4$Regions[deforestation_full4$Regions=="Namoroka/Baie de Baly"] <- "Boeny"
deforestation_full4$Regions[deforestation_full4$Regions=="Montagne d'Ambre"] <- "Diana"



#deflation data
deforestation_full4$Deflation <- deforestation_full4$Regions
deforestation_full4$Deflation[deforestation_full4$Deflation=="Analanjorofo"] <- 0.81834
deforestation_full4$Deflation[deforestation_full4$Deflation=="Alaotra Mangoro"] <- 0.844633
deforestation_full4$Deflation[deforestation_full4$Deflation=="Analamanga"] <- 1
deforestation_full4$Deflation[deforestation_full4$Deflation=="Diana"] <- 0.706547
deforestation_full4$Deflation[deforestation_full4$Deflation=="Anosy"] <- 0.856932
deforestation_full4$Deflation[deforestation_full4$Deflation=="Sava"] <- 0.814796
deforestation_full4$Deflation[deforestation_full4$Deflation=="Haute Matsiatra"] <-0.947125
deforestation_full4$Deflation[deforestation_full4$Deflation=="Boeny"] <- 1.007638
deforestation_full4$Deflation[deforestation_full4$Deflation=="Melaky"] <- 0.884184
deforestation_full4$Deflation[deforestation_full4$Deflation=="Atsinanana"] <- 0.973824
deforestation_full4$Deflation[deforestation_full4$Deflation=="Atsimo Andrefana"] <- 0.789781
deforestation_full4$Deflation[deforestation_full4$Deflation=="Sofia"] <- 0.722568
deforestation_full4$Deflation[deforestation_full4$Deflation=="Androy"] <- 0.805615
deforestation_full4$Deflation[deforestation_full4$Deflation=="Ihorombe"] <-0.711432 
deforestation_full4$Deflation[deforestation_full4$Deflation=="Betsiboka"] <-0.747884
deforestation_full4$Deflation[deforestation_full4$Deflation=="Menabe"] <- 0.626845
deforestation_full4$Deflation[deforestation_full4$Deflation=="Atsimo Atsinanana"] <- 0.700499
deforestation_full4$Deflation[deforestation_full4$Deflation=="Boeny"] <- 1.007638

deforestation_full4$Deflation <- as.numeric(deforestation_full4$Deflation)
deforestation_full4$OilPriceAdj <- deforestation_full4$OilPrice* deforestation_full4$Deflation

write.csv(deforestation_full4, "~/Documents/GitHub/TourismDeforestation/Data/MasterSheet_full.csv")


# funding analysis
deforestation_full4_funding <- deforestation_full4 %>% dplyr::select(Name, Tourism:OilPriceAdj) %>% filter(Year<2013, Year>2004)
deforestation_full4_funding2 <- left_join(deforestation_full4_funding, forest_funding, by=c("Name", "Year"))

write.csv(deforestation_full4_funding2, "~/Documents/GitHub/TourismDeforestation/Data/MasterSheet_full_funding.csv")



```

```{r Add in region information for each park--commune}
#commune 

deforestation_commune5$Regions <- deforestation_commune5$Name
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ambatovaky"] <- "Analanjorofo"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ambohijanahary"] <- "Alaotra Mangoro"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ambohitantely"] <- "Analamanga"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Analamerana"] <- "Diana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Andasibe/Analamazaotra"] <- "Alaotra Mangoro"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Andohahela"] <- "Anosy"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Andranomena"] <- "Sava"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Andringitra"] <- "Haute Matsiatra"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Anjanaharibe-Sud"] <- 
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ankarafantsika"] <- "Boeny"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ankarana"] <- "Sava"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Bemaraha (combined)"] <- "Melaky" 
deforestation_commune5$Regions[deforestation_commune5$Regions=="Bemarivo"] <- "Melaky" 
deforestation_commune5$Regions[deforestation_commune5$Regions=="Betampona"] <- "Atsinanana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Bezaha Mahafaly"] <- "Atsimo Andrefana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Bora"] <- "Sofia"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Cap Sainte Marie"] <- "Androy"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Foret d'Ambre"] <- "Diana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Isalo"] <- "Ihorombe"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Kalambatritra"] <- "Anosy"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Kasijy"] <- "Betsiboka"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Kirindy Mitea"] <- "Menabe"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Lokobe"] <- "Diana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Mananara-Nord"] <- "Analanjorofo"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Mangerivola"] <- "Atsinanana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Maningoza"] <- "Melaky"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Manombo"] <- "Atsimo Atsinanana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Manongarivo"] <- "Diana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Marojejy"] <- "Sava"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Marotandrano"] <- "Sofia"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Masoala"] <- "Sava"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Midongy du Sud"] <- "Atsimo Atsinanana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Pic d'Ivohibe"] <- "Ihorombe"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Ranomafana"] <- "Haute Matsiatra" #in two regions.. went with the one that has another park prepresented
deforestation_commune5$Regions[deforestation_commune5$Regions=="Tampoketsa Analamaitso"] <- "Sofia"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Tsaratanana"] <- "Betsiboka"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Tsimanampesotse"] <- "Atsimo Andrefana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Zahamena"] <- "Alaotra Mangoro"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Zombitse/Vohibasia"] <- "Atsimo Andrefana"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Namoroka/Baie de Baly"] <- "Boeny"
deforestation_commune5$Regions[deforestation_commune5$Regions=="Montagne d'Ambre"] <- "Diana"



#deflation data
deforestation_commune5$Deflation <- deforestation_commune5$Regions
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Analanjorofo"] <- 0.81834
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Alaotra Mangoro"] <- 0.844633
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Analamanga"] <- 1
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Diana"] <- 0.706547
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Anosy"] <- 0.856932
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Sava"] <- 0.814796
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Haute Matsiatra"] <-0.947125
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Boeny"] <- 1.007638
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Melaky"] <- 0.884184
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Atsinanana"] <- 0.973824
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Atsimo Andrefana"] <- 0.789781
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Sofia"] <- 0.722568
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Androy"] <- 0.805615
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Ihorombe"] <-0.711432 
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Betsiboka"] <-0.747884
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Menabe"] <- 0.626845
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Atsimo Atsinanana"] <- 0.700499
deforestation_commune5$Deflation[deforestation_commune5$Deflation=="Boeny"] <- 1.007638

deforestation_commune5 <- deforestation_commune5 %>% filter(Year >1999)

deforestation_commune5$Deflation <- as.numeric(deforestation_commune5$Deflation)
deforestation_commune5$OilPriceAdj <- deforestation_commune5$OilPrice* deforestation_commune5$Deflation

write.csv(deforestation_commune5, "~/Documents/GitHub/TourismDeforestation/Data/MasterSheet_commune.csv")


# funding analysis
deforestation_commune5_funding <- deforestation_commune5 %>% dplyr::select(Name, Tourism:OilPriceAdj) %>% filter(Year<2013, Year>2004)
deforestation_commune5_funding2 <- left_join(deforestation_commune5_funding, forest_funding, by=c("Name", "Year"))

write.csv(deforestation_commune5_funding2, "~/Documents/GitHub/TourismDeforestation/Data/MasterSheet_commune_funding.csv")
```

```{r Add in region information for each park--aggregate}
#aggregate
aggregate_dat$Regions <- aggregate_dat$Name
aggregate_dat$Regions[aggregate_dat$Regions=="Ambatovaky"] <- "Analanjorofo"
aggregate_dat$Regions[aggregate_dat$Regions=="Ambohijanahary"] <- "Alaotra Mangoro"
aggregate_dat$Regions[aggregate_dat$Regions=="Ambohitantely"] <- "Analamanga"
aggregate_dat$Regions[aggregate_dat$Regions=="Analamerana"] <- "Diana"
aggregate_dat$Regions[aggregate_dat$Regions=="Andasibe/Analamazaotra"] <- "Alaotra Mangoro"
aggregate_dat$Regions[aggregate_dat$Regions=="Andohahela"] <- "Anosy"
aggregate_dat$Regions[aggregate_dat$Regions=="Andranomena"] <- "Sava"
aggregate_dat$Regions[aggregate_dat$Regions=="Andringitra"] <- "Haute Matsiatra"
aggregate_dat$Regions[aggregate_dat$Regions=="Anjanaharibe-Sud"] <- 
aggregate_dat$Regions[aggregate_dat$Regions=="Ankarafantsika"] <- "Boeny"
aggregate_dat$Regions[aggregate_dat$Regions=="Ankarana"] <- "Sava"
aggregate_dat$Regions[aggregate_dat$Regions=="Bemaraha (combined)"] <- "Melaky" 
aggregate_dat$Regions[aggregate_dat$Regions=="Bemarivo"] <- "Melaky" 
aggregate_dat$Regions[aggregate_dat$Regions=="Betampona"] <- "Atsinanana"
aggregate_dat$Regions[aggregate_dat$Regions=="Bezaha Mahafaly"] <- "Atsimo Andrefana"
aggregate_dat$Regions[aggregate_dat$Regions=="Bora"] <- "Sofia"
aggregate_dat$Regions[aggregate_dat$Regions=="Cap Sainte Marie"] <- "Androy"
aggregate_dat$Regions[aggregate_dat$Regions=="Foret d'Ambre"] <- "Diana"
aggregate_dat$Regions[aggregate_dat$Regions=="Isalo"] <- "Ihorombe"
aggregate_dat$Regions[aggregate_dat$Regions=="Kalambatritra"] <- "Anosy"
aggregate_dat$Regions[aggregate_dat$Regions=="Kasijy"] <- "Betsiboka"
aggregate_dat$Regions[aggregate_dat$Regions=="Kirindy Mitea"] <- "Menabe"
aggregate_dat$Regions[aggregate_dat$Regions=="Lokobe"] <- "Diana"
aggregate_dat$Regions[aggregate_dat$Regions=="Mananara-Nord"] <- "Analanjorofo"
aggregate_dat$Regions[aggregate_dat$Regions=="Mangerivola"] <- "Atsinanana"
aggregate_dat$Regions[aggregate_dat$Regions=="Maningoza"] <- "Melaky"
aggregate_dat$Regions[aggregate_dat$Regions=="Manombo"] <- "Atsimo Atsinanana"
aggregate_dat$Regions[aggregate_dat$Regions=="Manongarivo"] <- "Diana"
aggregate_dat$Regions[aggregate_dat$Regions=="Marojejy"] <- "Sava"
aggregate_dat$Regions[aggregate_dat$Regions=="Marotandrano"] <- "Sofia"
aggregate_dat$Regions[aggregate_dat$Regions=="Masoala"] <- "Sava"
aggregate_dat$Regions[aggregate_dat$Regions=="Midongy du Sud"] <- "Atsimo Atsinanana"
aggregate_dat$Regions[aggregate_dat$Regions=="Pic d'Ivohibe"] <- "Ihorombe"
aggregate_dat$Regions[aggregate_dat$Regions=="Ranomafana"] <- "Haute Matsiatra" #in two regions.. went with the one that has another park prepresented
aggregate_dat$Regions[aggregate_dat$Regions=="Tampoketsa Analamaitso"] <- "Sofia"
aggregate_dat$Regions[aggregate_dat$Regions=="Tsaratanana"] <- "Betsiboka"
aggregate_dat$Regions[aggregate_dat$Regions=="Tsimanampesotse"] <- "Atsimo Andrefana"
aggregate_dat$Regions[aggregate_dat$Regions=="Zahamena"] <- "Alaotra Mangoro"
aggregate_dat$Regions[aggregate_dat$Regions=="Zombitse/Vohibasia"] <- "Atsimo Andrefana"
aggregate_dat$Regions[aggregate_dat$Regions=="Namoroka/Baie de Baly"] <- "Boeny"
aggregate_dat$Regions[aggregate_dat$Regions=="Montagne d'Ambre"] <- "Diana"

aggregate_dat$Deflation <- aggregate_dat$Regions
aggregate_dat$Deflation[aggregate_dat$Deflation=="Analanjorofo"] <- 0.81834
aggregate_dat$Deflation[aggregate_dat$Deflation=="Alaotra Mangoro"] <- 0.844633
aggregate_dat$Deflation[aggregate_dat$Deflation=="Analamanga"] <- 1
aggregate_dat$Deflation[aggregate_dat$Deflation=="Diana"] <- 0.706547
aggregate_dat$Deflation[aggregate_dat$Deflation=="Anosy"] <- 0.856932
aggregate_dat$Deflation[aggregate_dat$Deflation=="Sava"] <- 0.814796
aggregate_dat$Deflation[aggregate_dat$Deflation=="Haute Matsiatra"] <-0.947125
aggregate_dat$Deflation[aggregate_dat$Deflation=="Boeny"] <- 1.007638
aggregate_dat$Deflation[aggregate_dat$Deflation=="Melaky"] <- 0.884184
aggregate_dat$Deflation[aggregate_dat$Deflation=="Atsinanana"] <- 0.973824
aggregate_dat$Deflation[aggregate_dat$Deflation=="Atsimo Andrefana"] <- 0.789781
aggregate_dat$Deflation[aggregate_dat$Deflation=="Sofia"] <- 0.722568
aggregate_dat$Deflation[aggregate_dat$Deflation=="Androy"] <- 0.805615
aggregate_dat$Deflation[aggregate_dat$Deflation=="Ihorombe"] <-0.711432 
aggregate_dat$Deflation[aggregate_dat$Deflation=="Betsiboka"] <-0.747884
aggregate_dat$Deflation[aggregate_dat$Deflation=="Menabe"] <- 0.626845
aggregate_dat$Deflation[aggregate_dat$Deflation=="Atsimo Atsinanana"] <- 0.700499
aggregate_dat$Deflation[aggregate_dat$Deflation=="Boeny"] <- 1.007638

aggregate_dat$Deflation <- as.numeric(aggregate_dat$Deflation)
aggregate_dat$OilPriceAdj <- aggregate_dat$OilPrice*aggregate_dat$Deflation

write.csv(aggregate_dat, "~/Documents/GitHub/TourismDeforestation/Data/aggregate_master.csv")

```