I would like to calculate how often changes between values happen by person-year combination (panel data). This mimics Stata's command xttrans
. The transition between index 6 and 7 should not be included, since it is not a transition from within one person.
df = data.frame(id=c(1,1,1,1,1,1,1,2,2,2,2,2,2,2),
year=seq(from=2003, to=2009, by=1),
health=c(3,1,2,2,5,1,1,1,2,3,2,1,1,2))