Hi, all
Have a problem when I processing panel data.
the basic situation is there are more 1,000 firms, have observations from 1998-2007(not necessarily have all of the 10 years for every firm),
and there would be a firm specific event and some year during its own time horizon.
what I want to do is to keep all those firms who have five consecutive observations, one year before the event occur, one year of the event, and three after the event occur.
for example, firm "101113645" 's event year is "2002", so if it has observations like 2001, 2002,2003,2004,2005, I will keep it as my sample, other wise,like you can see in the sample data
below, event year for this firm is 2002, but the year right before 2002 is 1998, not 2001, I will delete it.
how could I achieve this? spent a long time on this but still can't fix it.
I need help!!!
Have a problem when I processing panel data.
the basic situation is there are more 1,000 firms, have observations from 1998-2007(not necessarily have all of the 10 years for every firm),
and there would be a firm specific event and some year during its own time horizon.
what I want to do is to keep all those firms who have five consecutive observations, one year before the event occur, one year of the event, and three after the event occur.
for example, firm "101113645" 's event year is "2002", so if it has observations like 2001, 2002,2003,2004,2005, I will keep it as my sample, other wise,like you can see in the sample data
below, event year for this firm is 2002, but the year right before 2002 is 1998, not 2001, I will delete it.
how could I achieve this? spent a long time on this but still can't fix it.
I need help!!!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float year str9 firmid float event_year 1998 "101101628" 2003 1999 "101101628" 2003 2000 "101101628" 2003 2001 "101101628" 2003 2002 "101101628" 2003 2003 "101101628" 2003 2004 "101101628" 2003 2005 "101101628" 2003 2006 "101101628" 2003 2007 "101101628" 2003 1998 "101105573" 1999 1999 "101105573" 1999 2000 "101105573" 1999 2001 "101105573" 1999 2002 "101105573" 1999 1999 "101113645" 2002 2002 "101113645" 2002 2003 "101113645" 2002 2004 "101113645" 2002 2005 "101113645" 2002 end

Comment