Code
load_data("oecd/SNA_TABLE1_SNA93_var.RData")
load_data("oecd/SNA_TABLE1_SNA93.RData")
load_data("us/nber_recessions.RData")
Data - OECD
load_data("oecd/SNA_TABLE1_SNA93_var.RData")
load_data("oecd/SNA_TABLE1_SNA93.RData")
load_data("us/nber_recessions.RData")
%>%
SNA_TABLE1_SNA93 left_join(SNA_TABLE1_SNA93_var %>% pluck("TRANSACT"), by = c("TRANSACT" = "id")) %>%
rename(`TRANSACT Description` = label) %>%
left_join(SNA_TABLE1_SNA93_var %>% pluck("MEASURE"), by = c("MEASURE" = "id")) %>%
rename(`MEASURE Description` = label) %>%
group_by(TRANSACT, `TRANSACT Description`, MEASURE, `MEASURE Description`) %>%
summarise(nobs = n()) %>%
arrange(-nobs) %>%
if (is_html_output()) datatable(., filter = 'top', rownames = F) else .} {
$VAR_DESC %>%
SNA_TABLE1_SNA93_varif (is_html_output()) print_table(.) else .} {
id | description |
---|---|
LOCATION | Country |
TRANSACT | Transaction |
MEASURE | Measure |
TIME | Year |
OBS_VALUE | Observation Value |
TIME_FORMAT | Time Format |
OBS_STATUS | Observation Status |
UNIT | Unit |
POWERCODE | Unit multiplier |
REFERENCEPERIOD | Reference period |
%>%
SNA_TABLE1_SNA93 left_join(SNA_TABLE1_SNA93_var$TRANSACT, by = c("TRANSACT" = "id")) %>%
rename(`TRANSACT Description` = label) %>%
group_by(TRANSACT, `TRANSACT Description`) %>%
summarise(Nobs = n()) %>%
arrange(-Nobs) %>%
if (is_html_output()) datatable(., filter = 'top', rownames = F) else .} {
%>%
SNA_TABLE1_SNA93 left_join(SNA_TABLE1_SNA93_var$MEASURE, by = c("MEASURE" = "id")) %>%
rename(`MEASURE Description` = label) %>%
group_by(MEASURE, `MEASURE Description`) %>%
summarise(Nobs = n()) %>%
if (is_html_output()) datatable(., filter = 'top', rownames = F) else .} {
%>%
SNA_TABLE1_SNA93 filter(TRANSACT == "B1_GE",
== "C") %>%
MEASURE left_join(SNA_TABLE1_SNA93_var$LOCATION %>%
setNames(c("LOCATION", "LOCATION_desc")),
by = "LOCATION") %>%
group_by(LOCATION, UNIT, LOCATION_desc) %>%
summarise(year_first = first(obsTime),
year_last = last(obsTime),
value_last = last(round(obsValue))) %>%
if (is_html_output()) datatable(., filter = 'top', rownames = F) else .} {
%>%
SNA_TABLE1_SNA93 filter(LOCATION %in% c("USA"),
== "B1_GA",
TRANSACT %in% c("C", "V")) %>%
MEASURE mutate(date = paste0(obsTime, "-01-01") %>% as.Date,
obsValue = obsValue / 10^6) %>%
left_join(SNA_TABLE1_SNA93_var$LOCATION %>%
rename(LOCATION = id),
by = "LOCATION") %>%
left_join(SNA_TABLE1_SNA93_var$MEASURE %>%
rename(MEASURE = id, MEASURE_label = label),
by = "MEASURE") %>%
group_by(LOCATION) %>%
arrange(date) %>%
select(date, obsValue, MEASURE_label) %>%
ggplot(.) + geom_line(aes(x = date, y = obsValue, linetype = MEASURE_label, color = MEASURE_label)) +
theme_minimal() + xlab("") + ylab("") +
scale_color_manual(values = viridis(4)[1:3]) +
geom_rect(data = nber_recessions,
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_x_date(breaks = seq(1960, 2020, 5) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y"),
limits = c(1970, 2019) %>% paste0("-01-01") %>% as.Date) +
scale_y_continuous(breaks = seq(0, 30, 1),
labels = dollar_format(suffix = "Tn", prefix = "$", accuracy = 1)) +
theme(legend.position = c(0.3, 0.90),
legend.title = element_blank())
%>%
SNA_TABLE1_SNA93 filter(LOCATION %in% c("USA"),
== "P3",
TRANSACT %in% c("C", "V")) %>%
MEASURE mutate(date = paste0(obsTime, "-01-01") %>% as.Date,
obsValue = obsValue / 10^6) %>%
left_join(SNA_TABLE1_SNA93_var$LOCATION %>%
rename(LOCATION = id),
by = "LOCATION") %>%
left_join(SNA_TABLE1_SNA93_var$MEASURE %>%
rename(MEASURE = id, MEASURE_label = label),
by = "MEASURE") %>%
group_by(LOCATION) %>%
arrange(date) %>%
select(date, obsValue, MEASURE_label) %>%
ggplot(.) + geom_line(aes(x = date, y = obsValue, linetype = MEASURE_label, color = MEASURE_label)) +
theme_minimal() + xlab("") + ylab("") +
scale_color_manual(values = viridis(4)[1:3]) +
geom_rect(data = nber_recessions,
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_x_date(breaks = seq(1960, 2020, 5) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y"),
limits = c(1970, 2019) %>% paste0("-01-01") %>% as.Date) +
scale_y_continuous(breaks = seq(0, 30, 1),
labels = dollar_format(suffix = "Tn", prefix = "$", accuracy = 1)) +
theme(legend.position = c(0.3, 0.90),
legend.title = element_blank())
%>%
SNA_TABLE1_SNA93 filter(LOCATION %in% c("USA"),
== "P51",
TRANSACT %in% c("C", "V")) %>%
MEASURE mutate(date = paste0(obsTime, "-01-01") %>% as.Date,
obsValue = obsValue / 10^6) %>%
left_join(SNA_TABLE1_SNA93_var$LOCATION %>%
rename(LOCATION = id),
by = "LOCATION") %>%
left_join(SNA_TABLE1_SNA93_var$MEASURE %>%
rename(MEASURE = id, MEASURE_label = label),
by = "MEASURE") %>%
group_by(LOCATION) %>%
arrange(date) %>%
select(date, obsValue, MEASURE_label) %>%
ggplot(.) + geom_line(aes(x = date, y = obsValue, linetype = MEASURE_label, color = MEASURE_label)) +
theme_minimal() + xlab("") + ylab("") +
scale_color_manual(values = viridis(4)[1:3]) +
geom_rect(data = nber_recessions,
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_x_date(breaks = seq(1960, 2020, 5) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y"),
limits = c(1970, 2019) %>% paste0("-01-01") %>% as.Date) +
scale_y_continuous(breaks = seq(0, 10, 0.5),
labels = dollar_format(suffix = "Tn", prefix = "$", accuracy = 0.1)) +
theme(legend.position = c(0.3, 0.90),
legend.title = element_blank())
%>%
SNA_TABLE1_SNA93 filter(LOCATION %in% c("JPN"),
== "B1_GE",
TRANSACT %in% c("C", "V")) %>%
MEASURE mutate(date = paste0(obsTime, "-01-01") %>% as.Date) %>%
left_join(SNA_TABLE1_SNA93_var$LOCATION %>%
rename(LOCATION = id),
by = "LOCATION") %>%
left_join(SNA_TABLE1_SNA93_var$MEASURE %>%
rename(MEASURE = id, MEASURE_label = label),
by = "MEASURE") %>%
group_by(LOCATION) %>%
arrange(date) %>%
select(date, obsValue, MEASURE_label) %>%
ggplot(.) +
geom_line(aes(x = date, y = obsValue / 10^6, linetype = MEASURE_label, color = MEASURE_label)) +
theme_minimal() + xlab("") + ylab("") +
scale_color_manual(values = viridis(4)[1:3]) +
geom_rect(data = nber_recessions,
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_x_date(breaks = seq(1960, 2020, 5) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y"),
limits = c(1970, 2019) %>% paste0("-01-01") %>% as.Date) +
scale_y_continuous(breaks = seq(0, 600, 50),
labels = dollar_format(suffix = " Tn", prefix = "¥", accuracy = 1)) +
theme(legend.position = c(0.6, 0.20),
legend.title = element_blank())