The purpose of this analysis is to construct a Diffusion Index for three economic variables in the United States and compare it with the Chicago Fed National Activity Index: Diffusion Index (CFNAIDIFF). The Diffusion Index serves as an indicator of economic trends by summarizing the directional movement of selected variables. We will analyze the correlation between the two indexes and provide insights into their alignment and implications for current economic activity.
The data used includes: 1. Employment data (Total Nonfarm Payrolls). 2. Industrial Production Index. 3. Retail Sales. 4. CFNAIDIFF data from the Chicago Fed.
The data is preprocessed to calculate month-over-month changes and converted into binary indicators (expansion = 1, contraction = 0).
# Load Libraries
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(readr)
# Load datasets
employment <- read.csv("D:/DOWLOADS/employment.csv")
industrial_production <- read.csv("D:/DOWLOADS/industrial_production.csv")
retail_sales <- read.csv("D:/DOWLOADS/retail_sales.csv")
cfnaidiff <- read.csv("D:/DOWLOADS/cfnaidiff.csv")
# Ensure proper column names
colnames(employment) <- c("date", "value")
colnames(industrial_production) <- c("date", "value")
colnames(retail_sales) <- c("date", "value")
colnames(cfnaidiff) <- c("date", "value")
# Convert 'date' to Date format
employment$date <- as.Date(employment$date)
industrial_production$date <- as.Date(industrial_production$date)
retail_sales$date <- as.Date(retail_sales$date)
cfnaidiff$date <- as.Date(cfnaidiff$date)
# Handle month-over-month changes and binary indicators
employment <- employment %>%
arrange(date) %>%
mutate(change = value - lag(value),
indicator = ifelse(change > 0, 1, 0))
industrial_production <- industrial_production %>%
arrange(date) %>%
mutate(change = value - lag(value),
indicator = ifelse(change > 0, 1, 0))
retail_sales <- retail_sales %>%
arrange(date) %>%
mutate(change = value - lag(value),
indicator = ifelse(change > 0, 1, 0))
# Construct Diffusion Index
diffusion_index <- employment %>%
select(date, emp_indicator = indicator) %>%
inner_join(select(industrial_production, date, ind_indicator = indicator), by = "date") %>%
inner_join(select(retail_sales, date, retail_indicator = indicator), by = "date") %>%
mutate(diffusion_index = (emp_indicator + ind_indicator + retail_indicator) / 3)
# Merge with CFNAIDIFF
combined_data <- diffusion_index %>%
inner_join(select(cfnaidiff, date, cfnaidiff_value = value), by = "date")
# Remove non-finite or missing values
combined_data <- combined_data %>%
filter(!is.na(diffusion_index), !is.na(cfnaidiff_value))
# Correlation Analysis
correlation <- cor(combined_data$diffusion_index, combined_data$cfnaidiff_value, use = "complete.obs")
print(paste("Correlation Coefficient:", round(correlation, 4)))
## [1] "Correlation Coefficient: 0.0033"
# Visualization
ggplot(combined_data, aes(x = date)) +
geom_line(aes(y = diffusion_index, color = "My Diffusion Index"), linewidth = 1) +
geom_line(aes(y = cfnaidiff_value, color = "CFNAIDIFF"), linewidth = 1) +
geom_smooth(aes(y = diffusion_index), method = "loess", se = FALSE, color = "blue", linetype = "dashed") +
geom_smooth(aes(y = cfnaidiff_value), method = "loess", se = FALSE, color = "red", linetype = "dashed") +
labs(title = "Comparison of Diffusion Indexes",
x = "Date",
y = "Value",
color = "Index") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
This analysis demonstrates the construction and evaluation of a Diffusion Index for economic activity. The comparison with CFNAIDIFF provides valuable insights into the current state of the economy and potential leading indicators for future trends.