## This creates an irregularly spaced panel, with a gap in time for id = 2
data <- data.frame(id = rep(1:3, each = 4),
time = c(1:4, 1:2, 4:5, 1:4),
value = rnorm(12))
data
## This gave a gaps in time error previous to collapse 1.5.0
L(data, 1, value ~ id, ~time)
## Generating new id variable (here seqid(time) would suffice as data is sorted)
settransform(data, newid = seqid(time, order(id, time)))
data
## Lag the panel this way
L(data, 1, value ~ newid, ~time)
# \donttest{
## A different possibility: Creating a consecutive time variable
settransform(data, newtime = data.table::rowid(id))
data
L(data, 1, value ~ id, ~newtime)
# }
## With sorted data, the time variable can also just be omitted..
L(data, 1, value ~ id)
Run the code above in your browser using DataLab