Is there a way to check whether there is a new person in my grouped data?
HospitalID PersonID Year
1 1 2005
1 2 2005
1 3 2005
1 1 2006
1 2 2006
1 3 2006
1 4 2006
2 5 2005
2 6 2005
2 7 2005
2 5 2006
2 6 2006
2 8 2006
3 9 2005
3 10 2005
3 9 2006
3 10 2006
As shown above, there were 1, 2, and 3 in hospital A in year 2005. There is a new person, 4, in year 2006. In this case, I would like to give a value of 1 to observations of hospital 1 and year 2006 (i.e., 1 for the observations of groups where there is a new person).
In hospital 2, there are 5, 6, and 7 in year 2005. But next year, 7 left while 8 joined. In this case, I would like to assign missing to the observations of this group (i.e., hospital 2 - year 2006).
In hospital 3, there are 9 and 10 in years 2005 and 2006. For the observations of this group, I would like to assign 0 to the observations of this group.
The resulting dataset would be either at hospital-year level or at hospital-person-yearl level, whichever is OK for me. Is there a simple way to make this dataset? Thanks in advance!
... View more