Dear R users, I am working with panel data and I want the difference of a variable with its t+1 value.
For example, I have a data frame as below. > a <- data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA)) > colnames(a) <- c("firm","year","var") I want the output to be as follows. > b <- data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA),c(10,34,23,12,NA,45, NA, 45, NA, NA)) > colnames(b) <- c("firm","year","var","var.lead") > b firm year var var.lead 1 2 2005 NA 10 2 2 2006 10 34 3 2 2007 34 23 4 2 2008 23 12 5 2 2009 12 NA 6 3 2004 23 45 7 3 2005 45 NA 8 3 2006 NA 45 9 3 2007 45 NA 10 3 2008 NA NA Could you tell me if such a function exists in the plm package? Thank you -- Apoorva Gupta Consultant National Institute of Public Finance and Policy [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.