Re: [R] creating lagged variable in panel data

2012-08-29 Thread Alok Bohara, PhD
Sorry, this is what I used : f <- function(x) { wage <- ts(x$wage, start = x$year[1]) idx <- seq(length = length(wage)) wages <- cbind(wage, wage.lag1 = lag(wage, -1))[idx,] cbind(x, wages) } result <- do.call("rbin

Re: [R] creating lagged variable in panel data

2012-08-29 Thread R. Michael Weylandt
On Wed, Aug 29, 2012 at 8:20 PM, Alok Bohara, PhD wrote: > Thanks for the input. I wanted to avoid counting the column number. In > any case, in the script -- wage.lag1 = lag(wage, -1) seems to do the trick. The important thing is that "4" in my example below can be any computable expression:

Re: [R] creating lagged variable in panel data

2012-08-29 Thread Alok Bohara, PhD
Thanks for the input. I wanted to avoid counting the column number. In any case, in the script -- wage.lag1 = lag(wage, -1) seems to do the trick. Alok On 8/29/2012 12:29 PM, R. Michael Weylandt wrote: Of course: colnames(dats)[4] <- "new name" M On Aug 29, 2012, at 9:34 AM, "Alok K

Re: [R] creating lagged variable in panel data

2012-08-29 Thread arun
ot;,6:10)) names(wage2.dat)[4]<-"wag.lag1" A.K. - Original Message - From: "Alok K Bohara, PhD" To: R-help@r-project.org Cc: Sent: Wednesday, August 29, 2012 10:34 AM Subject: [R] creating lagged variable in panel data Hi I found an example in R to create a

Re: [R] creating lagged variable in panel data

2012-08-29 Thread R. Michael Weylandt
Of course: colnames(dats)[4] <- "new name" M On Aug 29, 2012, at 9:34 AM, "Alok K Bohara, PhD" wrote: > Hi > > I found an example in R to create a lagged panel data set which works fine. > The only problem is that it adds the lagged variable as follows > > wage2.dat > > year pers

[R] creating lagged variable in panel data

2012-08-29 Thread Alok K Bohara, PhD
Hi I found an example in R to create a lagged panel data set which works fine. The only problem is that it adds the lagged variable as follows wage2.dat year personwagelag(wage, -1) 1.1 1980 1 -0.75843997NA 1.2 1981 1 0.27233048 -0.7584399