Skip to content
Prev 300949 / 398503 Next

Creating panel data

This looks really ugly but it 'may' do what you want.  I was too lazy to generate enough raw data to check.  Note i changed the names in x as they were a bit clumsy.



 x <- data.frame( id = c(1,2), Event1= c(1,0), YEvent1 =
   c(68.25,0), Event2 = c(0,1), YEvent2 = c(0,68.5))

y   <-   data.frame(   id   =   c(   rep  (1,5),  rep  (2,5)),  Year=c
   (68.0,68.25,68.50,68.75,69.0))
   y $ Event1 <- c (0,1,1,1,1,0,0,0,0,0)
   y $ Event2 <- c (0,0,0,0,0,0,0,1,1,1)


 x <- data.frame( id = c(1,2), Event1= c(1,0), YEvent1 =
   c(68.25,0), Event2 = c(0,1), YEvent2 = c(0,68.5))

dd  <-  melt(x, id= c("id", "Event1", "Event2"),
          value.name="year.quarter" )
dd1  <-  subset(dd, dd[, 5] != 0 )

dd1  <-  dd1[ , c(1,2,3,5)]


John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!