daily pastebin goal
21%
SHARE
TWEET

R code for analysing historical GDP-per-capita data

csortu Oct 27th, 2016 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(readxl)
  2.  
  3. setwd("~/Dropbox/Misc/Statistics/mindenfele/data/Europe_economy_history")
  4.  
  5. datfile <- "Maddison_Europe_Full.xlsx"
  6. excel_sheets(datfile)
  7.  
  8. gdppc <- read_excel(datfile,sheet = 4,skip=2)
  9. names(gdppc)[1] <- 'year'
  10.  
  11. # Drop data <1820 and >2009
  12. gdppc <- gdppc[61:199,]
  13.  
  14. gdppc.xts <- xts(gdppc[,-1],as.Date(paste0(gdppc$year,'-01-01')))
  15.  
  16. gdppc.zoo <- as.zoo(gdppc.xts)
  17. tsRainbow <- rainbow(20)
  18. plot(gdppc.zoo[,1:20],col = tsRainbow,screens=1,
  19.      main = "gdppculation of European countries",
  20.      xlab="Year",
  21.      ylab="gdppculation [thousands]",
  22.      xlim = c(as.Date("1900-01-01"),as.Date("2009-01-01")))
  23. legend(x = "topleft", legend = names(gdppc.zoo)[1:20],
  24.        lty = 1,col = tsRainbow,cex=0.6)
  25.  
  26. compara <- gdppc[,c(1,21,2,7,13,5)]
  27. compara <- compara[77:139,]
  28.  
  29. plot(compara$year,compara$`Hungary `,type="l",
  30.      ylim = c(1000,25000),
  31.      main="GPD/capita of selected countries after WWII",
  32.      sub="plot labels reflect events in Hungary",
  33.      xlab="year",
  34.      ylab="USD",las=1)
  35. lines(compara$year,compara$`Germany `,col="blue")
  36. lines(compara$year,compara$`Austria `,col="green")
  37. lines(compara$year,compara$UK,col="red")
  38. lines(compara$year,compara$`Finland `,col="orange")
  39. lines(c(1956,1956),c(30,15000))
  40. lines(c(1990,1990),c(30,15000))
  41. text(1950,650,"Stalinism")
  42. text(1972,1440,"Socialism\nKádár regime")
  43. text(1956,20000,"'56 uprising",srt=90)
  44. text(1990,21000,"political transition",srt=90)
  45. legend(1960,25000,c("Hungary","Austria","Germany","Finland","UK"),
  46.        bty="n",
  47.        lty=1,
  48.        col=c("black","green","blue","orange","red"))
  49.  
  50.  
  51. plot(compara$year,100*compara$`Hungary `/compara$`Hungary `[1],type="l",
  52.      ylim = c(90,1200),
  53.      main="GPD/capita of selected countries after WWII\nin % of 1945 value",
  54.      sub="plot labels reflect events in Hungary",
  55.      xlab="year",
  56.      ylab="USD",las=1)
  57. lines(compara$year,100*compara$`Germany `/compara$`Germany `[1],col="blue")
  58. lines(compara$year,100*compara$`Austria `/compara$`Austria `[1],col="green")
  59. lines(compara$year,100*compara$UK/compara$UK[1],col="red")
  60. lines(compara$year,100*compara$`Finland `/compara$`Finland `[1],col="orange")
  61. lines(c(1956,1956),c(50,600))
  62. text(1956,800,"'56 uprising",srt=90)
  63. lines(c(1990,1990),c(50,600))
  64. text(1990,880,"political transition",srt=90)
  65. text(1950,400,"Stalinism")
  66. text(1972,420,"Socialism\nKádár regime")
  67. legend(1960,1200,c("Hungary","Austria","Germany","Finland","UK"),
  68.        bty="n",
  69.        lty=1,
  70.        col=c("black","green","blue","orange","red"))
  71.  
  72.  
  73. compara$AH <- 100*compara$`Hungary `/compara$`Austria `
  74. plot(compara$year,compara$AH,type='l',
  75.      main="Hungary's GDP/capita as percent of Austria's after WWII",
  76.      sub="plot labels reflect events in Hungary",
  77.      xlab="year",
  78.      ylab="%", las=1)
  79. #abline(v=1990)
  80. lines(c(1956,1956),c(31,65))
  81. lines(c(1990,1990),c(31,65))
  82. text(1950,35,"Stalinism")
  83. text(1972,34,"Socialism\nKádár regime")
  84. text(1956,75,"'56 uprising",srt=90)
  85. text(1990,76,"political transition",srt=90)
  86. arrows(1968,70,1974.5,70,length=0.15,code=3)
  87. text(1971.5,80,"New\nEconomical\nMechanism")
  88.  
  89. arrows(1975,70,1985,70,length=0.15,code=3)
  90. text(1980,80,"Fekete's\nEconomy")
  91.  
  92. arrows(1973,60,2010,60,length=0.15)
  93. text(1992,57,"External financing of Hungarian economy")
  94.  
  95.  
  96. # After Trianon, before the end of WWII
  97.  
  98. compara2 <- gdppc[!is.na(gdppc$`Hungary `),c(1,21,2,7,13,5)]
  99. compara2 <- compara2[6:25,]
  100. plot(compara2$year,compara2$`Hungary `,type="l",
  101.      ylim = c(1500,8000),
  102.      main="GPD/capita of selected countries before the end of WWII",
  103.      xlab="year",
  104.      ylab="USD",las=1)
  105. lines(compara2$year,compara2$`Germany `,col="blue")
  106. lines(compara2$year,compara2$`Austria `,col="green")
  107. lines(compara2$year,compara2$UK,col="red")
  108. lines(compara2$year,compara2$`Finland `,col="orange")
  109. legend(1922,8000,c("Hungary","Austria","Germany","Finland","UK"),
  110.        bty="n",
  111.        lty=1,
  112.        col=c("black","green","blue","orange","red"))
  113. arrows(1929,6000,1932,6000,length=0.15,code=3)
  114. text(1930.5,6300,"The great depression")
  115.  
  116. plot(compara2$year,100*compara2$`Hungary `/compara2$`Hungary `[1],type="l",
  117.      ylim = c(90,210),
  118.      main="GPD/capita of selected countries before the end of WWII",
  119.      sub="in % of 1920 value",
  120.      xlab="year",
  121.      ylab="%",las=1)
  122. lines(compara2$year,100*compara2$`Germany `/compara2$`Germany `[1],col="blue")
  123. lines(compara2$year,100*compara2$`Austria `/compara2$`Austria `[1],col="green")
  124. lines(compara2$year,100*compara2$UK/compara2$UK[1],col="red")
  125. lines(compara2$year,100*compara2$`Finland `/compara2$`Finland `[1],col="orange")
  126. legend(1922,210,c("Hungary","Austria","Germany","Finland","UK"),
  127.        bty="n",
  128.        lty=1,
  129.        col=c("black","green","blue","orange","red"))
  130. arrows(1929,180,1932,180,length=0.15,code=3)
  131. text(1930.5,190,"The great depression")
  132.  
  133. compara2$AH <- 100*compara2$`Hungary `/compara2$`Austria `
  134. plot(compara2$year,compara2$AH,type='l',
  135.      main="Hungary's GDP/capita as percent of Austria's before the end of WWII",
  136.      sub="plot labels reflect events in Hungary",
  137.      xlab="year",
  138.      ylab="%", las=1)
  139. arrows(1929,85,1932,85,length=0.15,code=3)
  140. text(1930.5,87,"The great depression")
RAW Paste Data
Top