0

I have panel data that right now has t1 and t2 observations in the same row. I want to convert it into the typical "long" format, so that for each id, there is a unique row for t1 and t2 observations.

Here's a snippet to create an example of the data:

id <- c(1, 2, 3, 4, 5, 6)
t1_date <- c(2000, 2001, 2000, 2002, 2003, 2004)
t2_date <- c(2001, 2002, 2003, 2003, 2004, 2005)
t1_x <- c(4, 3, 7, 8, 1, 5)
t2_x <- c(3, 8, 5, 6, 3, 9)

data <- data.frame(cbind(id, t1_date, t2_date, t1_x, t2_x))

Here's what the example looks like: Example data

Here's what I want it to look like: Desired format

I'm not sure what to try. Thanks for any and all help!

zjablow
  • 1
  • 1

0 Answers0