A Correlation between Economic Variables and a Prediction for the Future

Throughout this project I will be analyzing the correlation between different economic variables with one another, as well as making a prediction for the future.

As an economics major at Elon, I took this class because I wanted to pair something in the communications department that I thought would compliment my work in economics. I was excited for this final project, as I am deciding to go out of the box by exploring economic indicators to see if I can visualize different concepts I have learned in my economics class.

First, I am going to load my packages.

library(tidyverse)
library(ggthemes)

Now, I am going to load my first dataset.

library(readxl)
data <- read_excel("~/Desktop/final project /ConsumptionAndProductivity (2).xlsx")
View(data)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1
data
## # A tibble: 205 × 9
##    CC              FCE Population lnCons…¹ Count…² Region Incom…³  GDPPC lnGDPPC
##    <chr>         <dbl>      <dbl>    <dbl> <chr>   <chr>  <chr>    <dbl>   <dbl>
##  1 AFG     18746901733   36296400     2.71 Afghan… South… Low in…   521.    2.72
##  2 AGO     85631168587   29816748     3.46 Angola  Sub-S… Lower …  3432.    3.54
##  3 ALB     11879922787    2873457     3.62 Albania Europ… Upper …  5269.    3.72
##  4 ARB   1850000000000  411898965     3.65 Arab W… <NA>   <NA>     6609.    3.82
##  5 ARE    192000000000    9487203     4.31 United… Middl… High i… 43005.    4.63
##  6 ARG    540000000000   44044811     4.09 Argent… Latin… Upper … 11684.    4.07
##  7 ARM     10645440263    2944809     3.56 Armenia Europ… Upper …  4212.    3.62
##  8 AUS   1000000000000   24601860     4.61 Austra… East … High i… 57374.    4.76
##  9 AUT    299000000000    8797566     4.53 Austria Europ… High i… 51462.    4.71
## 10 AZE     28167731815    9854033     3.46 Azerba… Europ… Upper …  4721.    3.67
## # … with 195 more rows, and abbreviated variable names ¹​lnConsumption,
## #   ²​`Country Name`, ³​IncomeGroup

This data was retrieved from the World Data Bank, and is a compilation of all Countries, their population, reigion, income group, GDPPC, lnGDPPC, and consumption.

Consumption is the amount of goods and services a household uses, while GDP is gross domestic product, which is a measure of all goods and services produced in an economy. I am going to use the natural log (ln) because it measures growth rate which is more significant for comparison of variables.

I am going to create a scatter plot, and add color to showcase different income groups that countries are grouped by, which include low income,

data %>% 
  ggplot(aes(x=lnGDPPC, y=lnConsumption, color=IncomeGroup)) +
  geom_point() -> incomeanalysis

incomeanalysis

We can see there is a positive correlation between a countries consumption and GDP which makes sense, because the more a household consumes the higher GDP should be.

Let’s add a line of best fit, to show the liner correlation between the two variables. Based on the positive correlation we see in the scatter plot, we will expect a positive slope with the line of best fit.

data %>% 
  ggplot(aes(x=lnGDPPC, y=lnConsumption, color=IncomeGroup)) +
  geom_point() +geom_abline() -> candpanalysis

candpanalysis

As expected, the line of best fit shows the positive correlation between consumption and GDP.

Now I am going to add labels to the graph including a title, y and x axis labels, as well as labels for each individual point defined by ‘CC’ which is a countries three letter identification code.

print(candpanalysis + ggtitle("Income and Welfare") + 
        labs(y="GDP per capita", x="Consumption per capita") +
        labs (color= "Income Group"))

data %>% 
  ggplot(aes(x=lnGDPPC, y=lnConsumption, color=IncomeGroup, label= CC)) +
  geom_point() +geom_abline() -> candpanalysis

print(candpanalysis + ggtitle("Income and Welfare") + 
        labs(y="GDP per capita", x="Consumption per capita") +
        labs (color= "Income Group"))  +
  geom_text(size= 2, hjust=0, nudge_x= 0.33)

Now we can see the three letter code which represents each country. Overall, this graph tells us that in general, the higher income a country on average make has is correlated with better welfare,as gdp is a measure of how well off a country is (in economics).

With this, we can see that income is also a measure of how well off a country is. This makes sense because the more income a person has, the more they are willing to spend and the more consumption people have, the higher a country’s GDP is. In general, economists compare country’s GDP to compare how well off country’s are compared to one another.

Now let’s look at some specific factors in the US, and let’s see if we can find a correlation between interest rates and inflation. As the economy is a hot topic right now I want to try and see if I can find any patterns in the economy to tell as where we are headed.

So, let’s load new data, also taken from World Data Bank Indicators, to get inflation rates and interest rates in the United States through time.

library(readxl)
Inflation_and_Interest_Rate <- read_excel("~/Desktop/final project /Inflation and Interest Rate.xlsx")
View(Inflation_and_Interest_Rate)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1
Inflation_and_Interest_Rate
## # A tibble: 50 × 3
##    Year          Inflation      r
##    <chr>             <dbl>  <dbl>
##  1 1972 [YR1972]      3.27  0.887
##  2 1973 [YR1973]      6.18  2.41 
##  3 1974 [YR1974]     11.1   1.65 
##  4 1975 [YR1975]      9.14 -1.28 
##  5 1976 [YR1976]      5.74  1.27 
##  6 1977 [YR1977]      6.50  0.575
##  7 1978 [YR1978]      7.63  1.89 
##  8 1979 [YR1979]     11.3   4.03 
##  9 1980 [YR1980]     13.5   5.72 
## 10 1981 [YR1981]     10.3   8.59 
## # … with 40 more rows

Inflation is a measure of the increase of prices of goods and services in an economy, represented as ‘inflation’ in my data. Interest rates are controlled by the Federal Reserve, and is the total amount of interest on funds borrowed, that then trickles down to private banks who set interest rates to their customers.

Let’s make another scatter plot between inflation and interest rates and see if we can find any correlation.

Inflation_and_Interest_Rate %>% 
  ggplot(aes(x=Inflation, y=r, label=Year)) +
  geom_point(color = "steelblue")+
  geom_abline(color = "darkred") -> inflationandr

print(inflationandr + ggtitle("Inflation and Interest Rates")+
        labs(y="Interest Rate", x="Inflation Rate")+
        geom_text(size=2, hjust=0, nudge_x=0.33))

We can see there is a positive correlation between inflation and interest rates. Although it is not as strong as we saw before with consumption and GDP, this makes sense, when inflation is rising (prices are rising), the federal reserve will fight that, by increasing interest rates, so people spend less money in the economy, and inflation, will hopefully go down.

Now this didn’t tell us much about where we are headed, so lets plot out just inflation over time. I had to update my data’s ‘years’ column to only have a numerical value, so lets re-upload it.

library(readxl)
Updates_Years_for_Inflation_and_Interest_Rate <- read_excel("~/Desktop/final project /Updates Years for Inflation and Interest Rate.xlsx")
View(Updates_Years_for_Inflation_and_Interest_Rate)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1
Updates_Years_for_Inflation_and_Interest_Rate %>% 
  ggplot(aes(x=Year, y=Inflation)) +
  geom_line(color="darkred") ->inflationovertime

print(inflationovertime + ggtitle("US Inflation Through Time") +
        labs(y="Inflation Rate", x="Year")) -> USinflation

This shows us the inflation rate since 1970. I think it would be interesting to see at what time period that the United states was in a declared recession and what the corresponding inflation to see if there is a correlation. A recession is declared when the country’s GDP declines for two quarters in a row

Let’s load real GDP data from FRED for the US over time to gather this information! The data shows GDP for each quarter, so I will be able to see when the US was in a recession when the GDP dropped for two or more consecutive quarters.

library(readxl)
USRealGDPBillions <- read_excel("~/Desktop/final project /USRealGDPBillions.xls")
View(USRealGDPBillions)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1

To keep this manageable, I am looking at data from 1970 on wards. Looking at this table, I am going to shade in areas on the inflation graph I created above where a recession took place. Although I cant get extremely specific by declaring months, I am using decimals depending on the quarter the recession was in to specify when to start shading on my graph.

USinflation +
  annotate("rect", xmin=1973.75, xmax=1975.5, ymin=-.5, ymax=15, alpha=.2) +
  annotate("rect", xmin=1980, xmax=1980.5, ymin=-.5, ymax=15, alpha=.2)+
  annotate("rect", xmin=1981.5, xmax=1982.75, ymin=-.5, ymax=15, alpha=.2)+
  annotate("rect", xmin=1990.5, xmax=1991.25, ymin=-.5, ymax=15, alpha=.2)+
  annotate("rect", xmin=2001.25, xmax=2001.75, ymin=-.5, ymax=15, alpha=.2)+
  annotate("rect", xmin=2007.75, xmax=2009.5, ymin=-.5, ymax=15, alpha=.2)+
  annotate("rect", xmin=2020.25, xmax=2020.5, ymin=-.5, ymax=15, alpha=.2)

For the most part, we see recessions during periods when inflation is decreasing after a big spike in inflation. So although we are not in a recession right now, it would be interesting to see what happens in the future, considering inflation has been increasing constantly.

As we see from the past, inflation cannot continue to increase since the fed will fight it, so at some point it will need to start to decrease, and it will be interesting to see what happens as far as if we will be in a recession. My prediction is that eventually, we will end up in a brief recession.

I want to graph this same thing on an interest rates graph to see if we see a more clear correlation.

Updates_Years_for_Inflation_and_Interest_Rate %>% 
  ggplot(aes(x=Year, y=r)) +
  geom_line(color="darkred") ->rovertime

print(rovertime + ggtitle("US Interest Rates Through Time") +
        labs(y="Interest Rate", x="Year")) -> USinterest

USinterest +
  annotate("rect", xmin=1973.75, xmax=1975.5, ymin=-1, ymax=9, alpha=.2) +
  annotate("rect", xmin=1980, xmax=1980.5, ymin=-1, ymax=9, alpha=.2)+
  annotate("rect", xmin=1981.5, xmax=1982.75, ymin=-1, ymax=9, alpha=.2)+
  annotate("rect", xmin=1990.5, xmax=1991.25, ymin=-1, ymax=9, alpha=.2)+
  annotate("rect", xmin=2001.25, xmax=2001.75, ymin=-1, ymax=9, alpha=.2)+
  annotate("rect", xmin=2007.75, xmax=2009.5, ymin=-1, ymax=9, alpha=.2)+
  annotate("rect", xmin=2020.25, xmax=2020.5, ymin=-1, ymax=9, alpha=.2)

This one is a little more clear. When a recession happens, interest rates fall and start to increase again shortly after a recession ends. Again, the recession tends to be after periods when the interest rate is high, which is very interesting. Although my data doesn’t show the current day interest rates, they are very high, so this would further the idea that we could be headed into a recession, just by looking at past data.