Created
April 15, 2013 23:30
-
-
Save milesgrimshaw/5392161 to your computer and use it in GitHub Desktop.
R script for making the graphs on the US economy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################## | |
# Miles Grimshaw | |
# April 15th, 2013 | |
# Code for graphs exploring US Economy | |
# Blog Post: | |
############################## | |
getwd() | |
setwd("~/Desktop/Macro_Paper/Data/") | |
# Recessions: http://www.nber.org/cycles.html | |
## Color for recessions | |
rcol <- rgb(190, 190, 190, alpha=50, maxColorValue=255) | |
# Standard Margins: [1] 5.1 4.1 4.1 2.1 | |
######### NUMBER OF UNEMPLOYED PERSONS ######### | |
u <- read.csv("./CSV/Unemployed.csv", header=TRUE, as.is=TRUE) | |
str(u) | |
u$Date <- as.Date(as.character(u$Date)) | |
u <- u[format(u$Date, '%Y')>1950,] | |
at = format(u$Date, '%m') == '01' & as.numeric(format(u$Date, '%Y')) %% 5 == 0 | |
pdf(file="Num_Unemployed.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 5.0, 4.1, 2.1)) | |
plot(u$Date, u$Unemploy, ylim=c(1, 1.1*max(u$Unemploy)), col="red", type='l', | |
xlab="Date", ylab="Persons (Thousands)", main="Number Of People Unemployed", xaxt='n') | |
mtext("Source: Current Population Survey", cex=0.8, padj=-1) | |
axis(side=1, at=u$Date[ at ], labels=format(u$Date[at], '%Y')) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('2001-03-01'), xright=as.Date('2001-11-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-03-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-11-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1973-11-01'), xright=as.Date('1975-03-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1969-12-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1000, ytop=1.1*max(u$Unemploy)+1000, density=100, col=rcol) | |
dev.off() | |
######### DURATION OF UNEMPLOYMENT ######### | |
d <- read.csv("./CSV/Unemploy_Duration.csv", header=TRUE, as.is=TRUE) | |
str(d) | |
d$Date <- as.Date( as.character( d$Date ) ) | |
## 1970-Present | |
# 5 Year Date Increments | |
at = format(d$Date, '%m') == '01' & as.numeric(format(d$Date, '%Y')) %% 5 == 0 | |
pdf(file="Duration_Unemployment.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 5.0, 4.1, 2.1)) | |
plot(d$Date, d$Mean, ylim=c(1, 1.1*max(d$Mean)), col="black", type='l', | |
xlab="Date", ylab="Weeks", main="Duration of Unemployment", xaxt='n') | |
mtext("Source: Current Population Survey", cex=0.8, padj=-1) | |
axis(side=1, at=d$Date[ at ], labels=format(d$Date[at], '%Y')) | |
points(d$Date, d$Median, col='red', type='l') | |
legend(x=as.Date('1982-07-01'), y=40, legend=c('Mean', 'Median'), | |
col=c('black', 'red'), text.col=c('black','black'), lwd=2.2, cex=1.6, | |
text.width=strwidth("Mean"), | |
seg.len=0.7, adj=0.1, y.intersp=1.4, bty='n', x.intersp=1) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('2001-03-01'), xright=as.Date('2001-11-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-03-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-11-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1973-11-01'), xright=as.Date('1975-03-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1969-12-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
dev.off() | |
######### BEVERIDGE CURVE ######### | |
b <- read.csv("./CSV/Beveridge.csv", header=TRUE, as.is=TRUE) | |
str(b) | |
b$Date <- as.Date( as.character( b$Date ) ) | |
year.cat <- function(x) { | |
year <- as.numeric(format(x, '%Y')) | |
year <- year-(year %% 2) | |
} | |
b$mdate <- sapply(b$Date, FUN=year.cat) | |
b$mdate <- factor(b$mdate, levels=unique(b$mdate), ordered=TRUE) | |
mycolors = c("darkgreen", "brown", "turquoise", "orange", "purple", "blue", "red") | |
pdf(file="Beveridge_Curve.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(b$Unemploy, b$Jobs, ylim=c(0, 1.1*max(b$Jobs)), | |
xlab="Unemployment Rate (%)", ylab="Vacancy Rate (%)", main="Beveridge Curve 2000-2012", | |
col=mycolors[b$mdate], pch=20, cex=2) | |
mtext("Source: Current Population Survey & JOLTs", cex=0.8, padj=-1) | |
legend("bottomleft", horiz=TRUE, legend=paste(a <- levels(b$mdate),"-", as.numeric(substring(a,3,4))+1, sep=""), | |
text.col=mycolors, x.intersp=2, y.intersp=5,text.width=0.45, cex=1.3, bty='n') | |
dev.off() | |
######### GDP TO EMPLOYMENT ######### | |
e <- read.csv("./CSV/GDP_Employment.csv", header=TRUE, as.is=TRUE) | |
str(e) | |
e$Date <- as.Date( as.character( e$Date ) ) | |
year.cat.2 <- function(x) { | |
year <- as.numeric(format(x, '%Y')) | |
year <- year-(year %%10) | |
} | |
e$mdate <- sapply(e$Date, FUN=year.cat.2) | |
e$mdate <- factor(e$mdate, levels=unique(e$mdate), ordered=TRUE) | |
mycolors = c("darkgreen", "brown", "turquoise", "orange", "purple", "green", "blue", "red") | |
pdf(file="GDP_Employ.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(e$Employed, e$GDP, ylim=c(0, 1.1*max(e$GDP)), | |
xlab="Employed Persons (Thousands)", ylab="GDP (Billions)", main="GDP & Employed Persons (1948-2012)", | |
col=mycolors[e$mdate], pch=20, cex=1) | |
mtext("Source: Establishment Survey & St. Louis Fred", cex=0.8, padj=-1) | |
legend("topleft", horiz=TRUE,legend=paste(levels(e$mdate), "s", sep=""), text.col=mycolors, | |
x.intersp=3, y.intersp=3, text.width=1, cex=1.7, bty='n', adj=1) | |
dev.off() | |
# Last 14 Years | |
e2 <- e[ e$Date >= as.Date('1998-01-01'),] | |
e2$mdate <- sapply(e2$Date, FUN=year.cat) | |
e2$mdate <- factor(e2$mdate, levels=unique(e2$mdate), ordered=TRUE) | |
pdf(file="GDP_Employ_2.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(e2$Employed, e2$GDP, | |
xlab="Employed Persons (Thousands)", ylab="GDP (Billions)", | |
main="GDP & Employed Persons (1998-2012)", | |
col=mycolors[e2$mdate], pch=20, cex=1.5) | |
mtext("Source: Establishment Survey & St. Louis Fred", cex=0.8, padj=-1) | |
legend("topleft", legend=paste(a <- levels(e2$mdate),"-", as.numeric(substring(a,3,4))+1, sep=""), | |
text.col=mycolors, cex=1.4, | |
x.intersp=6, y.intersp=1.5, text.width=4,col=mycolors, adj=1, ncol=2, bty='n') | |
dev.off() | |
######### REAl GDP TO EMPLOYMENT (NOVEMBER 1948=100) ######### | |
r <- read.csv("./CSV/Real_GDP_Force_2.csv", header=TRUE, as.is=TRUE) | |
str(r) | |
r$Date <- as.Date( as.character( r$Date ) ) | |
r$mdate <- sapply(r$Date, FUN=year.cat.2) | |
r$mdate <- factor(r$mdate, levels=unique(r$mdate), ordered=TRUE) | |
mycolors = c("darkgreen", "brown", "turquoise", "orange", "purple", "green", "blue", "red") | |
pdf(file="REAL_GDP_Employ.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(r$Employ, r$GDP, ylim=c(0, 1.1*max(r$GDP)), | |
xlab="Employed Persons (Thousands)", ylab="Real GDP Index (November 1948=100)", | |
main="Real GDP & Employed Persons (1948-2012)", | |
col=mycolors[r$mdate], pch=20, cex=1) | |
mtext("Source: Establishment Survey & St. Louis Fred", cex=0.8, padj=-1) | |
legend("topleft", horiz=TRUE,legend=paste(levels(r$mdate), "s", sep=""), text.col=mycolors, | |
x.intersp=3, y.intersp=3, text.width=1, cex=1.7, bty='n', adj=1) | |
dev.off() | |
######### LABOR FORCE PARTIPATION ######### | |
p <- read.csv("./CSV/Participation.csv", header=TRUE, as.is=TRUE) | |
str(p) | |
p$Date <- as.Date( as.character( p$Date ) ) | |
at = format(d$Date, '%m') == '01' & as.numeric(format(d$Date, '%Y')) %% 5 == 0 | |
pdf(file="Labor_Participation.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(p$Date, p$Partic, col="black", type='l', xaxt='n', | |
xlab="Date", ylab="Participation Rate", main="Labor Force Participation Rate (1948-2012)") | |
mtext("Source: Current Population Survey", cex=0.8, padj=-1) | |
abline(h=p$Partic[nrow(p)], col='red', lwd=0.5) | |
axis(side=1, at=p$Date[ at ], labels=format(p$Date[at], '%Y')) | |
dev.off() | |
######### LABOR FORCE TO POPULATION ######### | |
ep <- read.csv("./CSV/Employ_Pop_Ratio.csv", header=TRUE, as.is=TRUE) | |
str(ep) | |
ep$Date <- as.Date( as.character( ep$Date ) ) | |
at = format(ep$Date, '%m') == '01' & as.numeric(format(ep$Date, '%Y')) %% 5 == 0 | |
pdf(file="Employ_Population.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(ep$Date, ep$Ratio, col="black", type='l', xaxt='n', | |
xlab="Date", ylab="Ratio (Thousands / Thousands)", | |
main="Employment to Population Ratio (1948-2012)") | |
mtext("Source: Current Population Survey", cex=0.8, padj=-1) | |
abline(h=ep$Ratio[nrow(ep)], col='red', lwd=0.5) | |
axis(side=1, at=ep$Date[ at ], labels=format(ep$Date[at], '%Y')) | |
dev.off() | |
######### CORPORATE PROFITS / GDP ######### | |
pg <- read.csv("./CSV/Profit_GDP.csv", header=TRUE, as.is=TRUE) | |
str(pg) | |
pg$Date <- as.Date( as.character( pg$Date ) ) | |
at = format(pg$Date, '%m') == '01' & as.numeric(format(pg$Date, '%Y')) %% 5 == 0 | |
# PROFIT | |
pdf(file="Corp_Profit.pdf",width=11,height=8.5) | |
par(mfrow=c(1,2), mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(pg$Date, pg$Profit, ylim=c(1, 1.1*max(pg$Profit)), col="red", type='l', | |
xlab="Date", ylab="Profit (Billions of USD)", | |
main="Corporate Profits (1947-2012)", xaxt='n') | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=pg$Date[ at ], labels=format(pg$Date[at], '%Y')) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+2000, density=100, col=rcol) | |
plot(pg$Date, pg$PG, ylim=c(0, 1.1*max(pg$PG)), col="red", type='l', | |
xlab="Date", ylab='Profit / GDP (Billions of $ / Billions of $)', | |
main="Corporate Profits Share Of GDP (1947-2012)", xaxt='n') | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=pg$Date[ at ], labels=format(pg$Date[at], '%Y')) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1000, ytop=1.1*max(d$Mean)+1000, density=100, col=rcol) | |
dev.off() | |
######### WAGES / GDP ######### | |
cg <- read.csv("./CSV/Comp_GDP.csv", header=TRUE, as.is=TRUE) | |
str(cg) | |
cg$Date <- as.Date( as.character( cg$Date ) ) | |
# Need to rep Sup | |
for (i in 1:length(cg$Sup)) { | |
index <- ((i*4)-3) | |
sup <- cg$Sup[i] | |
cg$Supmod[index:(index+3)] <- sup | |
} | |
cg$Wagep <- cg$Wage / cg$GDP | |
cg$Wages <- (cg$Wage + cg$Supmod) / cg$GDP | |
at = format(cg$Date, '%m') == '01' & as.numeric(format(cg$Date, '%Y')) %% 5 == 0 | |
pdf(file="Labor_Share.pdf",width=11,height=8.5) | |
par(mfrow=c(1,2), mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(cg$Date, cg$Wagep, ylab="Wages / GDP (Billions of $ / Billions of $)", | |
xlab="Date", main="Labor's Share of GDP", type='l', col="red", xaxt='n') | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=cg$Date[ at ], labels=format(cg$Date[at], '%Y')) | |
abline(h=cg$Wagep[nrow(cg)], col="black", lwd=0.5, lty=2) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=0, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
plot(cg$Date, cg$Wages, ylab="Wages + Supplements / GDP", | |
xlab="Date", main="Labor's Share (+ Supplements) of GDP", | |
type='l', col="red", xaxt='n') | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=cg$Date[ at ], labels=format(cg$Date[at], '%Y')) | |
abline(h=cg$Wages[nrow(cg)], col="black", lwd=0.5, lty=2) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1, ytop=1, density=100, col=rcol) | |
dev.off() | |
######### CORPORATE PROFIT TO WAGE GROWTH ######### | |
pw2 <- read.csv("./CSV/Profit_Comp_1970.csv", header=TRUE, as.is=TRUE) | |
str(pw2) | |
pw2$Date <- as.Date( as.character( pw2$Date ) ) | |
at = format(pw2$Date, '%m') == '01' & as.numeric(format(pw2$Date, '%Y')) %% 5 == 0 | |
pdf(file="Labor_VS_Corp.pdf",width=11,height=8.5) | |
par(mfrow=c(1,2), mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(pw2$Date, pw2$WASCUR, ylab="Billions of $", xlab="Date", | |
main="Wages & Corporate Profits",type='l', col="blue", xaxt='n') | |
points(pw2$Date, pw2$CP, type='l', col='red') | |
legend(x=as.Date("1973-01-01"), y=6500, legend=c('Wages', 'Corporate Profits'), | |
col=c('blue', 'red'), text.col="black", lwd=2, cex=1, | |
text.width=3, seg.len=1.2, y.intersp=1.5, bty='n', x.intersp=2, adj=0 ) | |
axis(side=1, at=pw2$Date[ at ], labels=format(pw2$Date[at], '%Y')) | |
plot(pw2$Date, pw2$CPT, type='l', | |
ylab="% Change Since 1970", xlab="Date", main="Change in Wages & Corporate Profits 1970 - 2012", | |
xaxt='n', col='red') | |
points(pw2$Date, pw2$WageT, type='l', col='blue') | |
axis(side=1, at=pw2$Date[ at ], labels=format(pw2$Date[at], '%Y')) | |
legend(x=as.Date("1973-01-01"), y=3400, legend=c('Wages', 'Corporate Profits'), | |
col=c('blue', 'red'), text.col="black", lwd=2, cex=1, | |
text.width=3, seg.len=1.2, y.intersp=1.5, bty='n', x.intersp=2, adj=0 ) | |
dev.off() | |
######### JOB GROWHT BY DECADE ######### | |
te <- read.csv("./CSV/Total_Employ.csv", header=TRUE, as.is=TRUE) | |
str(te) | |
te$Date <- as.Date( as.character( te$Date ) ) | |
te <- te[format(te$Date, '%Y') >= "1940",] | |
at = as.numeric(format(te$Date, '%Y')) %% 10 == 0 & format(te$Date, '%m') == "01" | |
at2 = substring(format(te$Date, '%Y'),1,3) == "194" & format(te$Date, '%m') =="01" | |
years <- seq(1,10, by=1) | |
for (i in 1:nrow(te)) { | |
a <- ((i-1)%/% 120) | |
init <- te$Employ[((a*120)+1)] | |
te$Perc[i] <- 100*((te$Employ[i]-init)/init) | |
} | |
mycolors = c("darkgreen", "brown", "turquoise", "orange", "purple", "blue", "red") | |
pdf(file="Employment_Growth.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 5.0, 4.1, 2.1)) | |
plot(te$Perc[which(at)[1]:(which(at)[2]-1)], | |
type="l", xaxt='n', col=mycolors[1], ylim=c(2*min(te$Perc), 1.1*max(te$Perc)), | |
ylab="Cumulative Percent Change", xlab="Years Into The Decade", main="Employment Growth By Decade (1940s-2000s)") | |
axis(1, at=c(13, 25, 37, 49, 61, 73, 85, 97, 109, 121), labels=years) | |
mtext("Source: Bureau of Labor Statistics", cex=0.8, padj=-1) | |
text(x=120, y=(te$Perc[which(at)[2]-1]+2), | |
labels=paste(format(te$Date[which(at)[1]], '%Y'), "s", sep = ""), | |
col=mycolors[1], cex=1.2) | |
for (i in 2:(length(which(at))-1)){ | |
points(te$Perc[which(at)[i]:(which(at)[i+1]-1)], | |
type="l", xaxt='n', col=mycolors[i]) | |
h <- te$Perc[which(at)[i+1]-1] | |
if (i==6) | |
h <- h-3 | |
if (i==5) | |
h <- h+1 | |
text(x=120, y=h, labels=paste(format(te$Date[which(at)[i]], '%Y'), "s", sep = ""), | |
col=mycolors[i], cex=1.2) | |
} | |
dev.off() | |
gg <- read.csv("./CSV/GDP_Growth.csv", header=TRUE, as.is=TRUE) | |
str(gg) | |
gg$Date <- as.Date( as.character( gg$Date ) ) | |
at = as.numeric(format(gg$Date, '%Y')) %% 10 == 0 & format(gg$Date, '%m') == "01" | |
at2 = substring(format(gg$Date, '%Y'),1,3) == "195" & format(gg$Date, '%m') =="01" | |
for (i in 1:nrow(gg)) { | |
a <- ((i-1)%/% 40) | |
init <- gg$GDP[((a*40)+1)] | |
gg$Perc[i] <- 100*((gg$GDP[i]-init)/init) | |
} | |
pdf(file="GDP_Growth.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 5.0, 4.1, 2.1)) | |
plot(gg$Perc[which(at)[1]:(which(at)[2]-1)], | |
type="l", xaxt='n', col=mycolors[1], ylim=c(2*min(gg$Perc), 1.1*max(gg$Perc)), | |
ylab="Cumulative Percent Change", xlab="Years Into The Decade", main="GDP Growth By Decade (1950s-2000s)") | |
axis(1, at=c(5, 9, 13, 17, 21, 25, 29, 33, 37, 40), labels=years) | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
text(x=40, y=(gg$Perc[which(at)[2]-1]+2)-8, | |
labels=paste(format(gg$Date[which(at)[1]], '%Y'), "s", sep = ""), | |
col=mycolors[1], cex=1.2) | |
for (i in 2:(length(which(at))-1)){ | |
points(gg$Perc[which(at)[i]:(which(at)[i+1]-1)], | |
type="l", xaxt='n', col=mycolors[i]) | |
h <- gg$Perc[which(at)[i+1]-1] | |
if (i==2) | |
h <- h+3 | |
text(x=40, y=h, labels=paste(format(gg$Date[which(at)[i]], '%Y'), "s", sep = ""), | |
col=mycolors[i], cex=1.2) | |
} | |
dev.off() | |
pdf(file="GDP_VS_Employment_Growth.pdf",width=11,height=8.5) | |
par(mfrow=c(1,2), mar=c(5.1, 5.0, 4.1, 2.1)) | |
at = as.numeric(format(te$Date, '%Y')) %% 10 == 0 & format(te$Date, '%m') == "01" & format(te$Date,'%Y') > "1940" | |
mycolors = c("brown", "darkgreen", "orange", "purple", "blue", "red") | |
plot(te$Perc[which(at)[1]:(which(at)[2]-1)], | |
type="l", xaxt='n', col=mycolors[1], | |
ylim=c(2*min(te$Perc), 1.1*max(te$Perc[format(te$Date,'%Y')>="1950"])), | |
ylab="Cumulative Percent Change", xlab="Years Into The Decade", | |
main="Employment Growth By Decade (1950s-2000s)") | |
axis(1, at=c(13, 25, 37, 49, 61, 73, 85, 97, 109, 121), labels=years) | |
mtext("Source: Bureau of Labor Statistics", cex=0.8, padj=-1) | |
text(x=115, y=(te$Perc[which(at)[2]-1]+2), | |
labels=paste(format(te$Date[which(at)[1]], '%Y'), "s", sep = ""), | |
col=mycolors[1], cex=1.2) | |
for (i in 2:(length(which(at))-1)){ | |
points(te$Perc[which(at)[i]:(which(at)[i+1]-1)], | |
type="l", xaxt='n', col=mycolors[i]) | |
h <- te$Perc[which(at)[i+1]-1] | |
if (i==6) | |
h <- h-3 | |
if (i==5) | |
h <- h+1 | |
text(x=115, y=h, labels=paste(format(te$Date[which(at)[i]], '%Y'), "s", sep = ""), | |
col=mycolors[i], cex=1.2) | |
} | |
at = as.numeric(format(gg$Date, '%Y')) %% 10 == 0 & format(gg$Date, '%m') == "01" | |
plot(gg$Perc[which(at)[1]:(which(at)[2]-1)], | |
type="l", xaxt='n', col=mycolors[1], ylim=c(2*min(gg$Perc), 1.1*max(gg$Perc)), | |
ylab="Cumulative Percent Change", xlab="Years Into The Decade", main="GDP Growth By Decade (1950s-2000s)") | |
axis(1, at=c(5, 9, 13, 17, 21, 25, 29, 33, 37, 40), labels=years) | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
text(x=38.5, y=(gg$Perc[which(at)[2]-1]+2)-8, | |
labels=paste(format(gg$Date[which(at)[1]], '%Y'), "s", sep = ""), | |
col=mycolors[1], cex=1.2) | |
for (i in 2:(length(which(at))-1)){ | |
points(gg$Perc[which(at)[i]:(which(at)[i+1]-1)], | |
type="l", xaxt='n', col=mycolors[i]) | |
h <- gg$Perc[which(at)[i+1]-1] | |
if (i==2) | |
h <- h+3 | |
text(x=38.5, y=h, labels=paste(format(gg$Date[which(at)[i]], '%Y'), "s", sep = ""), | |
col=mycolors[i], cex=1.2) | |
} | |
dev.off() | |
######### LABOR SHARE ######### | |
# Non Farm Business Sector | |
le <- read.csv("./CSV/Labor_Share.csv", header=TRUE, as.is=TRUE) | |
str(le) | |
le$Date <- as.Date( as.character( le$Date ) ) | |
at = format(le$Date, '%m') == '01' & as.numeric(format(le$Date, '%Y')) %% 5 == 0 | |
pdf(file="Labor_Share_Value_Add.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(le$Date, le$Share, type="l", col="red", | |
xlab="Date", ylab="Index: March 2001 = 100", | |
main="Labor's Share of Value Add", xaxt='n') | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=le$Date[ at ],labels=format(le$Date[at], '%Y')) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-1, ytop=120, density=100, col=rcol) | |
dev.off() | |
######### QUITS ######### | |
q <- read.csv("./CSV/Quits.csv", header=TRUE, as.is=TRUE) | |
str(q) | |
q$Date <- as.Date( as.character( q$Date ) ) | |
pdf(file="Quits_Rate.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(q$Date, q$Quit, xlab="Date", ylab="Quits Rate", | |
main="Quits Rate (2000-2013)", type='l', col="red") | |
mtext("Source: JOLTS", cex=0.8, padj=-1) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-1, ytop=4, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-1, ytop=4, density=100, col=rcol) | |
dev.off() | |
######### SOFTWARE INVESTMENT PER WORKER ######### | |
se <- read.csv("./CSV/Software_Employ.csv", header=TRUE, as.is=TRUE) | |
str(se) | |
se$Date <- as.Date( as.character( se$Date ) ) | |
at = format(se$Date, '%m') == '01' & as.numeric(format(se$Date, '%Y')) %% 5 == 0 | |
pdf(file="Investment_Per_Worker.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 4)) | |
plot(se$Date, se$Perc, xlab="Date", ylab="Investment per Employed Person (Billions of $ / Thousands of Persons)", | |
main="Private Nonresidential Investment in Equipment & Software", type='l', col="red", | |
xaxt='n', yaxt='n') | |
text(x=se$Date[which(format(se$Date,'%Y')=="1981")[4]], y=0.45, | |
labels="Investment per Employee", col="red", cex=1) | |
axis(2, pretty(c(0, 1.1*max(se$Perc))), col='red') | |
mtext("Source: FRED National Accounts Data, Bureau of Labor Statistics", cex=0.8, padj=-1) | |
axis(side=1, at=se$Date[ at ],labels=format(se$Date[at], '%Y')) | |
par(new=T) | |
plot(se$Date, se$Invest, type='l', col="blue", xaxt='n', axes=F, , ylab='', xlab='') | |
text(x=se$Date[which(format(se$Date,'%Y')=="2000")[1]], y=400, | |
labels="Total Investment", col="blue", cex=1) | |
axis(4, pretty(c(0, 1.1*max(se$Invest))), col='blue') | |
mtext("Private Fixed Investment (Billions of $)", 4,padj=4, cex=1) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=-500, ytop=1500, density=100, col=rcol) | |
dev.off() | |
######### PRODUCTIVITY WAGE GROWTH SEPERATION ######### | |
#output per hour | |
#Real compensation per hour | |
#January 1980 = 100 | |
pp <- read.csv("./CSV/Output_Comp.csv", header=TRUE, as.is=TRUE) | |
str(pp) | |
pp$Date <- as.Date( as.character( pp$Date ) ) | |
at = format(le$Date, '%m') == '01' & as.numeric(format(le$Date, '%Y')) %% 5 == 0 | |
pdf(file="Productivity_Compensation_2.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(pp$Date, pp$Output, xlab="Date", ylab="Output Per Hour & Real Wages Per Hour (1980=100)", | |
main="Wage Productivity Gap", | |
type='l', col="blue", xaxt='n') | |
points(pp$Date, pp$Comp, type='l', col="red") | |
mtext("Source: FRED National Accounts Data", cex=0.8, padj=-1) | |
axis(side=1, at=pp$Date[ at ],labels=format(se$Date[at], '%Y')) | |
text(x=pp$Date[which(format(pp$Date,'%Y')=="2000")[1]], y=100, | |
labels="Real Wages Per Hour", col="red", cex=1.2) | |
text(x=pp$Date[which(format(pp$Date,'%Y')=="1990")[1]], y=140, | |
labels="Output Per Hour", col="blue", cex=1.2) | |
rect(xleft=as.Date('2007-10-01'), xright=as.Date('2009-07-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('2001-04-01'), xright=as.Date('2001-10-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1990-07-01'), xright=as.Date('1991-04-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1981-07-01'), xright=as.Date('1982-10-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1973-10-01'), xright=as.Date('1975-04-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1969-10-01'), xright=as.Date('1970-11-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1960-04-01'), xright=as.Date('1961-01-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1957-10-01'), xright=as.Date('1958-04-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
rect(xleft=as.Date('1953-07-01'), xright=as.Date('1954-04-01'), | |
ybottom=0, ytop=200, density=100, col=rcol) | |
dev.off() | |
######### PRODUCTIVITY vs MEDIAN INCOME ######### | |
# Data is from: http://stateofworkingamerica.org/charts/productivity-and-real-median-family-income-growth-1947-2009/ | |
pm <- read.csv("./CSV/Product_Median.csv", header=TRUE, as.is=TRUE) | |
str(pm) | |
pdf(file="Productivity_vs_Median_Income.pdf",width=11,height=8.5) | |
par(mar=c(5.1, 4.8, 4.8, 2.1)) | |
plot(pm$Year, pm$Product, xlab="Date", ylab="Cumulative Percent Change Since 1947", | |
main="Productivity vs Real Median Family Income (1947-2011)", | |
type='l', col="blue") | |
points(pm$Year, pm$Median, type='l', col='red') | |
mtext("Source: www.stateofworkingamerica.org", cex=0.8, padj=-1) | |
text(x=2000, y=pm$Median[pm$Year==2000]-0.6, labels="Real Median Family Income", col="red", cex=1.2) | |
text(x=1990, y=pm$Product[pm$Year==2000]-0.2, labels="Productivity", col="blue", cex=1.2) | |
dev.off() | |
############################################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment