knitr::opts_chunk$set(
  collapse = TRUE,
  echo = FALSE,
  message = FALSE,
  warning = FALSE,
  comment = "#>"
)
library(tidyverse)
library(ggptt)
# library(ficomp)
library(pttdatahaku)

devtools::load_all()

start_year <- 2000
set_board_theme(base_size = 10)

fig_translation <- pRoductivity::fig_translation

geo_wage <- c("BE", "DK", "DE", "ES", "FR", "IT", "NL", "AT", "FI", "SE", "UK", "NO", "US")

ameco7_0 <- ficomp::read_ameco(table_num = 7, ameco_file = here::here("data-raw/AMECO7_2022spring.TXT"))

ameco7_I <- 
  ameco7_0 |> 
  separate(code, into = c("geo", NA, "desc", "unit_code", "rel", "vars"), sep = "\\.", remove = FALSE) |> 
  mutate(geo = as_factor(countrycode::countrycode(geo, "iso3c", "eurostat",
                                                  nomatch = NULL,
                                                  custom_match = c(ROM = "RO")))) |> 
  mutate_if(is.character, as_factor) |> 
  filter(desc %in% c(0,1))  # Only current values weights, 2 is PPS weights (it seems)

# ameco7_I |> 
#   filter(geo == "US",
#          rel == "0") |> 
#   unite("title_unit", title, unit) |> 
#   filter(time >= 2021) |> 
#   droplevels() |> #str()
#   select(title_unit, unit_code ,time, values) |> 
#   spread(time, values) |> 
#   knitr::kable()
fig_height <- 10

Komission ennusteet

Ameco tietokanta sisältää komission ennusteet.

EU ja EA aggregaatit eivät vastaa ennustejulkaisun Statistics annexin lukuja, vaikka maiden luvut vastaavat.

Sain selitykseksi tämän: Please note that table 26 in the Statistical Annex is based on full-time equivalents when available. See note 6 in the Annex: “Employment data used in tables 24 and 26-30 are based on full-time equivalents (FTEs), where available. Currently, Spain, France, Italy, and the Netherlands report FTE data. In the absence of FTE data, employment is based on numbers of persons. In the calculation of EU and euro-area aggregates, priority is given to FTE data, as this is regarded as more representative of diverse patterns of working time”

By contrast the AMECO variable is based on numbers of persons.

Nominal compensation per employee: total economy

ameco7_I |> 
  filter(
    rel == "0",
    # Standard aggregation
    desc == "0",
    title == "Nominal compensation per employee: total economy ",
    # national currency
    unit_code == "0"
    ) |> 
  filter(time >= max(time)-4) |> 
  select(country, time, values) |> 
  complete(country, time) |> 
  group_by(country) |> 
  mutate(values = pc(values, 1, order_by = time)) |> 
  ungroup() |> 
  filter(time >= max(time)-3) |> 
  spread(time, values) |> 
  drop_na() |>
  arrange(across(last_col())) |> 
  knitr::kable(digits = 1)
ameco7_I |> 
  filter(
    geo %in% geo_wage,
    rel == "0",
    # Standard aggregation
    desc == "0",
    title == "Nominal compensation per employee: total economy ",
    # national currency
    unit_code == "0"
    ) |> 
  filter(time >= start_year) |> 
  # select(country, time, values) |> 
  group_by(country) |> 
  mutate(values = pc(values, 1, order_by = time)) |> 
  ungroup() |> 
  ggplot(aes(time, values, colour = country, size = geo == "FI")) +
  geom_line()+
  scale_size_manual(values = c(1,3)) +
  labs(
    title = "Nominal compensation per employee"
  )

Suhteelliset

Ameco sisältää myös suhteellisia

ameco7_I |> 
  filter_recode(
    geo = "FI",
    # rel == "0",
    # Standard aggregation
    desc = "0",
    title = c(
      "EU-15" = "Nominal compensation per employee: total economy: Relative performance: double export weights :- Performance relative to the rest of the former EU-15: double export weights ",
      "Teollisuusmaat_24" = "Nominal compensation per employee: total economy: Relative performance: double export weights :- Performance relative to the rest of 24 industrial countries: double export weights : EU-15, TR CH NR US CA JP AU MX and NZ",
      "Teollisuusmaat_12" = "Nominal compensation per employee: total economy: Relative performance: double export weights :- Performance relative to  12 industrial countries (DK SE UK TR CH NO US CA MX JP AU NZ)",
      "Teollisuusmaat_9" = "Nominal compensation per employee: total economy: Relative performance: double export weights :- Performance relative to  9 industrial countries (TR CH NO US CA MX JP AU NZ)", 
       "Teollisuusmaat_37" = "Nominal compensation per employee: total economy: Relative performance: double export weights :- Performance relative to the rest of 37 industrial countries: double export weights "),
    # national currency
    unit_code = "0"
    ) |> 
  filter(time >= start_year) |> 
  # select(country, time, values) |> 
  # group_by(title) |> 
  # mutate(values = pc(values, 1, order_by = time)) |> 
  # ungroup() |> 
  ggplot(aes(time, values, colour = title, size = geo == "FI")) +
  geom_line()+
  scale_size_manual(values = c(1,3)) +
  labs(
    title = "Nominal compensation per employee"
  )

Suhteelliset eivät kuitenkaan sisällä ennusteita, joten oma suhteellinen ennusteiden kanssa:

ameco7_rel <- 
  ameco7_I |> 
  filter_recode(
    geo = c(geo17),
    rel = "0",
    # Standard aggregation
    desc = "0",
    title = "Nominal compensation per employee: total economy ",
    # national currency
    unit_code = "0"
    ) |> 
  filter(time >= start_year) |> 
  group_by(geo) |> 
  mutate(values = rebase(values, time, 2015)) |> 
  group_by(time) |> 
  mutate(rel = weight_index2(values, geo, time, geos = geo17, weight_df = weights_ecfin37)) |> 
  ungroup()


ameco7_rel |> 
  filter(geo == "FI") |> 
  ggplot(aes(time, rel)) +
  geom_line()+
  # scale_size_manual(values = c(1,3)) +
  labs(
    title = "Nimelliset palkansaajakorvaukset suhteessa kauppakumppaneihin\nEU komission ennuste"
  )
eo_rel <- 
  eo_a_dat |> 
  select(geo, time, values = D1_aper__CP_MNAC) |> 
  filter(time >= start_year) |> 
  group_by(geo) |> 
  mutate(values = rebase(values, time, 2015)) |> 
  group_by(time) |> 
  mutate(rel = weight_index2(values, geo, time, geos = setdiff(geo17, "CH"), 
                             weight_df = weights_ecfin37)) |> 
  ungroup()

p <- bind_rows(
  EU = select(ameco7_rel, geo, time, values, rel),
  OECD = eo_rel,
  .id = "source"
) |> 
  filter(geo == "FI") |> 
  mutate(other_w = 100 * values / rel) |> 
  select(time, Suomi = values, Verrokkimaat = other_w, source) |> 
  gather(vars, value, Suomi, Verrokkimaat) |> 
  group_by(vars, source) |> 
  mutate(value = 100 * (value / lag(value, 1) -1)) |> 
  ungroup() |> 
  unite(vars2, vars, source, sep = ", ", remove = FALSE) |> 
    ggplot(aes(time, value, colour = vars2, size = vars2)) +
  # facet_wrap(~source) +
   geom_rect(aes(xmin=2021.5, xmax=2023.5, ymin=-Inf, ymax=Inf), 
            fill="grey", colour = "grey", size = 1, alpha=0.9) +
  geom_line() +
  scale_x_continuous(limits = c(2000, 2023.5), expand = c(0,0)) +
  scale_size_manual(values = c(2, 1,2,1)) +
  scale_colour_manual(values = c("#0072B2", "#fc7d0b")[c(1,1,2,2)]) +
  geom_h0() +
  labs(
    title = "Palkansaajakorvaukset työllistä kohden",
    y = "%, vuosimuutos",
    caption = "Lähde: OECD, AMECO, Tuottavuuslautakunta"
  ) +
  the_title_blank("xl") +
  the_legend_bot() +
  guides(colour = guide_legend(nrow = 2), size = guide_legend(nrow = 2))

p

save_board_figs("Kuvio_2_6", plot = p, height = fig_height, save_data = TRUE)

save_board_figs("Kuvio_2_6_en", plot = ggptt::translate_plot(p + labs(caption = NULL), fig_translation), height = fig_height)

OECD Economic outlook

Compensation rate, total economy per palkansaajat (EE)

eo_a_dat |> 
  filter(geo %in% geo_wage) |> 
  select(geo, time, values = D1_aper__CP_MNAC) |> 
  filter(time >= start_year) |> 
  # select(country, time, values) |> 
  group_by(geo) |> 
  mutate(values = pc(values, 1, order_by = time)) |> 
  ungroup() |> 
  ggplot(aes(time, values, colour = geo, size = geo == "FI")) +
  geom_line() +
  scale_size_manual(values = c(1,3)) +
  labs(
    title = "Compensation rate, total economy"
  )

Yksikkötyökustannukset

ameco7_rel_ulc <- 
  ameco7_I |> 
  filter_recode(
    geo = c(geo17),
    rel = "0",
    # Standard aggregation
    desc = "1",
    vars = "PLCD",
    # title = "Nominal unit labour costs (ratio of compensation per employee to real GDP per employee) (Ratio of compensation per employee to real GDP per person employed.) ",
    # national currency
    unit_code = "0"
    ) |> 
  filter(time >= start_year) |> 
  group_by(geo) |> 
  mutate(values = rebase(values, time, 2015)) |> 
  group_by(time) |> 
  mutate(rel = weight_index2(values, geo, time, geos = geo17, weight_df = weights_ecfin37)) |> 
  ungroup()


ameco7_rel_ulc |> 
  filter(geo == "FI") |> 
  ggplot(aes(time, rel)) +
  geom_line()+
  # scale_size_manual(values = c(1,3)) +
  labs(
    title = "Nimelliset yksikkötyökustannukset suhteessa kauppakumppaneihin\nEU komission ennuste"
  )

eo_rel_ulc <- 
  eo_a_dat |> 
  select(geo, time, values = nulc) |> 
  filter(time >= start_year) |> 
  group_by(geo) |> 
  mutate(values = rebase(values, time, 2015)) |> 
  group_by(time) |> 
  mutate(rel = weight_index2(values, geo, time, geos = setdiff(geo17, "CH"), 
                             weight_df = weights_ecfin37)) |> 
  ungroup()

p <- bind_rows(
  EU = select(ameco7_rel_ulc, geo, time, values, rel),
  OECD = eo_rel_ulc,
  .id = "source"
) |> 
  filter(geo == "FI") |> 
  mutate(other_w = 100 * values / rel) |> 
  select(time, Suomi = values, Verrokkimaat = other_w, source) |> 
  gather(vars, value, Suomi, Verrokkimaat) |> 
  group_by(vars, source) |> 
  mutate(value = 100 * (value / lag(value, 1) -1)) |> 
  ungroup() |> 
  unite(vars2, vars, source, sep = ", ", remove = FALSE) |> 
    ggplot(aes(time, value, colour = vars2, size = vars2)) +
  # facet_wrap(~source) +
   geom_rect(aes(xmin=2021.5, xmax=2023.5, ymin=-Inf, ymax=Inf), 
            fill="grey", colour = "grey", size = 1, alpha=0.9) +
  geom_line() +
  scale_x_continuous(limits = c(2000, 2023.5), expand = c(0,0)) +
  scale_size_manual(values = c(2, 1,2,1)) +
  scale_colour_manual(values = c("#0072B2", "#fc7d0b")[c(1,1,2,2)]) +
  geom_h0() +
  labs(
    title = "Nimelliset yksikkötyökustannukset",
    y = "%, vuosimuutos",
    caption = "Lähde: OECD, AMECO, Tuottavuuslautakunta") +
  the_title_blank("xl") +
  the_legend_bot() +
  guides(colour = guide_legend(nrow = 2), size = guide_legend(nrow = 2))
# +
#     guides(size = guide_legend(override.aes = list(colour = "grey50"),   title = ""),
#          colour = guide_legend(title = "Lähde:"))

p

save_board_figs("Kuvio_2_7", plot = p, height = fig_height, save_data = TRUE)

save_board_figs("Kuvio_2_7_en", plot = ggptt::translate_plot(p + labs(caption = NULL), fig_translation), height = fig_height)


pttry/ficomp documentation built on June 11, 2024, 9:53 p.m.