Skip to content

Instantly share code, notes, and snippets.

@jkr216
Created March 13, 2023 23:35
Show Gist options
  • Save jkr216/a505c40e3716119fe2e96c94cc50f30c to your computer and use it in GitHub Desktop.
Save jkr216/a505c40e3716119fe2e96c94cc50f30c to your computer and use it in GitHub Desktop.
miller labor slack index
```{r, include = FALSE}
library(tidyverse)
library(tidyquant)
library(timetk)
library(scales)
library(fredr)
library(gt)
library(gtExtras)
library(janitor)
library(ggtext)
```
We will start clean for the MLSI, even though we have already imported some of this data previously. The steps are as follows:
1) import the unemployment rate, participation rates and full time/part time rates from FRED
2) Combine to one tibble with each time series in a column
3) Convert the participation rate to an unparticipation rate by taking 100 - partic rate/100
4) Use a custom indexing function to index all the series to be equal to 100 on January,1 2020 (just before COVID)
5) Take the mean of the unemploymnet rate, the nonparticipation rate and the part time full time ratio for each month.
6) The mean of those three numbers is the MLSI. In other words, they are equally weighted
```{r}
unrate <-
"UNRATE" %>%
tq_get(get = "economic.data",
from = "1960-01-01")
labor_force_part <-
"LNS11300060" %>%
tq_get(
get = "economic.data",
from = "1960-01-01"
)
```
```{r}
ratio_part_time_to_full_time <-
tibble(
symbol = c("LNS12032199", "LNS12035019"),
name = c("part_time", "full_time")
) %>%
tq_get(get = "economic.data",
from = "1960-01-01") %>%
select(name, date, price) %>%
pivot_wider(names_from = name,
values_from = price) %>%
mutate(
part_time_ratio = part_time / full_time
) %>%
select(date, part_time_ratio)
```
```{r}
value_indexify <- function(.data, index_date, value_col) {
col_name <- str_glue("{value_col}_indexed")
mutate(.data,
base_value =
case_when(date == index_date ~ !!rlang::ensym(value_col),
TRUE ~ as.numeric(NA_integer_))) %>%
fill(base_value, .direction = "down") %>%
fill(base_value, .direction = "up") %>%
mutate(indexed_val = !!rlang::ensym(value_col)/base_value * 100) %>%
rename(!!quo_name(col_name) := indexed_val) %>%
select(-base_value)
}
```
```{r}
miller_slack_index <-
labor_force_part %>%
mutate(labor_force_unpart = (100 -price)/100) %>%
select(-price) %>%
left_join(
unrate %>%
rename(unrate = price) %>%
select(date, unrate)
) %>%
left_join(
ratio_part_time_to_full_time
) %>%
value_indexify("2020-01-01",
"unrate") %>%
value_indexify("2020-01-01",
"labor_force_unpart") %>%
value_indexify("2020-01-01",
"part_time_ratio") %>%
# select(date, contains("indexed")) %>%
mutate(mlsi =
rowMeans(select(., contains("indexed"))))
miller_slack_index
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment