Time-dependent changes in economic data can be considered as time series. However, in order to make an economic analysis in detail, it is necessary to master the dynamics of the economy because these different types of data can affect each other directly or indirectly at different rates. This may not be always that easy to observe as the duration of action can also differ or there may be other current effects.
Nevertheless, in this analysis, some data provided by Central Bank of the Republic of Turkey will be handled and their relationship with each other will be examined based on basic economic knowledge.
First, it is necessary to decide on 3 data sets from 3 different categories that I think are related to each other. Dollar exchange rate data is the first one I chose because it has a great commercial impact on Turkey’s economy especially in these days. Later, when I evaluated consumers that could be greatly affected by the increase of dollar exchange rate, consumer confidence index came to my mind. So, the overall price index is also chosen as the second economic measure will most likely increase with the effect of the exchange rate.
In short, this report is to clarify whether the exchange rate of USD, the price index and the consumer confidence index are related to each other. The monthly based time series data for nearly 5 years is determined. It will be visualized and some correlation analysis will be made in the analysis section.
#install.packages('openxlsx')
#install.packages('ggplot2')
#install.packages('data.table')
#install.packages('skimr')
#install.packages('GGally')
#install.packages('ggcorrplot')
#install.packages(file.choose(),repos=NULL)
require(openxlsx)
library(openxlsx)
require(ggplot2)
require(data.table)
require(skimr)
require(GGally)
require(ggcorrplot)
#install.packages("readxl")
library(readxl)
data_path=file.choose()
invest=read_excel(data_path,sheet=1)
str(invest)
## tibble [59 × 5] (S3: tbl_df/tbl/data.frame)
## $ Date : POSIXct[1:59], format: "2017-05-01" "2017-06-01" ...
## $ Consumer.Confidence.Index: num [1:59] 94.2 92.7 93.2 93.5 92 ...
## $ USD.Exchange.Rate : num [1:59] 3.56 3.52 3.56 3.51 3.47 ...
## $ Price.Index : num [1:59] 311 310 310 312 314 ...
## $ year : num [1:59] 2017 2017 2017 2017 2017 ...
#install.packages("skimr")
library(skimr)
summary_data=skim(invest)
print(summary_data)
## ── Data Summary ────────────────────────
## Values
## Name invest
## Number of rows 59
## Number of columns 5
## _______________________
## Column type frequency:
## numeric 4
## POSIXct 1
## ________________________
## Group variables None
##
## ── Variable type: numeric ──────────────────────────────────────────────────────
## skim_variable n_missing complete_rate mean sd p0
## 1 Consumer.Confidence.Index 0 1 82.6 6.35 68.5
## 2 USD.Exchange.Rate 0 1 6.55 2.59 3.47
## 3 Price.Index 0 1 452. 119. 310.
## 4 year 0 1 2019. 1.47 2017
## p25 p50 p75 p100 hist
## 1 79.1 81.1 87.6 94.2 ▂▂▇▂▃
## 2 5.01 5.86 7.67 14.6 ▇▇▂▁▁
## 3 364. 436. 509. 844. ▇▆▃▁▁
## 4 2018 2019 2020. 2022 ▇▅▅▅▁
##
## ── Variable type: POSIXct ──────────────────────────────────────────────────────
## skim_variable n_missing complete_rate min max
## 1 Date 0 1 2017-05-01 00:00:00 2022-03-01 00:00:00
## median n_unique
## 1 2019-10-01 00:00:00 59
## $numeric
##
## ── Variable type: numeric ──────────────────────────────────────────────────────
## skim_variable n_missing complete_rate mean sd p0 p25 p50
## 1 Consumer.Confidenc… 0 1 8.26e1 6.35 6.85e1 7.91e1 8.11e1
## 2 USD.Exchange.Rate 0 1 6.55e0 2.59 3.47e0 5.01e0 5.86e0
## 3 Price.Index 0 1 4.52e2 119. 3.10e2 3.64e2 4.36e2
## 4 year 0 1 2.02e3 1.47 2.02e3 2.02e3 2.02e3
## # … with 3 more variables: p75 <dbl>, p100 <dbl>, hist <chr>
##
## $POSIXct
##
## ── Variable type: POSIXct ──────────────────────────────────────────────────────
## skim_variable n_missing complete_rate min max
## 1 Date 0 1 2017-05-01 00:00:00 2022-03-01 00:00:00
## # … with 2 more variables: median <dttm>, n_unique <int>
#install.packages("data.table")
library(data.table)
invest=data.table(invest)
str(invest)
## Classes 'data.table' and 'data.frame': 59 obs. of 5 variables:
## $ Date : POSIXct, format: "2017-05-01" "2017-06-01" ...
## $ Consumer.Confidence.Index: num 94.2 92.7 93.2 93.5 92 ...
## $ USD.Exchange.Rate : num 3.56 3.52 3.56 3.51 3.47 ...
## $ Price.Index : num 311 310 310 312 314 ...
## $ year : num 2017 2017 2017 2017 2017 ...
## - attr(*, ".internal.selfref")=<externalptr>
library(ggplot2)
Monthly time series data of about five years are plotted as follows:
ggplot(invest,aes(x=Date,y=USD.Exchange.Rate))+
geom_line(color="red")+
ggtitle("Time Series of Exchange Rate USD/TRY",
subtitle="Between the Years 2017-2022")
ggplot(invest,aes(x=Date,y=Price.Index))+
geom_line(color="purple")+
ggtitle("Time Series of Price Index",
subtitle="Between the Years 2017-2022")
ggplot(invest,aes(x=Date,y=Consumer.Confidence.Index))+
geom_line(color="green")+
ggtitle("Time Series of Consumer Confidence Index",
subtitle="Between the Years 2017-2022")
When looking at the changes of the measurements over time, the
followings can be understood visually:
Dollar exchange rate and price index are highly correlated and always tend to increase except for some breaks.
While small fluctuations in the exchange rate is more visible, the price index follows a smoother course. However, consumer confidence index has a more fluctuation which can be a result of that consumer confidence index is not only affected by price index & exchange rate. There are other parameters for CCI.
Even though CCI is not only related to these 2 parameters, exchange rate and price index caused a significant decrease trend for CCI between 2017 and 2022.
dist1<- invest%>%
ggplot(.,aes(x=USD.Exchange.Rate))+
geom_density(color="darkgrey",fill="red",adjust=1.5, alpha=.3) +
ggtitle("Distribution of Exchange Rate Values")
dist1
print(paste("Variance of Exchange Rate Values:", var(invest$USD.Exchange.Rate)))
## [1] "Variance of Exchange Rate Values: 6.69734068958407"
print(paste("Mean of Exchange Rate Values:",mean(invest$USD.Exchange.Rate)))
## [1] "Mean of Exchange Rate Values: 6.55441574853234"
The average value of the exchange rate is very close to the minimum value of 5 years of data. This can be attributed to the fact that the time interval for initial small values is wider and the increase in the ratio in recent years has been sharper. These reasons can also be supported by annual density plots
dist1<- invest%>%
ggplot(.,aes(x=Price.Index))+
geom_density(color="darkgrey",fill="purple",adjust=1.5, alpha=.3) +
ggtitle("Distribution of Price Index Values")
dist1
print(paste("Variance of Price Index Values:", var(invest$Price.Index)))
## [1] "Variance of Price Index Values: 14056.6722127411"
print(paste("Mean of Price Index Values:",mean(invest$Price.Index)))
## [1] "Mean of Price Index Values: 452.321016949153"
It can be seen that the shape of the first chart is almost the same as the first chart in the exchange rate, the only difference is the scale. Therefore, the same analysis can be made for the price index.
dist1<- invest%>%
ggplot(.,aes(x=Consumer.Confidence.Index))+
geom_density(color="darkgrey",fill="green",adjust=1.5, alpha=.3) +
ggtitle("Distribution of Consumer Confidence Index Values")
dist1
print(paste("Variance of Consumer Confidence Index Values:", var(invest$Consumer.Confidence.Index)))
## [1] "Variance of Consumer Confidence Index Values: 40.3072985625854"
print(paste("Mean of Consumer Confidence Index Values:",mean(invest$Consumer.Confidence.Index)))
## [1] "Mean of Consumer Confidence Index Values: 82.6262003826051"
The situation here is different from Price Index & Exchange Rate. While CCI is placing in middle values mostly, there is sharp increasing trend for other parameters. This is showing that CCI is also decreasing over time but as sharp as others and not as smooth as others.
In addition to visual inspection, when correlation values between the time series are calculated, it is seen that the relationship between the price index and the USD exchange rate is the highest as expected. When looking at other pairwise correlation values, even if such a high value is not obtained, a value that confirms that they have relationships is reached. Demonstration of the correlation values is as follows:
#install.packages("corrplot")
library(corrplot)
cor_numVar <- cor(invest[,c(2,3,4)], use="pairwise.complete.obs")
corrplot.mixed(cor_numVar, tl.col="black", tl.pos = "lt")
## Analysis with the Normalized Values
Comparison of change amounts may not be very convenient since the magnitude of the values is not similar. For this reason, if we normalize all the values, the comparison of the values that will be in the same scale can be done without any problem.
#install.packages("dplyr")
library(dplyr)
min1<-min(invest$USD.Exchange.Rate)
max1<-max(invest$USD.Exchange.Rate)
min2<-min(invest$Price.Index)
max2<-max(invest$Price.Index)
min3<-min(invest$Consumer.Confidence.Index)
max3<-max(invest$Consumer.Confidence.Index)
data<-invest%>% mutate(N_USD.Exchange.Rate=(USD.Exchange.Rate-min1)/(max1-min1),
N_Price.Index=(Price.Index-min2)/(max2-min2),
N_Consumer.Confidence.Index=(Consumer.Confidence.Index-min3)/(max3-min3))
#install.packages("ggplot2")
library(ggplot2)
#install.packages("tidyverse")
library(tidyverse)
data%>%pivot_longer(.,cols=c(N_USD.Exchange.Rate,N_Price.Index,N_Consumer.Confidence.Index),
names_to="name",
values_to="values")%>%
ggplot(.,aes(x=Date,y=values,color=name,shape=name))+
geom_line(size=1)+
labs(color="Normalized Economic Measures",
y="Normalized Values")+
scale_colour_discrete()+
ggtitle("Comparison of Time Series",
subtitle="With the Normalized Values")
The Consumer Confidence Index series fluctuates the most over time. The
fluctuations may be due to the re-determination of CCI against economic
changes and this process probably takes time.These fluctuations and the
rapid decline after 2021 may be the reason for the higher correlation
values initially calculated. Besides, these three time series follow
each other in general until 2021 and are similarly affected by the
changes.
#install.packages("ggridges")
library(ggridges)
norm1<-data%>%pivot_longer(.,cols=c(N_USD.Exchange.Rate,N_Price.Index,N_Consumer.Confidence.Index),
names_to="name",
values_to="values")%>%
ggplot(.,aes(x=values,y=factor(name),fill=factor(name)))+
geom_density_ridges() +
labs(color="Normalized Economic Measures",
y="Normalized Values")+
theme(legend.position = "none")+
ggtitle("Distribution of the Normalized Values")
norm1
print(paste("Variance of the Normalized Exchange Rate:",var(data$N_USD.Exchange.Rate)))
## [1] "Variance of the Normalized Exchange Rate: 0.0543810118863284"
print(paste("Variance of the Normalized Price Index:",var(data$N_Price.Index)))
## [1] "Variance of the Normalized Price Index: 0.0493205321017917"
print(paste("Variance of the Normalized Consumer Confidence Index:",var(data$N_Consumer.Confidence.Index)))
## [1] "Variance of the Normalized Consumer Confidence Index: 0.0609834742342922"
Since normalization does not affect the shape of the density plots, the visual analysis in the first part remains valid. Thanks to normalization, all three plots can be expressed on the same scale and variances can be compared more clearly. According to the results, although the variance values are very close, the smallest value is observed in the price index and the largest value in the consumer confidence index.
Since normalizing the values will not change the correlation values, the correlation value calculated on all data will not change. For this reason, this time we can calculate with another test method, Kendall.
res1 <- cor.test(data$N_USD.Exchange.Rate, data$N_Consumer.Confidence.Index, method="kendall")
res1
##
## Kendall's rank correlation tau
##
## data: data$N_USD.Exchange.Rate and data$N_Consumer.Confidence.Index
## z = -5.5913, p-value = 2.254e-08
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau
## -0.4997078
res2 <- cor.test(data$N_USD.Exchange.Rate, data$N_Price.Index, method="kendall")
res2
##
## Kendall's rank correlation tau
##
## data: data$N_USD.Exchange.Rate and data$N_Price.Index
## z = 9.9596, p-value < 2.2e-16
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau
## 0.8901227
res3 <- cor.test(data$N_Price.Index, data$N_Consumer.Confidence.Index, method="kendall")
res3
##
## Kendall's rank correlation tau
##
## data: data$N_Price.Index and data$N_Consumer.Confidence.Index
## z = -5.6697, p-value = 1.43e-08
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau
## -0.5067212
When looking at the pairwise results obtained here, it is seen that the correlation values are almost the same with the values calculated before. Since the p-values of the tests are quite small, these tests can be trusted.
library(dplyr)
library(tidyverse)
library(lubridate)
d<-data%>%group_by(year(Date))%>%
mutate(ExchangeRateUSD_PriceIndex=cor(N_USD.Exchange.Rate,N_Price.Index),
ExchangeRateUSD_ConsumerConfidenceIndex=cor(N_USD.Exchange.Rate,N_Consumer.Confidence.Index),
PriceIndex_ConsumerConfidenceIndex=cor(N_Price.Index,N_Consumer.Confidence.Index))
d%>%
pivot_longer(.,cols=c(ExchangeRateUSD_PriceIndex,ExchangeRateUSD_ConsumerConfidenceIndex,PriceIndex_ConsumerConfidenceIndex))%>%
ggplot(., aes(x=year(Date), y=value)) +
geom_line( aes(color=name)) +
geom_point(aes( fill=name),shape=21, color="black", size=6) +
labs(fill="Between:",color="Between:",
y="Correlation",
x="Year")+
facet_wrap(~name)+
ggtitle("Pairwise Yearly Correlations")+
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1),
strip.text.x = element_blank())+
scale_fill_discrete(labels=c("ExchangeRate-Price Index","ExchangeRate-CCI","PriceIndex-CCI"))+
scale_color_discrete(labels=c("ExchangeRate-Price Index","ExchangeRate-CCI","PriceIndex-CCI"))
d%>%mutate(avg_corr=sum(ExchangeRateUSD_PriceIndex,
ExchangeRateUSD_ConsumerConfidenceIndex,
PriceIndex_ConsumerConfidenceIndex)/(3*length(year(Date))))%>%
ggplot(., aes(x=year(Date), y=avg_corr)) +
geom_line( color="grey") +
geom_point(shape=21, color="black", fill="#69b3a2", size=6) +
labs(y="Correlation",
x="Year")+
ggtitle("Average of the Pairwise Correlations",
subtitle="Yearly")
Correlation values are recalculated annually so that deviations in some
years do not affect the total correlation. In order to be able to say
that the three are related to each other at the same time, it is
necessary to look at all the pairwise correlation values separately.
These years which are 2019, 2020 and 2022 can be seen more clearly from
the second chart.
Firstly, the change and distribution of the selected economic data over time are examined, then similar charts are also plotted with the normalized data. Although the relationship between these three measures, whose monthly data is examined throughout the analysis, is very clear in economic manner, the relationships may change from time to time due to other real-life dynamics. By visualizing the time series, the findings can be summarized as follows: