CIPS面板协整检验中的系列问题

问题描述

我很难估计 R 中的 CIPS 面板协同测试。我加载了 plm 包并使面板数据成为 pdata 框架

bcc_panel3 <- pdata.frame(bcc_panel3,index = c("date","country"))

dataset

数据集包含 3 个变量。 我使用的 R 命令:

cipstest(bcc_panel3$BCC_con,lags = 4,type = c("trend"),model=c("cmg"))

我尝试了它的变体,但总是出现相同的消息。

*Error in difft.pseries(x = x,lag = lag,...) :  diff is only relevant for numeric or logical series*

有什么问题?

解决方法

正如您在评论中提到的,plm::pdata.frame 会将您的数字转换为非数字。您使用 pdata.frame 的方式是这样做并将您的数字转换为一个因子。请阅读 pdata.frame 的文档。您感兴趣的变量位于数据框的第二列中。如果您没有为 index 指定 pdata.frame 参数,它将假定前两列是索引并执行它应该做的事情:将前两列转换为因子。鉴于您不希望此变量成为索引,请像这样使用 pdata.frame

pdata.frame(xy_combine,index = c("country","date"))

(基于您在问题评论中提供的数据和脚本。)

给定您的数据,cipstest 会失败,因为您的(测试)数据中的观察单元太少(错误消息并没有真正提供相关信息)。描述测试的论文 (Pesaran (2007)) 给出了来自 10 个个体(观察单位)的列表 p 值。您的数据集中有 2 个个体。

我给出了我在下面使用的完整脚本(我将你的脚本剥离到相关部分):

library(readxl) #library for reading excel files
library("plm")
#import data
test <- read_excel("C:/Users/xxx/Downloads/test.xlsx") # adjust to your path

#create country column with 60 obs each Austria and Belgium
country <- rep(c("Austria","Belgium"),each=60)

#stack xy columns into a single column
attach(test)
df1 <- data.frame(a=x,b=y)
xy <- data.frame(c(df1[,"a"],df1[,"b"]))

#create panel data
date <-test$date
xy_combine <- cbind(date,xy,country)
xy_panel <- pdata.frame(xy_combine,"date")) # specify index

lapply(xy_panel,class) # factor,numeric,factor

#rename column 2 in xy_panel1
colnames(xy_panel)[2] <- "xy_con"

#order data by country
country_order <- order(xy_panel$country)
xy_panel1<- xy_panel[country_order,]

lapply(xy_panel1,factor


cipstest(xy_panel1$xy_con,lag=2,type=c("none")) # errors. Likely to few individuals in data set.