Created
April 12, 2012 15:50
-
-
Save Shreyes2010/2368506 to your computer and use it in GitHub Desktop.
MOM vs YOY rates in inflation
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
a <- read.csv("Data.csv") | |
# Pretty functions to compute the MOM and YOY inflation rates | |
mom.inf <- function(series){ | |
x <- rep(NA,length(series)) | |
for(i in 2:length(series))x[i] <- ((series[i] - series[i-1])/series[i-1])*100 | |
return(x) | |
} | |
yoy.inf <- function(series){ | |
y <- rep(NA,length(series)) | |
for(i in 13:length(series))y[i] <- ((series[i] - series[i-12])/series[i-1])*100 | |
return(y) | |
} | |
a$MOM <- mom.inf(a$CPI) | |
a$YOY <- yoy.inf(a$CPI) | |
a$MOM_SA <- mom.inf(a$CPI_SA) | |
a$YOY_SA <- yoy.inf(a$CPI_SA) | |
# Plotting the MOM and YOY inflation rates | |
plot(a$YOY,type="l",col="red", ylim=c(-2,18),xlab="Time", ylab="Inflation rate", | |
main="M-O-M and Y-O-Y Inflation rates with no seasonal adjustment") | |
lines(a$MOM,type="l") | |
legend("topright",c("MOM infltion rate","YOY inflation rate"),col=c("black","red") | |
,cex=0.7, lwd=2) | |
# Plotting the MOM and YOY seasonally adjusted inflation rates | |
plot(a$YOY_SA,type="l",col="red", ylim=c(-2,18),xlab="Time", ylab="Inflation rate", | |
main="M-O-M and Y-O-Y Inflation rates with seasonal adjustment") | |
lines(a$MOM_SA,type="l") | |
legend("topright",c("MOM infltion rate","YOY inflation rate"),col=c("black","red") | |
,cex=0.7, lwd=2) | |
# Plotting the YOY adjusted and unadjusted inflation rates | |
plot(a$YOY_SA,type="l",col="red",xlab="Time", ylab="Inflation rate", | |
main="Y-O-Y Inflation rates") | |
lines(a$YOY,type="l") | |
legend("topright",c("Y-O-Y seasonally adjusted","Y-O-Y seasonally unadjusted"), | |
col=c("black","red") ,cex=0.7, lwd=2) | |
# Plotting the MOM adjusted and unadjusted inflation rates | |
plot(a$MOM_SA,type="l",col="red",xlab="Time", ylim = c(-2,6), ylab="Inflation rate", | |
main="M-O-M Inflation rates") | |
lines(a$MOM,type="l") | |
legend("topright",c("M-O-M seasonally adjusted","M-O-M seasonally unadjusted"), | |
col=c("black","red") ,cex=0.7, lwd=2) | |
# Unit root test | |
library(tseries) | |
adf.test(a$YOY[13:length(a$YOY)]) | |
adf.test(a$MOM[2:length(a$MOM)]) | |
adf.test(a$YOY_SA[13:length(a$YOY_SA)]) | |
adf.test(a$MOM_SA[2:length(a$MOM_SA)]) | |
# Summary statistics | |
var(a$YOY[13:length(a$YOY)]) | |
var(a$MOM[2:length(a$MOM)]) | |
var(a$YOY_SA[13:length(a$YOY_SA)]) | |
var(a$MOM_SA[2:length(a$MOM_SA)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment