Wadim iLchuk
Wadim iLchuk

Reputation: 27

Number of items to be replace is not a multiple of replacement length

I am using prodest package in R. And everything worked fine until one moment.

Here are 2 datasets

  1. The function works for this: https://docs.google.com/spreadsheets/d/1Ecj9Otj6pb7nu5BSe0alk6Q0FpryK0xnMVWz5S2wa2Q/edit?usp=sharing

  2. Here doesn't: https://docs.google.com/spreadsheets/d/1ECxkygPH6SmKmJpRrFIQ4xNekKHtKjnmnFA3_WwjjpY/edit?usp=sharing

The code is the following:

SK_AB <- read.csv("adata.csv", header = TRUE, sep = ",")

AB <- prodest::prodestACF(SK_AB$turn, fX = SK_AB$l, sX = SK_AB$tfa, pX = SK_AB$m, idvar = SK_AB$ID, timevar = SK_AB$Year, 
                          R = 20, cX = NULL, opt = "DEoptim", theta0 = NULL, cluster = NULL)

Source code for the function: https://github.com/GabrieleRovigatti/prodest/blob/master/prodest/R/prodestACF.R

In the function description, the part of the code that gives the error is:

sX <- checkM(sX)
idvar <- checkM(idvar)
timevar <- checkM(timevar)
snum <- ncol(sX) # find the number of input variables
  
  lag.sX = sX # generate sX lags
  for (i in 1:snum) {
    lag.sX[, i] = lagPanel(sX[, i], idvar = idvar, timevar = timevar)
  }

The error I receive is this: enter image description here

I do not know why the exact same structure of one file works, and the same structure for the same function not.

UPD: links are now for the needed files

Upvotes: 0

Views: 293

Answers (1)

Jack Ma
Jack Ma

Reputation: 11

I had the same error message. It turned out my problem was that my panel data was problemetic, in the sense that within each individual panel there were repeated time values. For example, for id = Tom, in year 2007 there were two observations. This repeated time within panel will create problem in the lagpanel function as it involves a leftjoin using time and lagged_time.

Upvotes: 1

Related Questions