econ<-read.csv("/Users/carrielevan/Documents/Geo299/EconomicHW/GDPchange.csv")
library(car)
NOTE: For some reason my code under "preparing the data" keeps changing once I post. I've tried it three times and don't know why it changes. If you want the exact code, email me and I will give it to you.
#Subsets of GDP Quarter Change by Party in Power
dem1<-subset(econ$GDPQuarterChange, econ$Quarter<>
rep1<-subset(econ$GDPQuarterChange, econ$Quarter>19534 & econ$Quarter <>
dem2<-subset(econ$GDPQuarterChange, econ$Quarter>19614 & econ$Quarter <>
rep2<-subset(econ$GDPQuarterChange, econ$Quarter>19694 & econ$Quarter <>
dem3<-subset(econ$GDPQuarterChange, econ$Quarter>19774 & econ$Quarter <>
rep3<-subset(econ$GDPQuarterChange, econ$Quarter>19814 & econ$Quarter <>
dem4<-subset(econ$GDPQuarterChange, econ$Quarter>19814 & econ$Quarter <>
rep4<-subset(econ$GDPQuarterChange, econ$Quarter>19934 & econ$Quarter <>
dem4<-subset(econ$GDPQuarterChange, econ$Quarter>19934 & econ$Quarter <>
rep4<-subset(econ$GDPQuarterChange, econ$Quarter > 20004)
#Creating Subset of Quarter Dates
demQ1<-subset(econ$Quarter, econ$Quarter <>
repQ1<-subset(econ$Quarter, econ$Quarter>19534 & econ$Quarter <>
demQ2<-subset(econ$Quarter, econ$Quarter>19614 & econ$Quarter <>
repQ2<-subset(econ$Quarter, econ$Quarter>19694 & econ$Quarter <>
demQ3<-subset(econ$Quarter, econ$Quarter>19774 & econ$Quarter <>
repQ3<-subset(econ$Quarter, econ$Quarter>19814 & econ$Quarter <>
demQ4<-subset(econ$Quarter, econ$Quarter>19934 & econ$Quarter <>
repQ4<-subset(econ$Quarter, econ$Quarter > 20004)
#Line Plot with Different Party in Power lines
plot(econ$Quarter, econ$GDPQuarterChange, xlab="Year and Quarter", ylab="Change in GDP", main="GDP Change by Quarter from 1947-2009", type="l")
lines(demQ3, dem3, col="blue")
lines(demQ4, dem4, col="blue")
lines(demQ2, dem2, col="blue")
lines(demQ1, dem1, col="blue")
lines(repQ2, rep2, col="red")
lines(repQ1, rep1, col="red")
lines(repQ3, rep3, col="red")
lines(repQ4, rep4, col="red")
legend("bottomright", c("Democrat", "Republican"), col=c("blue", "red"), lty=1:2)
##Figure 2
#Boxplot
boxplot(GDPQuarterChange~PID, data=econ, ylab="GDP Change by Quarter", xlab="Party", main="GDP Change by Party of President 1947-2009", col=(c("red", "blue")))
par(mfrow=c(2,2))
plot(demQ1, dem1, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Democratic President 1947-1953", col="blue")
abline(lm(dem1~demQ1), col="blue")
plot(repQ1, rep1, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Republican President 1954-1961", col="red") abline(lm(rep1~repQ1), col="red")
plot(demQ2, dem2, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Democratic President 1962-1969", col="blue")
abline(lm(dem2~demQ2), col="blue")
plot(repQ2, rep2, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Republican President 1970-1977", col="red")
abline(lm(rep2~repQ2), col="red")
par(mfrow=c(2,2))
plot(demQ3, dem3, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Democratic President 1978-1981", col="blue")
abline(lm(dem3~demQ3), col="blue")
plot(repQ3, rep3, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Republican President 1982-1993", col="red")
abline(lm(rep3~repQ3), col="red")
plot(demQ4, dem4, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Democratic President 1994-2001", col="blue")
abline(lm(dem4~demQ4), col="blue")
plot(repQ4, rep4, type="p", xlab="Year and Quarter", ylab="GDP Change by Quarter", main="GDP Change under Republican President 2002-2009", col="red")
abline(lm(rep4~repQ4), col="red")
##Figure 4
#Preparing the Data
REP1<-subset(econ$GDPQuarterChange, econ$QuarterPID==1)
DEM1<-subset(econ$GDPQuarterChange, econ$QuarterPID==2)
dREP1<-density(REP1)
dDEM1<-density(DEM1)
#histogram
par(mfrow=c(2,1))
hist(DEM1, col="blue", main="Histogram of GDP Quarterly Change Under Democratic President", xlab="GDP Quarterly Change", breaks=15)
hist(REP1, col="red", main="Histogram of GDP Quarterly Change Under Republican President", xlab="GDP Quarterly Change", breaks=15)
##Figure 5
plot(dREP1, main="Distribution of GDP Quarterly Change Separated by Party", col="red", xlim=c(-40,40))
lines(dDEM1, col="blue")
legend("topleft", c("Republican", "Democrat"), col=c("red", "blue"), lty=1:1)