data <- read.csv(file = "_data/merge_all.csv", header = TRUE, stringsAsFactors = FALSE)
quartile <- read.csv(file = "_data/isocode_region_quartile_2003_12.csv", header = TRUE, stringsAsFactors = FALSE)
data <- data %>%mutate(
tot=pl_x/pl_m,
ptpnt=.5*(pl_x+pl_m)/pl_da,
tb=(csh_x+csh_m),
open=(csh_x-csh_m),
ypc=rgdpo/pop
)
data <- data %>% select(isocode,year,ypc,tot,ptpnt,tb,open)
### Adding the quartile variable to the dataset
data$quartile <- 0
data$quartile[data$isocode %in% quartile$isocode[quartile$quartile==1]] <- 1
data$quartile[data$isocode %in% quartile$isocode[quartile$quartile==2]] <- 2
data$quartile[data$isocode %in% quartile$isocode[quartile$quartile==3]] <- 3
data$quartile[data$isocode %in% quartile$isocode[quartile$quartile==4]] <- 4
data1 <- data %>% select(-c(isocode)) %>% group_by(quartile,year) %>% summarise_each(funs(mean))
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once per session.
data1 <- data1 %>% rename("Terms of trade"="tot","Per-capita output"="ypc",
"Traded non-traded prices"="ptpnt","Openness"="open","Trade balance"="tb")
data1$quartile <- as.character(data1$quartile)
data1$year <- as.numeric(data1$year)
data1 <- as.data.frame(data1)
data1.m <- melt(data1,id=c("year","quartile"))
head(data1.m)
## year quartile variable value
## 1 1970 1 Per-capita output 26498.17
## 2 1971 1 Per-capita output 26846.53
## 3 1972 1 Per-capita output 26353.07
## 4 1973 1 Per-capita output 26483.21
## 5 1974 1 Per-capita output 26314.21
## 6 1975 1 Per-capita output 25884.44
ggplot(data1.m,aes(x=year,y=value,group=quartile,col=quartile)) + geom_point(alpha=0.2) + stat_smooth(geom="line") + theme_minimal() +
facet_wrap(~variable,scales="free_y") + theme(legend.position=c(0.9,0.1))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Per-capita output: the per-capita output of the top quartile has increased significantly, where as the rest has not changed that significantly.
Terms of trade: Terms of trades has decreased for the top quartile and increased largely for the other three quartiles. For the bottom quartile, it dropped in the 1970s before increasing over the rest of the period.
Price of traded and non-traded goods: The richer the country, the lower the ratio of price of traded and non-traded goods.
Trade-balance: Trade balance has increased for the top quartile and decreased for the other three quartiles.
Openness: Openness has increased for the top quartile and decreased for the rest three quartiles.