Skip to content

Instantly share code, notes, and snippets.

@christophergandrud
Created February 7, 2012 09:22
Show Gist options
  • Save christophergandrud/1758596 to your computer and use it in GitHub Desktop.
Save christophergandrud/1758596 to your computer and use it in GitHub Desktop.
Fed Forecast Errors Time Series Graph
########
# Fed Inflation Forecast Error Times Series Graph
# Christopher Gandrud
# Updated 7 January 2011
########
### Using data frame cpi.data
#### 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
#### Partisan colours
partisan.colors = c("Dem" = "#2259B3", "Rep" = "#C42B00")
## Remove 2 quarters from Johnson presidency
cpi.data <- subset(cpi.data, president != "Johnson")
cpi.data$president <- as.factor(cpi.data$presTerm)
## Error region +/- 10 percent
rect.time <- data.frame(xmin = 1968, xmax = 2006, ymin = -0.1, ymax = 0.1)
## Create graph
errors.time <- ggplot(cpi.data, aes(x = Quarter, y = error.prop.deflator.q2)) +
geom_point(aes(color = pres_party)) +
stat_smooth(method = "lm", aes(group = presTerm, color = pres_party, fill = pres_party)) +
geom_rect(data = rect.time, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), color = "grey20", alpha = 0.5, inherit.aes = FALSE) +
scale_color_manual(values = partisan.colors, name = "") +
scale_fill_manual(values = partisan.colors, name = "") +
xlab("") + ylab("Standardized Forecast Error") +
scale_x_continuous(limits=c(1968, 2006)) +
theme_bw() +
opts(axis.title.x = theme_text(size = 12, vjust = 0)) +
opts(axis.title.y = theme_text(angle = 90, size = 12, vjust = 0.3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment