My data is employment spell data, pid being person id, syear being the start of the spell and eyear being the end.
As you can see, many spell dates seem to overlap- e.g. many begin with 1996 and end in different years.
What command can I use to keep the last line (syear=1996 eyear=2008) but delete the other spell observations for which syear=1996?
So basically I want to keep the observation if the next observation's syear is NOT the same, and the next year's pid IS the same, to get rid of the overlaps.
Here is an example of the data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long pid int(syear eyear)
1170296 1989 1991
1170296 1989 1991
1170296 1991 1992
1170296 1991 1993
1170296 1992 1994
1170296 1994 1994
1170296 1991 1995
1170296 1995 1995
1170296 1995 1995
1170296 1995 1996
1170296 1996 1996
1170296 1966 1997
1170296 1996 1998
1170296 1996 1999
1170296 1996 2000
1170296 1996 2001
1170296 1996 2002
1170296 1996 2003
1170296 1996 2004
1170296 1996 2005
1170296 1996 2006
1170296 1996 2007
1170296 1996 2008
1145567 1993 1995
1145567 1997 1998
1145567 1997 1999
end
[/CODE]
So eg. for person 1145567 I would like to delete the 1997-1998 observation.
As you can see, many spell dates seem to overlap- e.g. many begin with 1996 and end in different years.
What command can I use to keep the last line (syear=1996 eyear=2008) but delete the other spell observations for which syear=1996?
So basically I want to keep the observation if the next observation's syear is NOT the same, and the next year's pid IS the same, to get rid of the overlaps.
Here is an example of the data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long pid int(syear eyear)
1170296 1989 1991
1170296 1989 1991
1170296 1991 1992
1170296 1991 1993
1170296 1992 1994
1170296 1994 1994
1170296 1991 1995
1170296 1995 1995
1170296 1995 1995
1170296 1995 1996
1170296 1996 1996
1170296 1966 1997
1170296 1996 1998
1170296 1996 1999
1170296 1996 2000
1170296 1996 2001
1170296 1996 2002
1170296 1996 2003
1170296 1996 2004
1170296 1996 2005
1170296 1996 2006
1170296 1996 2007
1170296 1996 2008
1145567 1993 1995
1145567 1997 1998
1145567 1997 1999
end
[/CODE]
So eg. for person 1145567 I would like to delete the 1997-1998 observation.
Comment