I have tried the diff and lag function. I have given an example below. Diff gives me a$var2.shift. I want a$var2.noshift, i.e. var^(t+2)-var^(t) should stay in the row with year=t. Diff shifts it to the t+2 row.
> 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") > a <- pdata.frame(a) > a$var2.shift <- diff(a$var, lag=2, difference=1) > a$var2.noshift <- c(NA, 13,-22,NA, NA,NA, 0, NA, NA, NA) > a firm year var var2.shift var2.noshift 2-2005 2 2005 NA NA NA 2-2006 2 2006 10 NA 13 2-2007 2 2007 34 NA -22 2-2008 2 2008 23 13 NA 2-2009 2 2009 12 -22 NA 3-2004 3 2004 23 NA NA 3-2005 3 2005 45 NA 0 3-2006 3 2006 NA NA NA 3-2007 3 2007 45 0 NA 3-2008 3 2008 NA NA NA On Tue, May 8, 2012 at 6:21 PM, Liviu Andronic <landronim...@gmail.com>wrote: > On Tue, May 8, 2012 at 12:14 PM, Apoorva Gupta <apoorva.ni...@gmail.com> > wrote: > > I have checked that. It allows me to get the t-1, t-2 value but not the > t+1 > > value. > > Is there any other way of achieving this other than using the plm > package? > > > It would be easier to help if you provided a minimal reproducible > example, as requested in the posting guide. Have you tried > diff(x, lag = -1, ...) > > or > lag(x, k = -1, ...) > > Perhaps this does what you want. Regards > Liviu > -- 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.