I am using panel data and have some discrepancies in the age variable. For some respondents, their age increase or decrease by more than 1 from one year to another as we can see for respondents with ID number 2 and 3 below. This could be due to issues of data entries or other reasons that I cannot solve myself.
Could someone please guide me with how to create a new variable that detects people who either had an increase in their age by more than 1 value or had a decrease in their age from one year to another as it happens in ID 2 and 3 below?
id age year
1 25 2005
1 26 2006
1 27 2007
2 50 2006
2 51 2007
2 36 2008
3 25 2005
3 30 2006
structure(list(id = structure(c(1, 1, 1, 2, 2, 2, 3, 3), format.stata = "%9.0g"),
age = structure(c(25, 26, 27, 50, 51, 36, 25, 30), format.stata = "%9.0g"),
year = structure(c(2005, 2006, 2007, 2006, 2007, 2008, 2005,
2006), format.stata = "%9.0g")), row.names = c(NA, -8L), class = c("tbl_df",
"tbl", "data.frame"))