knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  fig.height = 7,
  fig.width = 10,
  fig.path = "Fig_labour_cost/", 
  echo = FALSE, message = FALSE, warning = FALSE
)
# library(ficomp)

devtools::load_all()

library(dplyr)
library(forcats)
library(ggplot2)
library(eurostat)
library(tidyr)
library(ggptt)

set_proj_theme()

data(naq_eurostat_dat, ulc_oecd_dat, ulc_ecb_dat, stan_dat)

base_year <- 2008
base_years <- 2000:2018
geos <- c(Finland = "FI", Sweden = "SE", Germany = "DE", France = "FR")
start_time <- "1990-01-01"

Data

Data for unit labour cost index

tibble(code = levels(naq_eurostat_dat$na_item), name = label_eurostat(levels(naq_eurostat_dat$na_item), "na_item"))

Nominal unit labour cost

Different definations for unit labour cost: Output: GDP or value added Relation to hours worked or persons (relevant if adjusted for self-employed or for decomposition)

Different measures quarterly

lc_dat_nace <- 
  naq_eurostat_dat %>% 
  unite(vars, na_item, unit) %>%  
  # filter(vars %in% c("D1_CP_MNAC", "B1G_CLV10_MNAC")) %>% 
  spread(vars, values) %>% 
  group_by(geo, nace_r2) %>% 
  mutate(
    # nominal unit labour cost
    nulc_va = ind_ulc(D1_CP_MNAC, B1G_CLV10_MNAC, time = time, baseyear = base_year),
    nulc = ind_ulc(D1_CP_MNAC, B1GQ_CLV10_MNAC, time = time, baseyear = base_year),
    # nominal unit labour cost, adjusted to take account emploees/emplyed share
    nulc_hw_va = ind_ulc(D1_CP_MNAC / SAL_DC_THS_HW, B1G_CLV10_MNAC / EMP_DC_THS_HW, time = time, baseyear = base_year),
    nulc_hw = ind_ulc(D1_CP_MNAC / SAL_DC_THS_HW, B1GQ_CLV10_MNAC / EMP_DC_THS_HW, time = time, baseyear = base_year),
    nulc_hw_eur = ind_ulc(D1_CP_MEUR / SAL_DC_THS_HW, B1GQ_CLV10_MNAC / EMP_DC_THS_HW, time = time, baseyear = base_year),
    nulc_per_va = ind_ulc(D1_CP_MNAC / SAL_DC_THS_PER, B1G_CLV10_MNAC / EMP_DC_THS_PER, time = time, baseyear = base_year),
    nulc_per = ind_ulc(D1_CP_MNAC / SAL_DC_THS_PER, B1GQ_CLV10_MNAC / EMP_DC_THS_PER, time = time, baseyear = base_year)) %>% 
  ungroup()

lc_dat <- lc_dat_nace %>% 
  filter(nace_r2 == "TOTAL")

lc_dat %>% 
  filter(geo %in% geos,
         time >= start_time) %>% 
  select(geo, time, nulc, nulc_va, nulc_hw, nulc_hw_va, nulc_per, nulc_per_va) %>% 
  gather(ind, values, -geo, -time) %>% 
  ggplot(aes(time, values, colour = geo)) +
  geom_line() +
  facet_wrap(~ ind)

On short term a NULC indicator selection does not matter. On longer term differences acculumate.

lc_dat %>% 
  filter(geo == "FI",
         time >= start_time) %>% 
  select(geo, time, nulc, nulc_va, nulc_hw, nulc_hw_va, nulc_per, nulc_per_va) %>% 
  gather(ind, values, -geo, -time) %>% 
  group_by(geo, ind) %>% 
  mutate(change = values / lag(values, 4, order_by = time) - 1) %>% 
  ungroup() %>% 
  gather(vars, values, values, change) %>% 
  ggplot(aes(time, values, colour = ind)) +
  facet_wrap(~ vars, scales = "free_y") +
  geom_line() 

ULC yearly from stan

lc_dat_stan <- 
  stan_dat %>% 
  # filter(vars %in% c("D1_CP_MNAC", "B1G_CLV10_MNAC")) %>% 
  group_by(geo, nace_r2) %>% 
  mutate(
    # nominal unit labour cost, adjusted to take account emploees/emplyed share
    nulc_hw_va = ind_ulc(D1__CP_MNAC / SAL_DC__THS_HW, B1G__CLV10_MNAC / EMP_DC__THS_HW, time = time, baseyear = base_year),
    nulc_va = ind_ulc(D1__CP_MNAC, B1G__CLV10_MNAC, time = time, baseyear = base_year),
) %>% 
  ungroup()

lc_dat_stan %>% 
   filter(geo %in% c(geos, "US"),
          nace_r2 == "TOTAL") %>% 
  select(geo, time, nulc_va, nulc_hw_va) %>% 
  gather(ind, values, -geo, -time) %>% 
  ggplot(aes(time, values, colour = geo)) +
  geom_line() +
  facet_wrap(~ ind)

In own and in common currency

lc_dat %>% 
  filter(geo %in% geos,
         time >= start_time) %>% 
  select(geo, time, nulc_hw, nulc_hw_eur) %>% 
  gather(ind, values, -geo, -time) %>% 
  ggplot(aes(time, values, colour = geo)) +
  geom_line() +
  facet_wrap(~ ind)
lc_dat %>% 
  filter(geo %in% geos,
         time >= start_time) %>% 
  select(geo, time, nulc_per) %>% 
  gather(ind, values, -geo, -time) %>% 
  mutate(geo = fct_recode(geo, !!!geos)) %>% 
  ggplot(aes(time, values, colour = geo)) +
  geom_line() +
  labs(title = "Unit labour cost, employment based",
       y = "index, 2008 = 100") +
  the_title_blank(c("x", "l"))

Nominal unit labour cost comparison from different sources

NULC_APER_OECD = NULC_PER_ECB = nulc_per = (D1_CP_MNAC / SAL_DC_THS_PER) / (B1GQ_CLV10_MNAC / EMP_DC_THS_PER)

NULC_HW_ECB = nulc_hw = (D1_CP_MNAC / SAL_DC_THS_HW) / (B1GQ_CLV10_MNAC / EMP_DC_THS_HW)

ulc_oecd_with <- ulc_oecd_dat %>% 
  select(- unit) %>% 
  filter(na_item == "NULC_APER") %>% 
  mutate(na_item = paste0(na_item, "_OECD")) %>% 
  group_by(geo, na_item) %>% 
  mutate(values = rebase(values, time, base_year)) %>% 
  ungroup() %>% 
  spread(na_item, values)

ulc_eurostat_with <- ulc_eurostat_dat %>% 
  filter(na_item %in% c("NULC_HW", "NULC_PER")) %>% 
  select(time, geo, na_item, values) %>% 
  mutate(na_item = paste0(na_item, "_eurostat")) %>% 
  group_by(geo, na_item) %>% 
  mutate(values = rebase(values, time, base_year)) %>% 
  ungroup() %>% 
  spread(na_item, values)

ulc_ecb_with <- ulc_ecb_dat %>% 
  filter(na_item %in% c("NULC_HW", "NULC_PER")) %>% 
  select(time, geo, na_item, values) %>% 
  mutate(na_item = paste0(na_item, "_ECB")) %>% 
  group_by(geo, na_item) %>% 
  mutate(values = rebase(values, time, base_year)) %>% 
  ungroup() %>% 
  spread(na_item, values)

lc_with <- lc_dat %>% 
  select(time, geo, nulc, nulc_va, nulc_hw, nulc_hw_va, nulc_per, nulc_per_va) %>% 
  left_join(ulc_oecd_with, by = c("time", "geo")) %>% 
  # left_join(ulc_eurostat_with, by = c("time", "geo")) %>%
  left_join(ulc_ecb_with, by = c("time", "geo")) # %>%   filter(geo == "FI") %>% View()

lc_with %>% 
  gather(vars, values, - time, - geo) %>% 
  mutate(vars = fct_relevel(vars, "NULC_APER", after = Inf)) %>% 
  filter(geo == "FI") %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line()
lc_with %>% 
  gather(vars, values, - time, - geo) %>% 
  filter(geo == "CH", vars %in% c("nulc", "nulc_per", "NULC_APER_OECD", "NULC_PER_ECB")) %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line()
lc_with %>% 
  filter(geo == "FI") %>% 
  tail() %>% 
  knitr::kable(digits = 2)
lc_with %>% 
  gather(vars, values, - time, - geo) %>% 
  mutate(vars = fct_relevel(vars, "NULC_APER", after = Inf)) %>% 
  filter(geo == "SE") %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line()

Nominal unit labour cost manufacturing

lc_dat_c <- 
  naq_eurostat_dat %>% 
  filter(nace_r2 == "C") %>% 
  unite(vars, na_item, unit) %>% 
  # filter(vars %in% c("D1_CP_MNAC", "B1G_CLV10_MNAC")) %>% 
  spread(vars, values) %>% 
  group_by(geo) %>% 
  mutate(
    # nominal unit labour cost
    ulc = ind_ulc(D1_CP_MNAC, B1G_CLV10_MNAC, time = time, baseyear = base_years),
    # nominal unit labour cost, adjusted to take account emploees/emplyed share
    ulc_adj = ind_ulc(D1_CP_MNAC / SAL_DC_THS_HW, B1G_CLV10_MNAC / EMP_DC_THS_HW, time = time, baseyear = base_years)) %>% 
  ungroup()

lc_dat_c %>% 
  filter(geo %in% geos,
         time >= start_time) %>% 
  select(geo, time, ulc, ulc_adj) %>% 
  gather(ind, values, -geo, -time) %>% 
  ggplot(aes(time, values, colour = geo)) +
  geom_line() +
  facet_wrap(~ ind)

Hourly compensation

naq_eurostat_dat %>% 
  filter(nace_r2 %in% c("TOTAL", "C")) %>% 
  unite(vars, na_item, unit) %>% 
  # filter(vars %in% c("D1_CP_MNAC", "B1G_CLV10_MNAC")) %>% 
  spread(vars, values) %>% 
  group_by(geo, nace_r2) %>% 
  mutate(comp_h = rebase(D1_CP_MNAC / SAL_DC_THS_HW, time = time, baseyear = base_year),
         d_comp_h = 100 * (comp_h / lag(comp_h, 4) - 1)) %>% 
  ungroup() %>% 
  filter(geo %in% geos,
         time >= start_time) %>% 
  ggplot(aes(time, d_comp_h, colour = geo)) +
  geom_line() +
  facet_wrap(~ nace_r2)
naq_eurostat_dat %>% 
  filter(nace_r2 %in% c("TOTAL", "C")) %>% 
  unite(vars, na_item, unit) %>% 
  # filter(vars %in% c("D1_CP_MNAC", "B1G_CLV10_MNAC")) %>% 
  spread(vars, values) %>% 
  group_by(geo, nace_r2) %>% 
  mutate(comp_h = rebase(D1_CP_MNAC / SAL_DC_THS_HW, time = time, baseyear = base_year),
         d_comp_h = 100 * (comp_h / lag(comp_h, 4) - 1)) %>% 
  ungroup() %>% 
  filter(geo %in% c("FI", "SE"),
         time >= "2010-01-01") %>% 
  ggplot(aes(time, d_comp_h, colour = geo)) +
  geom_line() +
  facet_wrap(~ nace_r2)

Relative nominal unit labour cost

ea_weights <- weights_bis_broad %>% 
  filter(time == max(time),
         geo_base == "FI",
         geo != geo_base,
         geo %in% eurostat::ea_countries$code) %>% 
  filter(geo != "MT") %>% 
  select(geo, weight) %>% 
  mutate(weight = weight / sum(weight))

lc_dat_nace %>% 
  filter(time >= "1995-01-01", time < "2017-12-31", geo %in% ea_weights$geo) %>% 
  left_join(ea_weights, by = "geo") %>% # filter(geo == "FI", is.na(nulc_va))
  group_by(time, nace_r2) %>% # filter(geo == "FI")  %>% select(time, nace_r2, nulc_va)
  # summarise(tt = length(geo))
  summarise(rel_nulc_va = 100 * nulc_va[geo == "FI"] / sum(nulc_va * weight)) %>% 
  ungroup() %>% 
    ggplot(aes(time, rel_nulc_va, colour = nace_r2)) +
  geom_line()

lc_dat_nace %>% 
  filter(time >= "1996-01-01", time < "2018-12-31", geo %in% c(ea_weights$geo, "FI")) %>% 
  left_join(ea_weights, by = "geo") %>% # filter(geo == "FI", is.na(nulc_va))
  filter(nace_r2 == "TOTAL") %>% # summarise(NA_WE = sum(is.na(weight), na_s = sum(is.na(nulc_va))))
  group_by(time) %>% 
  # summarise(tt = length(geo))
  summarise(rel_nulc_va = 100 * weighted_gmean(nulc_va[geo == "FI"]/ nulc_va[geo != "FI"] , weight[geo != "FI"]) ) %>% 
  ungroup() %>% 
      ggplot(aes(time, rel_nulc_va)) +
  geom_line()

myvariable <- c(1,2,3,4) ##Some data to average
myweight <- c(1,1,1,3) 


kk <- lc_dat_nace %>% 
  filter(time >= "1996-01-01", time < "2018-12-31", geo %in% c(ea_weights$geo, "FI")) %>% 
  left_join(ea_weights, by = "geo") %>% # filter(geo == "FI", is.na(nulc_va))
  filter(nace_r2 == "TOTAL", time == "2017-01-01") %>% 
  select(time, geo, nulc_va)



kk_d <- lc_dat_nace %>% 
  filter(geo %in% c(ea_weights$geo, "FI")) %>% 
  filter(nace_r2 == "TOTAL") %>% # summarise(NA_WE = sum(is.na(weight), na_s = sum(is.na(nulc_va))))
  group_by(time) %>% 
  mutate(rel_nulc_va = weight_index(nulc_va, geo, 2015, weights_bis_broad)) %>% 
  ungroup()

kk_d %>% 
  ggplot(aes(time, rel_nulc_va, group = geo)) +
  geom_line()


weight_index(x = kk$nulc_va, kk$geo, 2015, weights_bis_broad)

q_dat %>% 
  # filter(geo %in% c("US", "AU", "SE", "FI")) %>%
  group_by(time) %>% 
  mutate(rel_nulc_aper = weight_index(nulc_aper, geo, 2015, weights_bis_broad)) %>% 
  ungroup() %>% 
  filter(geo == "FI") %>% View()
  ggplot(aes(time, rel_nulc_aper, group = geo)) +
  geom_line()


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