2

I get a warning message from the plm package in R when I perform ´summary()´ of a model:

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

I used the following code:

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

My thought was that it could be one of the two indices. However, I get the same warning message when I either use "ID" or "month" as index.

An excerpt of the data feed in look like this: enter image description here

noslomo
  • 58
  • 7
  • Any chance you can make the data available? Also, from the code you supplied it is not clear which command gives the warning: `plm`, `pdata.frame`, or `summary` – Helix123 Nov 13 '20 at 10:28
  • Thank you @Helix123 for your answer. The warning is from `summary(model)` and stems from the [groupGenerics_pseries.R](https://rdrr.io/cran/plm/src/R/groupGenerics_pseries.R) I have added an excerpt of the data. – noslomo Nov 13 '20 at 15:25
  • I meant data that allows for replication of the issue, see, e.g., here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Helix123 Nov 13 '20 at 15:37
  • Thank you @Helix123 for your answer. Unfortunately this is not possible due to privacy reasons. – noslomo Nov 13 '20 at 15:44
  • Understood. So I would assume if you cannot provide a reproducable set-up (could be a non-privacy-violating subset of your data), nobody will be able to help. As the functions you are using are well tested, I would also assume the error is somewhere else. – Helix123 Nov 13 '20 at 18:33
  • I could generate a reproducable set-up (see above in the script). I hope this helps you @Helix123 and others to identify the issue. – noslomo Nov 16 '20 at 09:14
  • Thank you. Your code was not fully reproducible as function `dmy` seems to stems from non-declared package `lubridate`. I added it to your code (and put the call to `pdata.frame` in its own line). Please see my answer. – Helix123 Nov 16 '20 at 10:23

2 Answers2

3

It seems like plm or pdata.frame does not like some modifications injected into the data frame by some transformation you perform on the data prior to estimation.

Make sure to feed a clean data frame to pdata.frame like this and the code runs fine:

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
Helix123
  • 3,502
  • 2
  • 16
  • 36
  • Thanks a lot @Helix123. This solved my problem. It seems like using a tibble instead of a data.frame results in this warning. – noslomo Nov 16 '20 at 12:51
  • The current development version of plm has the call to `data.frame()` build into `pdata.frame` as a security measure. – Helix123 Nov 20 '20 at 22:49
1

Another way of solving the problem is to add ungroup().

So the following

group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3)))

should become

group_by(ID, group) %>% mutate(consumption = ifelse(group, runif(12, 1,2), runif(12,2,3))) %>% ungroup()
AcK
  • 2,063
  • 2
  • 20
  • 27
Bas Bakker
  • 11
  • 1