R/lag.Y.R

Defines functions lag.Y

###############################################################
###############################################################
###############################################################

# Create a lag variable
# the data is lag within person and within days

lag.Y = function(data){ 

Y_lag = rep(0,nrow(data))
subjno.i = unique(data$subjno)
for (i in subjno.i){
n.i = which(data$subjno==i)
Y_lag[n.i] = data.table::shift(data$Y[n.i],1)
}

return(Y_lag)
}
ginettelafit/PowerAnalysisIL documentation built on July 8, 2023, 5:57 a.m.