The task at hand is to replicate the charts and graphs that are illustrated in the book titled “”Introductory Macro-econometrics:A New Approach" by David F. Hendry by using R & specifically with the use of Tidyverse package.
Initially we load the macroeconomic data availlable to us in an excel file; one this to note here that the Excel files mentioned in the Preface of the book (QEHistData.xls and UKHist2013.xls) are not available for download; an attempt to contact the publisher of the online version of this book has not bare fruit in this matter either.
We are limited to the data available in the download pack named MacroData15.xlsx – this missing out some of the variable that are used within the book’s illustration.
The following R code loads the neccessary libraries and the data available for use in MacroData15.xlsx.
library(readxl)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.1
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Registered S3 methods overwritten by 'ggplot2':
## method from
## [.quosures rlang
## c.quosures rlang
## print.quosures rlang
library("tidyverse")
## Warning: package 'tidyverse' was built under R version 3.6.1
## -- Attaching packages --------------------------------------- tidyverse 1.2.1 --
## v tibble 2.1.1 v purrr 0.3.2
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## Warning: package 'tidyr' was built under R version 3.6.1
## Warning: package 'readr' was built under R version 3.6.1
## Warning: package 'forcats' was built under R version 3.6.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(gg3D)
library(gtable)
require(gridExtra)
## Loading required package: gridExtra
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
input_data <- read_excel("MacHendryData.xlsx")
summary(input_data)
## years Wr PGDP wages-nominal
## Min. :1870 Min. : 0.4438 Min. :0.02290 Min. : 1.103
## 1st Qu.:1906 1st Qu.: 0.6040 1st Qu.:0.02557 1st Qu.: 1.501
## Median :1941 Median : 1.9027 Median :0.06086 Median : 4.728
## Mean :1941 Mean : 39.1882 Mean :0.41224 Mean : 97.386
## 3rd Qu.:1976 3rd Qu.: 27.9684 3rd Qu.:0.40254 3rd Qu.: 69.504
## Max. :2012 Max. :275.3283 Max. :2.28246 Max. :684.216
## NA's :1 NA's :1 NA's :1 NA's :1
## prices log(wages) log(prices) realwages
## Min. : 0.9834 Min. :0.09799 Min. :-0.01678 Min. :0.003928
## 1st Qu.: 1.0980 1st Qu.:0.40608 1st Qu.: 0.09345 1st Qu.:0.348717
## Median : 2.6135 Median :1.55357 Median : 0.96069 Median :0.713377
## Mean :17.7038 Mean :2.41316 Mean : 1.57055 Mean :0.842609
## 3rd Qu.:17.2869 3rd Qu.:4.23878 3rd Qu.: 2.84759 3rd Qu.:1.387416
## Max. :98.0202 Max. :6.52827 Max. : 4.58517 Max. :1.952003
## NA's :1 NA's :1 NA's :1 NA's :1
## gdp pgdp pw eri
## Min. :10.53 Min. :-3.7767 Min. :-2.8389 Min. :0.2804
## 1st Qu.:11.18 1st Qu.:-3.6636 1st Qu.:-2.5597 1st Qu.:0.9408
## Median :11.70 Median :-2.7770 Median :-2.0111 Median :1.3950
## Mean :11.78 Mean :-2.1790 Mean :-1.6811 Mean :1.2177
## 3rd Qu.:12.47 3rd Qu.:-0.8780 3rd Qu.:-1.1070 3rd Qu.:1.5826
## Max. :13.24 Max. : 0.8253 Max. : 0.3951 Max. :1.7258
## NA's :2 NA's :2 NA's :15 NA's :15
## LPrm RS RL Natdebt
## Min. :1.708 Min. :0.004839 Min. :0.02250 Min. : 628
## 1st Qu.:2.251 1st Qu.:0.024325 1st Qu.:0.03058 1st Qu.: 770
## Median :2.620 Median :0.036150 Median :0.04125 Median : 7822
## Mean :2.844 Mean :0.044639 Mean :0.05129 Mean : 55172
## 3rd Qu.:2.819 3rd Qu.:0.054550 3rd Qu.:0.05880 3rd Qu.: 33442
## Max. :4.644 Max. :0.158800 Max. :0.14950 Max. :434540
## NA's :14 NA's :2 NA's :2 NA's :11
## LNatdebt m LEmpUK LKtotUK
## Min. : 6.443 Min. : 6.332 Min. : 9.438 Min. :5.039
## 1st Qu.: 6.646 1st Qu.: 6.829 1st Qu.: 9.759 1st Qu.:5.755
## Median : 8.965 Median : 8.080 Median :10.045 Median :6.217
## Mean : 9.101 Mean : 8.685 Mean : 9.934 Mean :6.362
## 3rd Qu.:10.418 3rd Qu.: 9.651 3rd Qu.:10.123 3rd Qu.:7.091
## Max. :12.982 Max. :13.131 Max. :10.290 Max. :8.065
## NA's :11 NA's :15 NA's :2 NA's :7
## Rna E pop Un
## Min. :0.004971 Min. :1.298 Min. :3.403 Min. : 63.49
## 1st Qu.:0.015879 1st Qu.:2.172 1st Qu.:3.714 1st Qu.: 392.50
## Median :0.029182 Median :4.031 Median :3.880 Median : 828.14
## Mean :0.034535 Mean :3.544 Mean :3.846 Mean :1153.26
## 3rd Qu.:0.048213 3rd Qu.:4.867 3rd Qu.:4.024 3rd Qu.:1670.50
## Max. :0.113582 Max. :5.617 Max. :4.138 Max. :3400.00
## NA's :15 NA's :5 NA's :5 NA's :2
## wpop RsUS Pcpi LW85
## Min. :13119 Min. :0.00100 Min. :-4.275 Min. :-5.157
## 1st Qu.:18238 1st Qu.:0.03030 1st Qu.:-4.155 1st Qu.:-4.869
## Median :23400 Median :0.04690 Median :-3.260 Median :-3.700
## Mean :22347 Mean :0.04526 Mean :-2.699 Mean :-2.852
## 3rd Qu.:26038 3rd Qu.:0.05660 3rd Qu.:-1.402 3rd Qu.:-1.006
## Max. :31736 Max. :0.14680 Max. : 0.179 Max. : 1.247
## NA's :2 NA's :5 NA's :2 NA's :2
## nh w Dpgdp Dm
## Min. :38.73 Min. :-4.754 Min. :-0.18620 Min. :-0.04392
## 1st Qu.:39.81 1st Qu.:-4.614 1st Qu.:-0.00113 1st Qu.: 0.01445
## Median :42.55 Median :-3.695 Median : 0.02593 Median : 0.03719
## Mean :43.40 Mean :-2.916 Mean : 0.03224 Mean : 0.05298
## 3rd Qu.:47.90 3rd Qu.:-1.912 3rd Qu.: 0.05350 3rd Qu.: 0.09051
## Max. :48.44 Max. : 1.087 Max. : 0.24268 Max. : 0.23538
## NA's :61 NA's :14 NA's :5 NA's :16
## ppp Ur RLr
## Min. :0.2265 Min. :0.002823 Min. :-0.184839
## 1st Qu.:0.4580 1st Qu.:0.019827 1st Qu.: 0.004192
## Median :0.5361 Median :0.044257 Median : 0.028558
## Mean :0.5277 Mean :0.049951 Mean : 0.019469
## 3rd Qu.:0.6020 3rd Qu.:0.073922 3rd Qu.: 0.043737
## Max. :0.7492 Max. :0.153499 Max. : 0.230500
## NA's :15 NA's :4 NA's :13
## Dgdp DUr Ursq
## Min. :-0.104290 Min. :-0.051673 Min. :0.000008
## 1st Qu.: 0.007476 1st Qu.:-0.009136 1st Qu.:0.000360
## Median : 0.024267 Median :-0.000195 Median :0.001281
## Mean : 0.019073 Mean : 0.000108 Mean :0.003761
## 3rd Qu.: 0.035523 3rd Qu.: 0.006516 3rd Qu.:0.005464
## Max. : 0.095381 Max. : 0.090991 Max. :0.023562
## NA's :5 NA's :13 NA's :12
## Dpop Wshare Dpgfna
## Min. :-0.005453 Min. :0.07512 Min. :-0.9999
## 1st Qu.: 0.002995 1st Qu.:0.08149 1st Qu.:-0.8624
## Median : 0.004669 Median :0.09287 Median :-0.5135
## Mean : 0.005251 Mean :0.09151 Mean :-0.5264
## 3rd Qu.: 0.008301 3rd Qu.:0.09940 3rd Qu.:-0.2173
## Max. : 0.011262 Max. :0.12216 Max. :-0.0167
## NA's :16 NA's :15 NA's :16
## DpgfnaDp ulc gdppc ulcp
## Min. :-0.015811 Min. :-6.056 Min. :1.043 Min. :-2.589
## 1st Qu.:-0.014484 1st Qu.:-5.961 1st Qu.:1.352 1st Qu.:-2.507
## Median :-0.009833 Median :-5.320 Median :1.588 Median :-2.377
## Mean :-0.005467 Mean :-4.769 Mean :1.780 Mean :-2.398
## 3rd Qu.: 0.001644 3rd Qu.:-4.309 3rd Qu.:2.294 3rd Qu.:-2.309
## Max. : 0.015811 Max. :-1.890 Max. :2.883 Max. :-2.102
## NA's :16 NA's :15 NA's :4 NA's :15
## ulcpm er RrDg
## Min. :-0.22611 Min. :0.2605 Min. :-0.192027
## 1st Qu.:-0.14462 1st Qu.:0.8965 1st Qu.:-0.024864
## Median :-0.01392 Median :1.3950 Median :-0.001811
## Mean :-0.03567 Mean :1.2223 Mean : 0.000231
## 3rd Qu.: 0.05403 3rd Qu.:1.5826 3rd Qu.: 0.025683
## Max. : 0.26021 Max. :1.7258 Max. : 0.224433
## NA's :15 NA's :15 NA's :13
## DLKtotUK DLEmpUK productivity input
## Min. :0.000266 Min. :-0.125262 Min. :1.077 Min. :-4.454
## 1st Qu.:0.015771 1st Qu.:-0.001733 1st Qu.:1.399 1st Qu.:-4.037
## Median :0.020550 Median : 0.007004 Median :1.655 Median :-3.785
## Mean :0.022250 Mean : 0.005923 Mean :1.850 Mean :-3.577
## 3rd Qu.:0.027236 3rd Qu.: 0.015351 3rd Qu.:2.354 3rd Qu.:-3.033
## Max. :0.064279 Max. : 0.063286 Max. :2.958 Max. :-2.209
## NA's :8 NA's :3 NA's :2 NA's :7
## Dproductivity pro25 gl wshr
## Min. :-0.099807 Min. :1.077 Min. :-0.1038 Min. :-1.1146
## 1st Qu.: 0.003044 1st Qu.:1.375 1st Qu.: 1.3521 1st Qu.:-1.0529
## Median : 0.015448 Median :1.542 Median : 1.5911 Median :-1.0183
## Mean : 0.013168 Mean :1.667 Mean : 1.7815 Mean :-0.9945
## 3rd Qu.: 0.027205 3rd Qu.:1.901 3rd Qu.: 2.2812 3rd Qu.:-0.9812
## Max. : 0.058772 Max. :2.595 Max. : 2.8578 Max. : 1.9431
## NA's :3 NA's :25 NA's :1
## urt
## Min. :-0.00500
## 1st Qu.: 0.01393
## Median : 0.03647
## Mean : 0.04390
## 3rd Qu.: 0.06831
## Max. : 0.14850
## NA's :1
Figure 1.1 Wages and prices over 1860–2011.
df_1 <- input_data %>% select(years, `wages-nominal`, prices) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
ggplot(df_1, aes(x=years, y=value, color=variable)) + geom_line()
Figure 1.2 Log wages and log prices over 1860–2011
df_2 <- input_data %>% select(years, `log(wages)`, 'log(prices)') %>% gather(key = "variable", value = "value", -years) %>% na.omit()
ggplot(df_2, aes(x=years, y=value, color=variable)) + geom_line()
Figure 1.3 Log wages and log prices with one trend line.
df_3 <- transform(df_2, Fitted=fitted(lm(value~years, data = subset(df_2, variable=='log(wages)'))))
## Warning in data.frame(structure(list(years = c(1870, 1871, 1872, 1873,
## 1874, : row names were found from a short variable and have been discarded
ggplot(df_3,aes(x=years,y=value, color=variable )) +
geom_line() +
geom_smooth(data=subset(df_3, variable=='log(wages)'), method='lm',formula=y~x, se=FALSE) +
geom_segment(data=subset(df_3, variable=='log(wages)'), aes(x=years, y=value, xend=years,yend=Fitted)) +
annotate("text", x = 1980, y = 6.5, colour = "black", label = 'log(wages)') +
annotate("segment", x = 1980, xend = 1990, y = 6.3, yend = 5.6, colour = "black", arrow = arrow()) +
annotate("text", x = 1985, y = 1.8, colour = "black", label = 'log(prices)') +
annotate("segment", x = 1990, xend = 1979, y = 2, yend = 3.1, colour = "black", arrow = arrow()) +
annotate("text", x = 1900, y = 3, colour = "black", label = 'regression line with projections') +
annotate("segment", x = 1930, xend = 1950, y = 3, yend = 3, colour = "black", arrow = arrow())
Figure 1.4 Log wages and log prices each with six trend lines.
df1_4 <- df_2 %>% mutate(group = ifelse(years>1850 & years < 1882 , 'A',
ifelse(years>= 1882 & years < 1910 , 'B',
ifelse(years>= 1910 & years < 1935 , 'C',
ifelse(years>= 1935 & years < 1960 , 'D',
ifelse(years>= 1960 & years < 1978 , 'E','F'))))))
ggplot(df1_4,aes(x=years,y=value, color=variable )) +
geom_line() +
geom_smooth(data=subset(df1_4, group == 'A'), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=subset(df1_4, group == 'B'), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=subset(df1_4, group == 'C'), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=subset(df1_4, group == 'D'), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=subset(df1_4, group == 'E'), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=subset(df1_4, group == 'F'), method='lm',formula=y~x, se=FALSE)
Figure 1.5 Log real wages, w − p, over 1860–2011.
df1_5 <- input_data %>% select(years, `log(wages)`, `log(prices)`) %>% mutate(real_wages=`log(wages)`-`log(prices)`) %>% na.omit()
ggplot(df1_5, aes(x=years, y=real_wages)) + geom_line() +
annotate("text", x = 1908, y = 1.55, colour = "black", label="1914") +
annotate("segment", x = 1914, xend = 1914, y = 0, yend = 1.5, colour = "black") +
annotate("text", x = 1920, y = 1.55, colour = "black", label="1918") +
annotate("segment", x = 1918, xend = 1918, y = 0, yend = 1.5, colour = "black") +
annotate("segment", x = 1939, xend = 1939, y = 0, yend = 1.5, colour = "black") +
annotate("segment", x = 1945, xend = 1945, y = 0, yend = 1.5, colour = "black") +
annotate("segment", x = 1973, xend = 1973, y = 0, yend = 1.5, colour = "black")
Figure 1.6 Log real wages with one trend line.
df1_6 <- df1_5 %>% na.omit() %>% mutate(Fitted = fitted(lm(real_wages ~ years)))
ggplot(df1_6, aes(x=years, y=real_wages)) + geom_line() +
geom_smooth(method='lm', se=FALSE) +
geom_segment(aes(x=years, y=real_wages, xend=years, yend=Fitted)) +
annotate("segment", x = 1960, xend = 1987, y = 1.6, yend = 1.6, colour = "black", arrow=arrow())+
annotate("text", x = 1950, y = 1.6, colour = "black", label='real wages')
Figure 1.7 Log real wages with 4 regressions.
df1_7 <- df1_5 %>% mutate(group = ifelse(years < 1900, 'A',
ifelse(years>= 1900 & years < 1935, 'B',
ifelse(years >= 1935 & years < 1970, 'C', 'D')))) %>% mutate(
Fitted = ifelse(group =='A', fitted(lm(real_wages ~ years, data = subset(df1_5, group == 'A'))),
ifelse(group =='B', fitted(lm(real_wages ~ years, data = subset(df1_5, group == 'B'))),
ifelse(group =='C', fitted(lm(real_wages ~ years, data = subset(df1_5, group == 'C'))),
fitted(lm(real_wages ~ years, data = subset(df1_5, group == 'D'))))))) %>% na.omit()
ggplot(df1_7, aes(x=years, y=real_wages)) + geom_line() +
geom_smooth(data=subset(df1_7, group=='A'),method='lm', se=FALSE) +
geom_smooth(data=subset(df1_7, group=='B'),method='lm', se=FALSE) +
geom_smooth(data=subset(df1_7, group=='C'),method='lm', se=FALSE) +
geom_smooth(data=subset(df1_7, group=='D'),method='lm', se=FALSE) +
annotate("text", x = 1950, y = 1.6, colour = "black", label='real wages')
Figure 1.8 ‘Production function’ over 1860–2011
df1_8 <- input_data %>% select(years, gl, input) %>% na.omit() %>% mutate(Fitted = fitted(lm(gl~input)))
ggplot(df1_8, aes(y=gl, x=input)) +
geom_point(colour='brown') +
geom_smooth(method = 'lm', se=FALSE) +
geom_segment(aes(y=gl, yend=Fitted, x=input, xend=input))
Figure 1.9 3-dimensional ‘production function’ over 1860–2011.
ggplot(df1_8, aes(x=input, y=gl, z=years)) + axes_3D(theta=30, phi=0) + stat_3D()
Figure 1.10 Log levels and changes in: days lost through strikes; National Insurance Contributions (NICs); Trades Unions membership (TU); and replacement ratios.
The data for days lost to strikes is not available to us…
Figure 1.11 Log real wages and log average productivity over 1860–2011.
df1_11 <- input_data %>% select(years, realwages, productivity) %>% na.omit() %>% mutate(lrw = log(realwages), lprod = log(productivity)) %>% select(years, realwages, lprod) %>% gather(key = "variable", value = "value", -years)
ggplot(df1_11, aes(x=years, y=value, color=variable)) + geom_line()
Figure 1.12 Changes in average productivity ∆(1 − l)t over 1860–2011.
df1_12 <- input_data %>% select(years, productivity) %>% na.omit() %>% mutate(DProd = diff(c(NA,productivity))) %>% na.omit()
ggplot(df1_12, aes(x=years, y=DProd)) + geom_line() + annotate("segment", x = 1870, xend = 2011, y = 0, yend = 0, colour = "black", linetype=2)
Figure 1.13 Normal distribution with mean E[t] 0 and variance E[2t ] σ2 1.
ggplot(data = data.frame(x = c(-5, 5), y = c(0,0.5)), aes(x, y)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 0, sd = 1)) + ylab("") +
annotate("segment", x = -2, xend = -2, y = 0, yend = 0.05, colour = "black", linetype=2) +
annotate("segment", x = 2, xend = 2, y = 0, yend = 0.05, colour = "black", linetype=2)+
annotate("text", x = 0, y = 0.05, colour = "black", label="95% of the distribution \nlies between -2σ' and 2σ")
Figure 1.14 Histograms and densities of wt, pt, 1t and lt, shaded pre-WWII.
df1_14 <- input_data %>% select(years, 'log(wages)', 'log(prices)', gdp, LEmpUK) %>% mutate(log_gdp = log(gdp)) %>% na.omit()
summary(df1_14)
## years log(wages) log(prices) gdp
## Min. :1870 Min. :0.09799 Min. :-0.01678 Min. :10.53
## 1st Qu.:1905 1st Qu.:0.40447 1st Qu.: 0.09315 1st Qu.:11.18
## Median :1940 Median :1.53711 Median : 0.94947 Median :11.70
## Mean :1940 Mean :2.38418 Mean : 1.54933 Mean :11.78
## 3rd Qu.:1976 3rd Qu.:4.10777 3rd Qu.: 2.71818 3rd Qu.:12.47
## Max. :2011 Max. :6.50423 Max. : 4.57126 Max. :13.24
## LEmpUK log_gdp
## Min. : 9.438 Min. :2.354
## 1st Qu.: 9.759 1st Qu.:2.414
## Median :10.045 Median :2.460
## Mean : 9.934 Mean :2.464
## 3rd Qu.:10.123 3rd Qu.:2.524
## Max. :10.290 Max. :2.583
p1_14_3 <- ggplot(df1_14) + geom_histogram(data=subset(df1_14, years<1940), aes(x = log_gdp), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_14, years<1940), aes(x=log_gdp), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years<1940)$log_gdp), sd = sd(subset(df1_14, years<1940)$log_gdp)))+
geom_histogram(data=subset(df1_14, years>=1940), aes(x = log_gdp), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_14, years>=1940), aes(x=log_gdp), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years>=1940)$log_gdp), sd = sd(subset(df1_14, years>=1940)$log_gdp)))
p1_14_2 <- ggplot(df1_14) + geom_histogram(data=subset(df1_14, years<1940), aes(x = `log(prices)`), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_14, years<1940), aes(x=`log(prices)`), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years<1940)$`log(prices)`), sd = sd(subset(df1_14, years<1940)$`log(prices)`)))+
geom_histogram(data=subset(df1_14, years>=1940), aes(x = `log(prices)`), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_14, years>=1940), aes(x=`log(prices)`), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years>=1940)$`log(prices)`), sd = sd(subset(df1_14, years>=1940)$`log(prices)`)))
p1_14_1 <- ggplot(df1_14) + geom_histogram(data=subset(df1_14, years<1940), aes(x = `log(wages)`), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_14, years<1940), aes(x=`log(wages)`), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years<1940)$`log(wages)`), sd = sd(subset(df1_14, years<1940)$`log(wages)`)))+
geom_histogram(data=subset(df1_14, years>=1940), aes(x = `log(wages)`), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_14, years>=1940), aes(x=`log(wages)`), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years>=1940)$`log(wages)`), sd = sd(subset(df1_14, years>=1940)$`log(wages)`)))
p1_14_4 <- ggplot(df1_14) + geom_histogram(data=subset(df1_14, years<1940), aes(x = LEmpUK), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_14, years<1940), aes(x=LEmpUK), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years<1940)$LEmpUK), sd = sd(subset(df1_14, years<1940)$LEmpUK)))+
geom_histogram(data=subset(df1_14, years>=1940), aes(x = LEmpUK), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_14, years>=1940), aes(x=LEmpUK), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_14, years>=1940)$LEmpUK), sd = sd(subset(df1_14, years>=1940)$LEmpUK)))
grid.arrange(p1_14_1, p1_14_2, p1_14_3, p1_14_4, ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Figure 1.15 Histograms and densities of ∆wt, ∆pt, ∆1t and ∆lt, shaded pre-WWII.
df1_15 <- input_data %>% select(years, 'log(wages)', 'log(prices)', gdp, LEmpUK) %>% mutate(Dlgdp = diff(c(NA, log(gdp))), Dlwages = diff(c(NA, `log(wages)`)), Dlprices = diff(c(NA, `log(prices)`)), Dlemp = diff(c(NA, LEmpUK))) %>% na.omit()
p1_15_3 <- ggplot(df1_15) + geom_histogram(data=subset(df1_15, years<1940), aes(x = Dlgdp), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_15, years<1940), aes(x=Dlgdp), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years<1940)$Dlgdp), sd = sd(subset(df1_15, years<1940)$Dlgdp)))+
geom_histogram(data=subset(df1_15, years>=1940), aes(x = Dlgdp), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_15, years>=1940), aes(x=Dlgdp), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years>=1940)$Dlgdp), sd = sd(subset(df1_15, years>=1940)$Dlgdp)))
p1_15_2 <- ggplot(df1_15) + geom_histogram(data=subset(df1_15, years<1940), aes(x = Dlprices), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_15, years<1940), aes(x=Dlprices), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years<1940)$Dlprices), sd = sd(subset(df1_15, years<1940)$Dlprices)))+
geom_histogram(data=subset(df1_15, years>=1940), aes(x = Dlprices), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_15, years>=1940), aes(x=Dlprices), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years>=1940)$Dlprices), sd = sd(subset(df1_15, years>=1940)$Dlprices)))
p1_15_1 <- ggplot(df1_15) + geom_histogram(data=subset(df1_15, years<1940), aes(x = Dlwages), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_15, years<1940), aes(x=Dlwages), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years<1940)$Dlwages), sd = sd(subset(df1_15, years<1940)$Dlwages)))+
geom_histogram(data=subset(df1_15, years>=1940), aes(x = Dlwages), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_15, years>=1940), aes(x=Dlwages), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years>=1940)$Dlwages), sd = sd(subset(df1_15, years>=1940)$Dlwages)))
p1_15_4 <- ggplot(df1_15) + geom_histogram(data=subset(df1_15, years<1940), aes(x = Dlemp), fill = "red", alpha = 0.2) +
geom_density(data=subset(df1_15, years<1940), aes(x=Dlemp), color="red") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years<1940)$Dlemp), sd = sd(subset(df1_15, years<1940)$Dlemp)))+
geom_histogram(data=subset(df1_15, years>=1940), aes(x = Dlemp), fill = "blue", alpha = 0.2) +
geom_density(data=subset(df1_15, years>=1940), aes(x=Dlemp), color="blue") +
stat_function(fun = dnorm, args = list(mean = mean(subset(df1_15, years>=1940)$Dlemp), sd = sd(subset(df1_15, years>=1940)$Dlemp)))
grid.arrange(p1_15_1, p1_15_2, p1_15_3, p1_15_4, ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Figure 1.16 Time series of (m − 1 − p)t, (N=(PG))t, RL;t and RS;t, and pppt.
df1_16 <- input_data %>% select(years, m, prices, gdp, Natdebt, RL, RS, ppp) %>% mutate(mgp = m-gdp-prices, nPG = log(Natdebt/(gdp*prices))) %>% na.omit()
p1_16_1 <- ggplot(df1_16, aes(x=years, y=mgp)) + geom_line()
p1_16_2 <- ggplot(df1_16, aes(x=years, y=nPG)) + geom_line()
p1_16_3 <- ggplot(df1_16, aes(x=years, y=RL)) + geom_line()
p1_16_4 <- ggplot(df1_16, aes(x=years, y=ppp)) + geom_line()
grid.arrange(p1_16_1, p1_16_2, p1_16_3, p1_16_4, ncol = 2)
Figure 2.1 (a) Annual wages and prices; (b) wage and price changes; (c) real wages and productivity; (d) changes in real wages, all over 1860–1900.
df2_1_1 <- input_data %>% select(years, `wages-nominal`, prices) %>% filter(years < 1901) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_1_1 <- ggplot(df2_1_1, aes(x=years, y=value, group=variable)) + geom_line(aes(linetype = variable, color = variable)) + scale_linetype_manual(values=c("dashed", "solid")) + theme(legend.position = "none")
df2_1_2 <- input_data %>% select(years, `wages-nominal`, prices) %>% filter(years < 1901) %>% mutate(dw = diff(c(NA,`wages-nominal`)), dp = diff(c(NA,prices))) %>% select(years, dw, dp) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_1_2 <- ggplot(df2_1_2, aes(x=years, y=value, group=variable)) + geom_line(aes(linetype = variable, color = variable)) + scale_linetype_manual(values=c("dashed", "solid")) + theme(legend.position = "none")
df2_1_3 <- input_data %>% select(years, realwages, productivity) %>% filter(years < 1901) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_1_3 <- ggplot(df2_1_3, aes(x=years, y=value, group=variable)) + geom_line(aes(linetype = variable, color = variable)) + scale_linetype_manual(values=c("dashed", "solid")) + theme(legend.position = "none")
df2_1_4 <- input_data %>% select(years, `wages-nominal`, prices) %>% filter(years < 1901) %>% filter(years < 1901) %>% mutate(dWmP=diff(c(NA, `wages-nominal`-prices))) %>% na.omit()
p2_1_4 <- ggplot(df2_1_4, aes(x=years, y=dWmP)) + geom_line()
grid.arrange(p2_1_1, p2_1_2, p2_1_3, p2_1_4, ncol = 2)
Figure 2.2 Annual wage and price ination over 1860–2011.
df2_2 <- input_data %>% select(years, `log(wages)`, `log(prices)`) %>% mutate(dw = diff(c(NA,`log(wages)`)), dp = diff(c(NA, `log(prices)`))) %>% select(years, dw, dp) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
ggplot(df2_2, aes(x=years, y=value, group=variable)) + geom_line(aes(linetype = variable, color = variable)) + scale_linetype_manual(values=c("dashed", "solid"))
Figure 2.3 Real-wage growth over 1860–2011 with sub-sample means.
df2_3 <- input_data %>% select(years, `log(wages)`, `log(prices)`) %>% mutate(dWmP=diff(c(0, `log(wages)` - `log(prices)`))) %>% na.omit()
ggplot(df2_3, aes(x=years, y=dWmP)) + geom_line() +
geom_segment(data=subset(df2_3, years<1945),aes(x=1860, y=mean(dWmP), xend=1944, yend=mean(dWmP))) +
geom_segment(data=subset(df2_3, years>=1945),aes(x=1945, y=mean(dWmP), xend=2010, yend=mean(dWmP)))
Figure 2.4 Real annual GDP growth per worker by 25-year intervals.
df2_4 <- input_data %>% select(years, gl) %>% filter(years < 2010) %>% mutate(dgdp25=c(rep(NA, 25), diff(gl/25, 25))) %>% na.omit()
ggplot(df2_4, aes(x=years, y=dgdp25)) + geom_line() +
annotate("segment", x = 1880, xend = 1950, y = 0.007, yend = 0.007, colour = "black")+
annotate("segment", x = 1880, xend = 2010, y = 0.013, yend = 0.013, colour = "black")+
annotate("segment", x = 1950, xend = 2010, y = 0.022, yend = 0.022, colour = "black")
Figure 2.5 Growth rates of employment and capital stock over 1860–2011.
df2_5_1 <- input_data %>% select (years, LEmpUK) %>% na.omit() %>% mutate(dl=c(0, diff(LEmpUK)))
p2_5_1 <- ggplot(df2_5_1, aes(x=years, y=dl)) + geom_line() + ylim(-0.125, 0.060)
df2_5_2 <- input_data %>% select (years, LKtotUK) %>% na.omit() %>% mutate(dk=c(0, diff(LKtotUK)))
p2_5_2 <- ggplot(df2_5_2, aes(x=years, y=dk)) + geom_line() + ylim(-0.125, 0.060)
grid.arrange(p2_5_1, p2_5_2, ncol = 2)
Figure 2.6 Taming trends in wages.
df2_6_1 <- input_data %>% select(years, `wages-nominal`, prices) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_6_1 <- ggplot(df2_6_1, aes(x=years, y=value, color=variable)) + geom_line()
df2_6_2 <- input_data %>% select(years, `log(wages)`, 'log(prices)') %>% mutate(dwp = c(0, diff(`log(wages)` - `log(prices)` ))) %>% na.omit()
p2_6_2 <- ggplot(df2_6_2, aes(x=years, y=dwp)) + geom_line()
grid.arrange(p2_6_1, p2_6_2, ncol = 2)
Figure 2.7 ‘Wage share’ (w − p − 1 + l)t over 1860–2011.
df2_7_1 <- input_data %>% select(years, Wshare) %>% na.omit()
ggplot(df2_7_1, aes(x=years, y=Wshare, color="red")) + geom_line()
Figure 2.8 Exchange rate, prices and purchasing power parity, pppt.
df2_8_1 <- input_data %>% select(years, er) %>% na.omit()
p2_8_1 <- ggplot(df2_8_1, aes(x=years, y=er)) + geom_line()
df2_8_2 <- input_data %>% select(years, pw, Pcpi) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_8_2 <- ggplot(df2_8_2, aes(x=years, y=value, color=variable)) + geom_line()
df2_8_3 <- input_data %>% select(years, ppp) %>% na.omit()
p2_8_3 <- ggplot(df2_8_3, aes(x=years, y=ppp)) + geom_line()
grid.arrange(p2_8_1, p2_8_2, p2_8_3, ncol = 3)
Figure 2.9 Interest rates and spread over 1860–2011
df2_9_1 <- input_data %>% select(years, RL, RS) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_9_1 <- ggplot(df2_9_1, aes(x=years, y=value, color=variable)) + geom_line()
df2_9_2 <- input_data %>% select(years, prices, RL, RS) %>% mutate(spread = RL-RS) %>% na.omit()
p2_9_2 <- ggplot(df2_9_2, aes(x=years, y=spread)) + geom_line()
grid.arrange(p2_9_1, p2_9_2, ncol = 1)
Figure 2.10 Wage ination and institutional regimes.
df2_10 <- input_data %>% select(years, w) %>% mutate(dw = c(0,diff(w))) %>% na.omit()
ggplot(df2_10, aes(x=years, y=dw)) + geom_line(color="blue") + scale_x_continuous(breaks=seq(1860,2010,20))+
theme(panel.grid.major.x = element_blank(), panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.x = element_blank(), panel.grid.minor.y = element_blank()) +
theme(axis.line.x = element_line(color="black", size = 1),
axis.line.y = element_line(color="black", size = 1)) +
geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_vline(xintercept = 1914) + geom_vline(xintercept = 1918) + geom_vline(xintercept = 1922) +
geom_vline(xintercept = 1940) + geom_vline(xintercept = 1944) + geom_vline(xintercept = 1970) + geom_vline(xintercept = 1992) +
annotate("text", x = 1890, y = -.05, colour = "black", hjust = 0, size = 3, label="Pre-WW1: sliding scales popular in \nmany industries so wages change with \nprices. Union strength fairly limited.") +
annotate("text", x = 1900, y = .2, colour = "black", hjust = 0, size = 3, label="WW1: shift in government \nregulating wages.") +
annotate("text", x = 1919, y = .3, colour = "black", hjust = 0, size = 3, label="1918-1922: wages closely\nindexed to cost of living") +
annotate("text", x = 1940, y = .25, colour = "black", size = 3, label="1940") +
annotate("text", x = 1945, y = .2, colour = "black", hjust = 0, size = 3, label="Post-war reconstruction:\nLow unemployment,\nnational wage\nbargaining, incomes\npolicies, supplements\nfor earnings drift.") +
annotate("text", x = 1970, y = .3, colour = "black", hjust = 0, size = 3, label="1970s onwards:bargaining shifted towards\ndecentralisation. Strikes\nin unionised sectors and\ndecline in trade union power.") +
annotate("text", x = 1923, y = -0.15, colour = "black", hjust = 0, size = 3, label="Inter-war: wage rigidity - workers had more power\nin wage bargaining; minimum wage from indexation\nrules; insurance system reducing sensitivity to\nunemployment.") +
annotate("text", x = 1945, y = -0.05, colour = "black", hjust = 0, size = 3, label="WWII: centralised wage setting indexed to cost of\n living. 1940 - sharp rise in cost of living and wages,\n led to rationing to control cost of living and wages.") +
annotate("text", x = 1996, y = .1, colour = "black", hjust = 0, size = 3, label="Leave ERM")
Figure 2.11 UK wage ination location shifts over 1860–2011.
df2_11 <- input_data %>% select(years, w) %>% mutate(dw = c(0,diff(w))) %>% na.omit()
ggplot(df2_11, aes(x=years, y=dw)) + geom_line(color="blue") + scale_x_continuous(breaks=seq(1860,2010,20))+
theme(panel.grid.major.x = element_blank(), panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.x = element_blank(), panel.grid.minor.y = element_blank()) +
theme(axis.line.x = element_line(color="black", size = 1),
axis.line.y = element_line(color="black", size = 1)) +
geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_segment(data=filter(df2_11, years<1914),aes(x=1860, y=mean(dw), xend=1913, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1914 & years <=1920),aes(x=1914, y=mean(dw), xend=1920, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1921 & years <=1923),aes(x=1921, y=mean(dw), xend=1923, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1924 & years <=1938),aes(x=1924, y=mean(dw), xend=1938, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1939 & years <=1945),aes(x=1939, y=mean(dw), xend=1945, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1946 & years <=1968),aes(x=1946, y=mean(dw), xend=1968, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1969 & years <=1981),aes(x=1969, y=mean(dw), xend=1981, yend=mean(dw))) +
geom_segment(data=filter(df2_11, years>=1982 & years <=2011),aes(x=1982, y=mean(dw), xend=2011, yend=mean(dw)))
Figure 2.12 Data unavailable —
Figure 2.13 Evidence of real-wage co-breaking.
df2_13_1 <- input_data %>% select(years, `log(wages)`, `log(prices)`) %>% mutate(dw = diff(c(NA,`log(wages)`)), dp = diff(c(NA, `log(prices)`))) %>% select(years, dw, dp) %>% gather(key = "variable", value = "value", -years) %>% na.omit()
p2_13_1 <- ggplot(df2_13_1, aes(x=years, y=value, group=variable)) + geom_line(aes(linetype = variable, color = variable)) +
scale_linetype_manual(values=c("dashed", "solid")) + ylim(-0.20, 0.27)
df2_13_2 <- input_data %>% select(years, `log(wages)`, `log(prices)`) %>% mutate(dWmP=diff(c(0, `log(wages)` - `log(prices)`))) %>% na.omit()
p2_13_2 <- ggplot(df2_13_2, aes(x=years, y=dWmP)) + geom_line() + ylim(-0.20, 0.27)
grid.arrange(p2_13_1, p2_13_2, ncol = 2)
Figure 2.14 Non-linear transformations
fun_xsq <- function(x) {x ^ 2}
p2_14_1 <- ggplot(data.frame(x = c(-3:3)), aes(x)) + stat_function(fun = fun_xsq, geom = "line")
fun_xqb <- function(x) {x ^ 3}
p2_14_2 <- ggplot(data.frame(x = c(-3:3)), aes(x)) + stat_function(fun = fun_xqb, geom = "line")
fun_emx <- function(x) {x*exp(-abs(x))}
p2_14_3 <- ggplot(data.frame(x = c(-3:3)), aes(x)) + stat_function(fun = fun_emx, geom = "line")
grid.arrange(p2_14_1, p2_14_2, p2_14_3, ncol = 3)
Figure 3.1 Many aggregate economic time series.
df3_1 <- input_data %>% select(years, pop, w, gdp, ulc, LKtotUK, LEmpUK ) %>%
gather(key = "variable", value = "value", -years) %>% na.omit() %>%
group_by(variable) %>%
mutate_at(vars(value), funs(.- mean(.)))
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once per session.
ggplot(df3_1, aes(x=years, y=value, color=variable)) + geom_line()
#3.1 as seniors did it in Oxmetrics..
df3_1_2 <- input_data %>% select(years, realwages, pgdp, `log(prices)`, LEmpUK, LKtotUK ) %>%
gather(key = "variable", value = "value", -years) %>% na.omit()
ggplot(df3_1_2, aes(x=years, y=value, color=variable)) + geom_line()
Figure 3.2 Scatter plots of economic variables.
df3_2 <- input_data %>% select(years, W=`wages-nominal`, P=prices, p=`log(prices)`, w=`log(wages)`, g=gdp, k=LKtotUK, l=LEmpUK, pop) %>% na.omit()
p3_2_1 <- ggplot(df3_2, aes(x=p, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_2 <- ggplot(df3_2, aes(x=P, y=W, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_3 <- ggplot(df3_2, aes(x=g, y=k, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_4 <- ggplot(df3_2, aes(x=l, y=pop, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_5 <- ggplot(df3_2, aes(x=k, y=pop, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_6 <- ggplot(df3_2, aes(x=g, y=l, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_7 <- ggplot(df3_2, aes(x=g, y=pop, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_8 <- ggplot(df3_2, aes(x=l, y=k, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_9 <- ggplot(df3_2, aes(x=pop, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_10 <- ggplot(df3_2, aes(x=g, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_11 <- ggplot(df3_2, aes(x=k, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_12 <- ggplot(df3_2, aes(x=l, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_13 <- ggplot(df3_2, aes(x=p, y=l, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_14 <- ggplot(df3_2, aes(x=p, y=k, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_15 <- ggplot(df3_2, aes(x=p, y=g, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_2_16 <- ggplot(df3_2, aes(x=p, y=pop, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
grid.arrange(p3_2_1,p3_2_2,p3_2_3,p3_2_4,p3_2_5,p3_2_6,p3_2_7,p3_2_8,p3_2_9,p3_2_10,p3_2_11,p3_2_12,p3_2_13,p3_2_14,p3_2_15,p3_2_16, ncol=4)
Figure 3.3 Plots of xt against its lagged value xt−1.
df3_3 <- input_data %>% select( p=`log(prices)`, w=`log(wages)`, g=gdp, k=LKtotUK, l=LEmpUK ) %>% mutate(`w-p` = w-p) %>%
gather(key = "variable", value = "value") %>% na.omit()
p3_3_1 <- df3_3 %>% filter(variable=="p") %>% select( p = value) %>% mutate(Dif_1 = c(0,diff(p, 1))) %>% ggplot(aes(x=Dif_1, y=p, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_3_2 <- df3_3 %>% filter(variable=="w") %>% select( w = value) %>%mutate(Dif_1 = c(0,diff(w, 1))) %>% ggplot(aes(x=Dif_1, y=w, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_3_3 <- df3_3 %>% filter(variable=="g") %>% select( g = value) %>%mutate(Dif_1 = c(0,diff(g, 1))) %>% ggplot(aes(x=Dif_1, y=g, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_3_4 <- df3_3 %>% filter(variable=="k") %>% select( k = value) %>%mutate(Dif_1 = c(0,diff(k, 1))) %>% ggplot(aes(x=Dif_1, y=k, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_3_5 <- df3_3 %>% filter(variable=="l") %>% select( l = value) %>%mutate(Dif_1 = c(0,diff(l, 1))) %>% ggplot(aes(x=Dif_1, y=l, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
p3_3_6 <- df3_3 %>% filter(variable=="w-p") %>% select( `w-p` = value) %>%mutate(Dif_1 = c(0,diff(`w-p`, 1))) %>% ggplot(aes(x=Dif_1, y=`w-p`, color="red", alpha=0.5)) + geom_point() + theme(legend.position = "none")
grid.arrange(p3_3_1,p3_3_2,p3_3_3,p3_3_4,p3_3_5,p3_3_6, ncol=2)
Figure 3.4 Correlograms of levels of variables.
p3_4_1 <- df3_3 %>% filter(variable=="p") %>% select(p=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, p=acf) %>%
ggplot(mapping = aes(x = lag, y = p)) +
geom_bar(stat = "identity", position = "identity")
p3_4_2 <- df3_3 %>% filter(variable=="w") %>% select(w=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, w=acf) %>%
ggplot(mapping = aes(x = lag, y = w)) +
geom_bar(stat = "identity", position = "identity")
p3_4_3 <- df3_3 %>% filter(variable=="k") %>% select(k=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, k=acf) %>%
ggplot(mapping = aes(x = lag, y = k)) +
geom_bar(stat = "identity", position = "identity")
p3_4_4 <- df3_3 %>% filter(variable=="g") %>% select(g=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, g=acf) %>%
ggplot(mapping = aes(x = lag, y = g)) +
geom_bar(stat = "identity", position = "identity")
p3_4_5 <- df3_3 %>% filter(variable=="l") %>% select(l=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, l=acf) %>%
ggplot(mapping = aes(x = lag, y = l)) +
geom_bar(stat = "identity", position = "identity")
p3_4_6 <- df3_3 %>% filter(variable=="w-p") %>% select(`w-p`=value) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, `w-p`=acf) %>%
ggplot(mapping = aes(x = lag, y = "w-p")) +
geom_bar(stat = "identity", position = "identity")
grid.arrange(p3_4_1,p3_4_2,p3_4_3,p3_4_4,p3_4_5,p3_4_6, ncol=2)
Figure 3.5 Correlograms of dierences of variables.
p3_5_1 <- df3_3 %>% filter(variable=="p") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(p=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, Dp=acf) %>%
ggplot(mapping = aes(x = lag, y = Dp)) +
geom_bar(stat = "identity", position = "identity")
p3_5_2 <- df3_3 %>% filter(variable=="w") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(w=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, Dw=acf) %>%
ggplot(mapping = aes(x = lag, y = Dw)) +
geom_bar(stat = "identity", position = "identity")
p3_5_3 <- df3_3 %>% filter(variable=="k") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(k=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, Dk=acf) %>%
ggplot(mapping = aes(x = lag, y = Dk)) +
geom_bar(stat = "identity", position = "identity")
p3_5_4 <- df3_3 %>% filter(variable=="g") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(g=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, Dg=acf) %>%
ggplot(mapping = aes(x = lag, y = Dg)) +
geom_bar(stat = "identity", position = "identity")
p3_5_5 <- df3_3 %>% filter(variable=="l") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(l=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, Dl=acf) %>%
ggplot(mapping = aes(x = lag, y = Dl)) +
geom_bar(stat = "identity", position = "identity")
p3_5_6 <- df3_3 %>% filter(variable=="w-p") %>% mutate(diff_val = c(0,diff(value,1))) %>% select(`w-p`=diff_val) %>% acf(plot = FALSE) %>% with(data.frame(lag,acf)) %>%
select(lag, `D(w-p)`=acf) %>%
ggplot(mapping = aes(x = lag, y = "D(w-p)")) +
geom_bar(stat = "identity", position = "identity")
grid.arrange(p3_5_1,p3_5_2,p3_5_3,p3_5_4,p3_5_5,p3_5_6, ncol=2)
Figure 3.6 Many correlations between dierences.
Figure 3.7 UK unemployment, 1860–2011, with major events aecting it.
df3_7 <- input_data %>% select(years, Ur) %>% na.omit()
ggplot(df3_7, aes(x=years, y=Ur)) + geom_line(color="blue") + scale_x_continuous(breaks=seq(1860,2010,20))+
theme(panel.grid.major.x = element_blank(), panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.x = element_blank(), panel.grid.minor.y = element_blank()) +
theme(axis.line.x = element_line(color="black", size = 1),
axis.line.y = element_line(color="black", size = 1)) +
geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_segment(data=filter(df3_7, years<1920),aes(x=1860, y=mean(Ur), xend=1920, yend=mean(Ur))) +
geom_segment(data=filter(df3_7, years>=1920 & years <=1940),aes(x=1920, y=mean(Ur), xend=1940, yend=mean(Ur))) +
geom_segment(data=filter(df3_7, years>=1940 & years <=1980),aes(x=1940, y=mean(Ur), xend=1980, yend=mean(Ur))) +
geom_segment(data=filter(df3_7, years>=1980),aes(x=1980, y=mean(Ur), xend=2011, yend=mean(Ur))) +
annotate("text", x = 1875, y = 0.02, colour = "black", hjust = 0, size = 3, label="Boer War") +
annotate("text", x = 1895, y = 0.01, colour = "black", hjust = 0, size = 3, label="WWI") +
annotate("text", x = 1910, y = 0.12, colour = "black", hjust = 0, size = 3, label="US Crash") +
annotate("text", x = 1935, y = 0.15, colour = "black", hjust = 0, size = 3, label="Leave Gold Standard") +
annotate("text", x = 1923, y = 0.025, colour = "black", hjust = 0, size = 3, label="Postwar\nCras") +
annotate("text", x = 1945, y = 0.065, colour = "black", hjust = 0, size = 3, label="WWII") +
annotate("text", x = 1950, y = 0.002, colour = "black", hjust = 0, size = 3, label="Postwar reconstruction") +
annotate("text", x = 1980, y = 0.02, colour = "black", hjust = 0, size = 3, label="Oil crisis") +
annotate("text", x = 1983, y = 0.05, colour = "black", hjust = 0, size = 3, label="Mrs T") +
annotate("text", x = 1996, y = 0.10, colour = "black", hjust = 0, size = 3, label="Leave\nERM") +
annotate("text", x = 1993, y = 0.040, colour = "black", hjust = 0, size = 3, label="Financial\ncrisis")
Figure 3.8 Replicating the original Phillips curve, 1860–1913.
df3_8 <- input_data %>% filter(years<= 1913) %>% mutate(Dw = c(0,diff(`log(wages)`))) %>% select(Dw, Ur) %>% na.omit()
ggplot(df3_8, aes(x=Ur, y=Dw)) + geom_point(color="blue") + geom_smooth(data=df3_8, method='auto',formula=y~x, se=FALSE) + geom_hline(yintercept = 0, linetype="dashed", color="red")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Figure 3.9 Shifts in ination-unemployment ‘trade-o’.
df3_9 <- input_data %>% mutate(Dw = c(0,diff(`log(wages)`))) %>% select(Dw, Ur, years) %>% na.omit()
ggplot(df3_9, aes(x=Ur, y=Dw, label = years)) +
geom_text(aes(label=years)) + geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_smooth(data=filter(df3_9, years <= 1913), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_9, years > 1913 & years <= 1945), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_9, years > 1945 & years <= 1980), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_9, years > 1980 ), method='lm',formula=y~x, se=FALSE)
Figure 3.10 Shifts in the real-wage change-unemployment relation.
df3_10 <- input_data %>% mutate(dwp = `log(wages)` - log(`prices`)) %>% mutate(`D(w-p)` = c(0,diff(dwp))) %>% select(`D(w-p)`, Ur, years) %>% na.omit()
ggplot(df3_10, aes(x=Ur, y=`D(w-p)`, label = years)) +
geom_text(aes(label=years)) + geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_smooth(data=filter(df3_10, years <= 1913), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_10, years > 1913 & years <= 1945), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_10, years > 1945 & years <= 1980), method='lm',formula=y~x, se=FALSE) +
geom_smooth(data=filter(df3_10, years > 1980 ), method='lm',formula=y~x, se=FALSE)
Figure 3.11 Changes in real wages versus changes in productivity.
df3_11 <- input_data %>% mutate(dwp = `log(wages)` - log(`prices`)) %>% mutate(`D(w-p)` = c(0,diff(dwp)), `D(g-l)`=c(0,diff(gl))) %>% select(`D(w-p)`, `D(g-l)`, years) %>% na.omit() %>% filter(years < 2012)
ggplot(df3_11, aes(x=`D(g-l)`, y=`D(w-p)`, label = years)) +
geom_text(aes(label=years)) + geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_smooth(method='lm',formula=y~x, se=FALSE)
Figure 3.12 Dynamics of ination-unemployment ‘trade-os’.
df3_12 <- input_data %>% mutate(Dw = c(0,diff(`log(wages)`))) %>% select(Dw, Ur, years) %>% filter(years < 1914) %>% na.omit()
ggplot(df3_12, aes(x=Ur, y=Dw, label = years)) +
geom_text(aes(label=years)) + geom_hline(yintercept = 0, linetype="dashed", color="red") +
geom_line(data=filter(df3_12, years <= 1870), linetype = 1, color=1) +
geom_line(data=filter(df3_12, years > 1870 & years <= 1881), linetype = 2, color=2) +
geom_line(data=filter(df3_12, years > 1881 & years <= 1892), linetype = 3, color=3) +
geom_line(data=filter(df3_12, years > 1893 & years <= 1903), linetype = 4, color=4) +
geom_line(data=filter(df3_12, years > 1903), linetype = 5, color=5)
## geom_path: Each group consists of only one observation. Do you need to
## adjust the group aesthetic?