我很难在R中估计CIPS面板协整测试。我加载plm包并使面板数据成为pdata框架。
bcc_panel3 <- pdata.frame(bcc_panel3,index = c("date","country"))数据集包含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*问题出在哪里?
发布于 2021-01-04 08:00:08
正如您在评论中提到的,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, index = c("country", "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, class) # factor, numeric, factor
cipstest(xy_panel1$xy_con,lag=2, type=c("none")) # errors. Likely to few individuals in data set.https://stackoverflow.com/questions/65477990
复制相似问题