Skip to content
Prev 304526 / 398503 Next

creating lagged variable in panel data

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("rbind", by(A, A$person, f))
	result


Alok
On 8/29/2012 7:43 PM, R. Michael Weylandt wrote: