Skip to content

Instantly share code, notes, and snippets.

@arimitramaiti
Last active October 8, 2020 15:24
Show Gist options
  • Save arimitramaiti/294378141e885447f420a1d8197154fd to your computer and use it in GitHub Desktop.
Save arimitramaiti/294378141e885447f420a1d8197154fd to your computer and use it in GitHub Desktop.
##Used to import data
library(readr)
##Used for adf test
library(tseries)
##Import data
data <- read.csv("https://raw.githubusercontent.com/arimitramaiti/datasets/master/articles/a5_data.csv", header = TRUE, sep = ",")
##Use ts() function to create time series object
##Object with suffix _GWR stores growth rate series
##Growth rate is similar to percentage change from one time point to the other and is already stored in the dataset link above
GDP_pc <- ts(data$GDP_pc,
start = c(1990, 1),
end = c(2019, 4),
frequency = 4)
GDP_GWR <- ts(data$GDP_GWR,
start = c(1990, 1),
end = c(2019, 4),
frequency = 4)
Consumption <- ts(data$Consumption,
start = c(1990, 1),
end = c(2019, 4),
frequency = 4)
C_GWR <- ts(data$C_GWR,
start = c(1990, 1),
end = c(2019, 4),
frequency = 4)
##Create objects storing adf test results
adf1 <- adf.test(GDP_pc)
adf2 <- adf.test(GDP_GWR)
adf3 <- adf.test(Consumption)
adf4 <- adf.test(C_GWR)
##Plot Raw series and Growth Rate
par(mfrow=c(2,2))
plot(GDP_pc, main="U.S.A GDP Per Capita", xlab="Time", ylab="GDP Per Capita ($$)", sub=paste("ADF Test:p-value: ", round(adf1$p.value,3), "Failure to Reject Null-Not Stationary"))
plot(GDP_GWR, main="U.S.A GDP Growth Rate", xlab="Time", ylab="Growth Rate", sub=paste("ADF Test:p-value: ", round(adf2$p.value,3), "Reject Null-Stationary"))
plot(Consumption, main="U.S.A Consumption Expenses", xlab="Time", ylab="Consumption Expenses ($$)", sub=paste("ADF Test:p-value: ", round(adf3$p.value,3), "Failure to Reject Null-Not Stationary"))
plot(C_GWR, main="U.S.A Consumption Growth Rate", xlab="Time", ylab="Growth Rate", sub=paste("ADF Test:p-value: ", round(adf4$p.value,3), "Reject Null-Stationary"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment