Task 1: Use WB data to analyse something.

Here, I am using WB data to see the pattern of remittances over time and the bank account per 1000 adults over time for a group of countries that have the highest remittance inflows. The indicators that I use for this is:

rm(list = ls(all.names = TRUE))
library(wbstats)
library(ggplot2)
library(stargazer)
#wb_search('remittance') #wb_search('Bank Account')
# 7028      GFDD.AI.01  Bank accounts per 1,000 adults
# Using wb_data for getting wb data for specific countries. 
qn1 <- wb_data(country= c( "PHL", "China", "EGY"), indicator = c("GFDD.AI.01"), start_date = 2006, end_date = 2017)
#str(qn1)
ggplot(qn1)+geom_line(aes(x=date, y=GFDD.AI.01, color= country))+
ggtitle("Plot of Bank Accounts per 1000 Adults") +
  labs(y= "Bank Accounts Per 1000 Adults", x= "year") +scale_x_continuous(n.breaks=11)

The trend for the number of bank accounts is increasing for all countries. Philippines has the highest number of Bank Accounts per 1000 persons over time. Second is Egypt. China has the lowest number of Bank Accounts per 1000 adults.

Task 2

For this task, I am analyzing the interest in the word Naloxone over time in the US. Naloxone is a drug designed to reverse opiod overdose. There is moral hazard associated with easy access to Naloxone as shown by this paper. The authors find that moral hazard generated by Naloxone access is a problem, that results in increased opioid abuse and crime.

People may resort to using illegally produced fentanyl, if they are certain that they have Naloxone to save them in case of overdose. It would be interesting to see the search interests for these terms over time in US.

While we can see a relatively flat trend initially, there is an upward trend in interest from 2015/2016 onward. The upward trend in search interest for Naloxone definitely corresponds to the increasing expansion of Naloxone access by states.

library(gtrendsR)
library(reshape2)
googleData =gtrends(c("Naloxone", "opioid", "fentanyl"),geo=c("US"), gprop = "web",  time = "2010-01-01 2020-01-01"
                    )[[1]]
googleData =dcast(googleData, date~keyword+geo, value.var = "hits")
head(googleData)
##         date fentanyl_US Naloxone_US opioid_US
## 1 2010-01-01          16           2         5
## 2 2010-02-01          19           3         9
## 3 2010-03-01          14           3         9
## 4 2010-04-01          17           3         8
## 5 2010-05-01          15           3         7
## 6 2010-06-01          18           3         6
plot(googleData$date, googleData$fentanyl_US, type='l', col='blue', ylab = "Number of searches", xlab= "year", 
     main = "Searches for Opioid Related Terms Over Time")
lines(googleData$date, googleData$Naloxone_US, type='l', col='red')
lines(googleData$date, googleData$opioid_US, type='l', col='green')
legend("topright", legend =c("Fentanyl", "Naloxone", "Opioid"), col=c("blue", "red", "green"), lwd = 1, cex=0.8)

Let us see the graph for only Naloxone over time.

plot(googleData$date, googleData$Naloxone_US, type='l', col='blue', ylab = "Number of searches", xlab= "year", 
     main = "Searches for Naloxone Over Time")

Let us check for correlation between number of searches for search terms Naloxone and Fentanyl.

cor(googleData$fentanyl_US, googleData$Naloxone_US)
## [1] 0.8174179
ols_reg <-lm(fentanyl_US~Naloxone_US, googleData)
stargazer(ols_reg,
          title="OLS Fentanyl Naloxone",
          covariate.labels = "Naloxone",
          type="text",
          keep.stat=c("n", "rsq"), 
          column_labels=c("OLS"))
## 
## OLS Fentanyl Naloxone
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                      fentanyl_US        
## ----------------------------------------
## Naloxone              4.939***          
##                        (0.319)          
##                                         
## Constant               4.076*           
##                        (2.065)          
##                                         
## ----------------------------------------
## Observations             121            
## R2                      0.668           
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
## 
## OLS Fentanyl Naloxone
## ===
## OLS
## ---

It looks like there is a positive correlation between search frequencies Naloxone and Fentanyl. In general, positively correlated search interests for these terms could point to moral hazard and increase in risky behavior, meaning that people are searching ways to save themselves (in case of overdose) while also searching for the opioid Fentanyl.