我有一个数据由16个obs组成。和30个变量,我想为每列应用ADF测试。名为test1
的数据和第一列称为TBdu_jp
我的代码:
library(tseries)
library(urca)
library(vars)
TBdu_jp <- ts(test1$TBdu_jp, start = 1999, end = 2014, frequency = 1)
TBdu_jp <- log(TBdu_jp)
adf1 <- summary(ur.df(TBdu_jp, type = "none", lags = 0))
adf_lag0 <- summary(ur.df(TBdu_jp, type = "none", lags = 0))
adf_lag0 <- summary(ur.df(TBdu_jp, type = "trend", lags = 0))
adf_lag0 <- summary(ur.df(TBdu_jp, type = "none", lags = 0))
adf_lag0_t <- summary(ur.df(TBdu_jp, type = "trend", lags = 0))
adf_lag0_d <- summary(ur.df(TBdu_jp, type = "drift", lags = 0))
adf_lag0_d1 <- summary(ur.df(diff(TBdu_jp,differences = 1), type = "none", lags = 0))
adf_lag0_d2 <- summary(ur.df(diff(TBdu_jp,differences = 2), type = "none", lags = 0))
adf_lag0_d1_t <- summary(ur.df(diff(TBdu_jp,differences = 1), type = "trend", lags = 0))
adf_lag0_d2_t <- summary(ur.df(diff(TBdu_jp,differences = 2), type = "trend", lags = 0))
adf_lag0_d1_dr <- summary(ur.df(diff(TBdu_jp,differences = 1), type = "drift", lags = 0))
adf_lag0_d2_dr <- summary(ur.df(diff(TBdu_jp,differences = 2), type = "drift", lags = 0))
是否有一个命令允许我自动为其余列重复相同的命令?
另外,是否可以制作相同的命令,但是对于不同的滞后数量,例如1,2,3和4个滞后数量,而不是再次重写代码?
答案 0 :(得分:1)
sumts <- function(x) {
x <- log(ts(x, start = 1999, end = 2014, frequency = 1))
list(adf1=summary(ur.df(x, type = "none", lags = 0)),
adf_lag0=summary(ur.df(x, type = "none", lags = 0)),
adf_lag0_t=summary(ur.df(x, type = "trend", lags = 0)),
adf_lag0_d=summary(ur.df(x, type = "drifft", lags = 0)),
adf_lag0_d1= summary(ur.df(diff(x,differences = 1), type = "none", lags = 0)),
adf_lag0_d2= summary(ur.df(diff(x,differences = 2), type = "none", lags = 0)),
adf_lag0_d1_t= summary(ur.df(diff(x,differences = 1), type = "trend", lags = 0)),
adf_lag0_d2_t=summary(ur.df(diff(x,differences = 2), type = "trend", lags = 0)),
adf_lag0_d1_dr=summary(ur.df(diff(x,differences = 1), type = "drift", lags = 0)),
adf_lag0_d2_dr=summary(ur.df(diff(x,differences = 2), type = "drift", lags = 0))
)
}
lapply(test1, sumts)