~/code/R/
load_code("load_pk.R")
load_code("load_data.R")
load_code("include_graphics2.R")
load_code("oecd_functions.R")
load_code("reg_ERregime.R")
load_data("fred/data.RData")
load_data("uk/uk_extract.RData")
data_UK <- data %>%
filter(variable %in% c("CPIIUKA", "UNRTUKA", "EMPUKA")) %>%
mutate(year = date %>% substr(1, 4) %>% as.numeric,
value = value / 100) %>%
select(variable, year, value) %>%
spread(variable, value) %>%
mutate(CPIIUKA_log = log(CPIIUKA),
price_inflation = CPIIUKA_log - lag(CPIIUKA_log, 1)) %>%
full_join(uk_extract %>%
mutate(wages_log = log(wages),
wages_log_d1 = wages_log - lag(wages_log)),
by = "year") %>%
select(year, UNRTUKA, price_inflation, wages_log_d1) %>%
mutate(date = year %>% paste0("-01-01") %>% as.Date) %>%
select(date, UNRTUKA, wages_log_d1) %>%
mutate(wages_log_d1_lag = lag(wages_log_d1, 1)) %>%
arrange(date) %>%
na.omit
rolling_lm <- rollify(.f = function(wages_log_d1, UNRTUKA){
lm(wages_log_d1 ~ UNRTUKA)
}, window = 10, unlist = FALSE)
data_UK %>%
mutate(roll_lm = rolling_lm(wages_log_d1, UNRTUKA)) %>%
filter(!is.na(roll_lm)) %>%
mutate(tidied = purrr::map(roll_lm, broom::tidy, conf.int = TRUE)) %>%
unnest(tidied) %>%
select(date, term, estimate, std.error, statistic, p.value, conf.low, conf.high) %>%
filter(term != "(Intercept)") %>%
ggplot(data = .) +
geom_ribbon(aes(x = date, ymin = conf.low, ymax = conf.high),
alpha = 0.25)+
geom_line(aes(x = date, y = estimate)) +
geom_hline(yintercept = 0, linetype = "dashed", color = viridis(4)[1]) +
scale_x_date(breaks = seq(1760, 2025, 20) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%Y")) +
scale_y_continuous(breaks = seq(-10, 10, 1),
limits = c(-7.5, 7.5)) +
theme_minimal() + labs(x = "", y = "") +
geom_text(data = data_frame(start = c(1873) %>% paste0("-01-01") %>% as.Date,
percent = c(-7.5),
name = c("Phillips' Study Period (1861-1957)")),
aes(x = start, y = percent, label = name),
size = 3, vjust = 0, hjust = 0, nudge_x = 50, color = grey(0.3)) +
geom_rect(data = data_frame(start = as.Date("1861-01-01"),
end = as.Date("1957-09-19")),
aes(xmin = start, xmax = end, ymin = -Inf, ymax = +Inf),
fill = viridis(4)[3], alpha = 0.1)