-
Notifications
You must be signed in to change notification settings - Fork 1
/
Yellen_labor_mkt.R
148 lines (125 loc) · 4.89 KB
/
Yellen_labor_mkt.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Libraries
library(tidyverse)
# self-made package
devtools::install('../tqr')
library(tqr)
# Yellen's labor market dashboard
# note: https://www.bloomberg.com/graphics/2015-yellens-labor-market-dashboard/
# symbols in FRED
yellen_labor_mkt_symbols <- c(
"UNRATE", # Unemployment rate
"U6RATE", # U-6, underemployment rate
"LNS13025703", # Long-term unemployed share
"PAYEMS", # Non-farm payrolls, total
"JTSJOR", # Job openings rate
"JTSLDR", # Layoffs/discharged rate
"JTSQUR", # Quits rate
"JTSHIR", # Hires rate
"CEU0500000003", # Average hourly earnings, total private
"ECIALLCIV", # Employment cost index, all civilians, quaterly
"CIVPART", # Labor force participation rate
"PCEPILFE" # PCE excluding food and energy
)
# get data from this date
START = "2006-01-01"
# set xlim for plot
XLIM <- c(as.Date("2008-01-01"), as.Date("2019-12-01"))
# get data from FRED
labor_mkt_m <- yellen_labor_mkt_symbols %>%
tidyquant::tq_get(get = "economic.data", from = START)
# write csv for Excel in Windows 10, Japanese version
labor_mkt_m %>%
spread(key = symbol, value = price) %>%
write.csv("output/labor_mkt_m.csv", row.names = FALSE, fileEncoding = "CP932")
labor_mkt_m <- read_csv("output/labor_mkt_m.csv")
labor_mkt_m <- labor_mkt_m %>%
tq_tidy()
# transform Non-farm payrolls, total to differences, 3 month moving average
payems <- labor_mkt_m %>%
filter(symbol == "PAYEMS") %>%
tq_diff() %>%
tq_ma(n = 3)
# transform PCE to growth rates, YoY
pce <- labor_mkt_m %>%
filter(symbol == "PCEPILFE") %>%
tq_gr(n = 12)
# transform Average hourly earnings to YoY, 3 ma
ceu <- labor_mkt_m %>%
filter(symbol == "CEU0500000003") %>%
tq_gr(n = 12) %>%
tq_ma(n = 3)
# transform Employment cost index, quarterly data to YoY
eci <- labor_mkt_m %>%
filter(symbol == "ECIALLCIV") %>%
tq_gr(n = 4)
# Atlanta Fed Wage Trucker
# source: https://www.frbatlanta.org/chcs/wage-growth-tracker.aspx
url <- "https://www.frbatlanta.org/-/media/documents/datafiles/chcs/wage-growth-tracker/wage-growth-data.xlsx"
httr::GET(url, httr::write_disk(tf <- tempfile(fileext = ".xlsx")))
res <- readxl::read_excel(tf, col_names = FALSE, na = c(".", ""), skip = 2)
names(res)[1:2] <- c("date", "price")
res$date <- as.Date(res$date)
wage_tracker <- res %>%
select(date, price)
wage_tracker$symbol <- "WAGETR"
wage_tracker <- wage_tracker %>%
filter(date >= START)
# combine transformed data
labor_mkt <- labor_mkt_m %>%
filter(!(symbol %in% c("PAYEMS", "PCEPILFE", "CEU0500000003", "ECIALLCIV"))) %>%
bind_rows(payems) %>%
bind_rows(pce) %>%
bind_rows(ceu) %>%
bind_rows(eci) %>%
bind_rows(wage_tracker)
# symbol from chr to fctr
labor_mkt$symbol <- factor(labor_mkt$symbol,
levels = c("UNRATE", "LNS13025703", "U6RATE", "CIVPART",
"JTSJOR", "JTSLDR", "JTSQUR", "JTSHIR",
"PAYEMS", "CEU0500000003", "ECIALLCIV", "WAGETR",
"PCEPILFE"))
# recode symbol
labor_mkt <- labor_mkt %>%
mutate(
symbol = fct_recode(symbol,
"Unemployment rate" = "UNRATE",
"Long-term unemployed share" = "LNS13025703",
"U-6 underemployment rate" = "U6RATE",
"Labor force participation rate" = "CIVPART",
"Job openings rate" = "JTSJOR",
"Layoffs/discharged rate" = "JTSLDR",
"Quits rate" = "JTSQUR",
"Hires rate" = "JTSHIR",
"Non-farm payroll increase, 3 mo avg" = "PAYEMS",
"Avg hourly earnings, YoY, 3 mo avg" = "CEU0500000003",
"Employment cost index, YoY, quarterly" = "ECIALLCIV",
"Atlanta Fed wage tracker, YoY, 3 mo avg" = "WAGETR",
"PCE excluding food and energy, YoY" = "PCEPILFE"
)
)
# prepare for plot month
Sys.setlocale(category = "LC_TIME", locale = "C")
# plot with label only on the latest data
labor_mkt %>%
group_by(symbol) %>%
mutate(
label = if_else(date == max(date),
paste(lubridate::month(date, label = TRUE, abbr = TRUE),
as.character(round(price, 2))
, sep = " "),
NA_character_)
) %>%
ungroup() %>%
ggplot(aes(x = date, y = price)) +
geom_line() +
facet_wrap(~ symbol, ncol = 4, scales = "free_y") +
geom_text(aes(label = label), na.rm = TRUE,
hjust = 1, vjust = 0) +
coord_cartesian(xlim = XLIM) +
labs(
title = "Yellen's US labor market dashboard",
x = "",
y = "")
# save pdf in (nearly) A4 format wide
# ggsave(filename = "output/Yellen.pdf",
# width = 10, height = 8, units = "in", dpi = 300)