R plm 包中有关长度相同但内容不同的索引的警告消息
Warning message in R plm package regarding indexes that have the same length but not the same content
当我执行模型的“summary()”时,我从 R 中的 plm 包收到一条警告消息:
1: In Ops.pseries(y, bX) : indexes of pseries have same length but
not same content: result was assigned first operand's index
2: In Ops.pseries(y, bX) : indexes of pseries have same length but not
same content: result was assigned first operand's index
我使用了以下代码:
library(dplyr)
library(lubridate)
library(plm)
data <- data.frame(ID = rep(c("123456", "234567", "345678", "456789", "567890", "678901", "789012", "890123", "901234","9012345"), each = 24),
month = rep(seq(dmy("01.01.2019"), dmy("01.12.2020"), by = "1 months"),10), group = rep(c(rep(T, 12), rep(F, 12)), 10),
temperature = runif(24*10, 0, 1)) %>%
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3)))
pdata <- pdata.frame(x = data, index = c("ID", "month"))
model <- plm(formula = consumption ~ group + temperature, data = pdata, effect = "individual", model = "within")
summary(model)
## Warnmeldungen:
## 1: In Ops.pseries(y, bX) :
## indexes of pseries have same length but not same content: result was assigned first operand's index
## 2: In Ops.pseries(y, bX) :
## indexes of pseries have same length but not same content: result was assigned first operand's index
我的想法是它可以是两个指数之一。但是,当我使用“ID”或“month”作为索引时,我会收到相同的警告消息。
输入的数据摘录如下所示:
似乎 plm
或 pdata.frame
不喜欢通过在估计之前对数据执行的某些转换将某些修改注入数据框。
确保像这样向 pdata.frame
提供一个干净的数据框,代码运行正常:
fdata <- data.frame(data)
pdata <- pdata.frame(x = fdata, index = c("ID", "month"))
model <- plm(formula = consumption ~ group + temperature, data = pdata, effect = "individual", model = "within")
summary(model)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = consumption ~ group + temperature, data = pdata,
## effect = "individual", model = "within")
##
## Balanced Panel: n = 10, T = 24, N = 240
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.581113 -0.237459 0.031184 0.252256 0.541147
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## groupTRUE -1.020820 0.038559 -26.4743 <2e-16 ***
## temperature -0.029801 0.064738 -0.4603 0.6457
## ---
## Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
##
## Total Sum of Squares: 82.792
## Residual Sum of Squares: 20.318
## R-Squared: 0.75459
## Adj. R-Squared: 0.74275
## F-statistic: 350.521 on 2 and 228 DF, p-value: < 2.22e-16
解决问题的另一种方法是添加ungroup()。
所以下面
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3)))
应该变成
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3))) %>% ungroup()
当我执行模型的“summary()”时,我从 R 中的 plm 包收到一条警告消息:
1: In Ops.pseries(y, bX) : indexes of pseries have same length but not same content: result was assigned first operand's index 2: In Ops.pseries(y, bX) : indexes of pseries have same length but not same content: result was assigned first operand's index
我使用了以下代码:
library(dplyr)
library(lubridate)
library(plm)
data <- data.frame(ID = rep(c("123456", "234567", "345678", "456789", "567890", "678901", "789012", "890123", "901234","9012345"), each = 24),
month = rep(seq(dmy("01.01.2019"), dmy("01.12.2020"), by = "1 months"),10), group = rep(c(rep(T, 12), rep(F, 12)), 10),
temperature = runif(24*10, 0, 1)) %>%
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3)))
pdata <- pdata.frame(x = data, index = c("ID", "month"))
model <- plm(formula = consumption ~ group + temperature, data = pdata, effect = "individual", model = "within")
summary(model)
## Warnmeldungen:
## 1: In Ops.pseries(y, bX) :
## indexes of pseries have same length but not same content: result was assigned first operand's index
## 2: In Ops.pseries(y, bX) :
## indexes of pseries have same length but not same content: result was assigned first operand's index
我的想法是它可以是两个指数之一。但是,当我使用“ID”或“month”作为索引时,我会收到相同的警告消息。
输入的数据摘录如下所示:
似乎 plm
或 pdata.frame
不喜欢通过在估计之前对数据执行的某些转换将某些修改注入数据框。
确保像这样向 pdata.frame
提供一个干净的数据框,代码运行正常:
fdata <- data.frame(data)
pdata <- pdata.frame(x = fdata, index = c("ID", "month"))
model <- plm(formula = consumption ~ group + temperature, data = pdata, effect = "individual", model = "within")
summary(model)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = consumption ~ group + temperature, data = pdata,
## effect = "individual", model = "within")
##
## Balanced Panel: n = 10, T = 24, N = 240
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.581113 -0.237459 0.031184 0.252256 0.541147
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## groupTRUE -1.020820 0.038559 -26.4743 <2e-16 ***
## temperature -0.029801 0.064738 -0.4603 0.6457
## ---
## Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
##
## Total Sum of Squares: 82.792
## Residual Sum of Squares: 20.318
## R-Squared: 0.75459
## Adj. R-Squared: 0.74275
## F-statistic: 350.521 on 2 and 228 DF, p-value: < 2.22e-16
解决问题的另一种方法是添加ungroup()。
所以下面
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3)))
应该变成
group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3))) %>% ungroup()