Created
December 22, 2011 08:47
-
-
Save christophergandrud/1509560 to your computer and use it in GitHub Desktop.
Partisan Inflation Forecast Error Graph
This file contains hidden or 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
################ | |
# Partisan Inflation Forecast Error Graph | |
# Christopher Gandrud | |
# Updated 22 December 2011 | |
################ | |
library(foreign) | |
library(ggplot2) | |
## Load data | |
### Fed inflation forecast error data is from: http://www.phil.frb.org/research-and-data/real-time-center/greenbook-data/ | |
### Actual inflation data is from the FRED database: http://research.stlouisfed.org/fred2/ | |
### For a further description of how the data was compiled in order to be comparable see: http://christophergandrud.blogspot.com/2011/12/federal-reserve-internal-inflation.html | |
cpi.data <- read.dta("~/GB_FRED_cpi.dta") | |
## Clean up data and create forecast error variable | |
cpi.data$pres_party <- factor(cpi.data$pres_party, label = c("Dem", "Rep")) | |
cpi.data$error.prop.deflator.q2 <- (cpi.data$GB_CPI_QTR2 - cpi.data$deflator)/cpi.data$deflator | |
## Create graph using ggplot2 | |
preElection <- ggplot(cpi.data, aes(x = time_to_election, y = error.prop.deflator.q2)) | |
preElection <- preElection + geom_point(aes(color = pres_party)) | |
preElection <- preElection + stat_smooth(method = "loess", aes(group = pres_party, color = pres_party, fill = pres_party)) | |
preElection <- preElection + scale_color_manual(values = c("blue", "red"), name = "") | |
preElection <- preElection + scale_fill_manual(values = c("blue", "red"), name = "") | |
preElection <- preElection + coord_trans(x = "reverse") | |
preElection <- preElection + xlab("Quarters to Election") + ylab("Error/Actual") + opts(title = "Green Book Infl. Forecast Error\nMade 2 Qts Earlier as a Prop. of Actual Inflation\nby Pres. Party (1964 - 2005)") | |
preElection <- preElection + theme_bw() + opts(panel.grid.minor = theme_blank()) + opts(axis.line = theme_segment()) + opts(axis.title.y = theme_text(angle = 90, size = 12, vjust = 0)) | |
print(preElection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment