Hello Everyone,
I have an unbalanced panel dataset organized by firm id, year, age, and event. The event is a dummy if the event (=1) happened in that year. Events can happen more than once for each firm throughout the sample period.
For instance,
1. For id 1, the first time an event occurred was in the year 2007 and lasted for one year. The second time an event occurred was in the year 2011 and lasted to the year 2012. Thus, the duration of the second event lasted two years.
2. For id 2, the first time an event occurred was in the year 2007 and lasted to the year 2012, thus duration is six years.
3. For id 3, the first time an event occurred was in the year 2005 and lasted to the year 2008. Thus the duration of the first event lasted four years. The second time an event occurred was in the year 2011 and lasted to the year 2012. Thus, the duration of the second event lasted two years.
I'm trying to create multiple event dummy variable(s) so that I can sum the duration of events when an event (=1) occurred the first time, a second time, etc. by firm id.
What I want to do:
1. Create an event1 dummy variable in which only the duration of event1==1 happens and pre/post events ==0.
2. Create an event2 dummy variable in which only the duration of event2==1 happens and pre/post events ==0.
2. Create an event3 dummy variable in which only the duration of event3==1 happens and pre/post events ==0. And so forth…
. dataex id yr age event
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
Listed 24 out of 24 observations
I would really appreciate it if you could help me here. Many thanks in advance!
I have an unbalanced panel dataset organized by firm id, year, age, and event. The event is a dummy if the event (=1) happened in that year. Events can happen more than once for each firm throughout the sample period.
For instance,
1. For id 1, the first time an event occurred was in the year 2007 and lasted for one year. The second time an event occurred was in the year 2011 and lasted to the year 2012. Thus, the duration of the second event lasted two years.
2. For id 2, the first time an event occurred was in the year 2007 and lasted to the year 2012, thus duration is six years.
3. For id 3, the first time an event occurred was in the year 2005 and lasted to the year 2008. Thus the duration of the first event lasted four years. The second time an event occurred was in the year 2011 and lasted to the year 2012. Thus, the duration of the second event lasted two years.
I'm trying to create multiple event dummy variable(s) so that I can sum the duration of events when an event (=1) occurred the first time, a second time, etc. by firm id.
What I want to do:
1. Create an event1 dummy variable in which only the duration of event1==1 happens and pre/post events ==0.
2. Create an event2 dummy variable in which only the duration of event2==1 happens and pre/post events ==0.
2. Create an event3 dummy variable in which only the duration of event3==1 happens and pre/post events ==0. And so forth…
. dataex id yr age event
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id yr age event) 1 2006 1 0 1 2007 2 1 1 2008 3 0 1 2009 4 0 1 2010 5 0 1 2011 6 1 1 2012 7 1 2 2006 1 0 2 2007 2 1 2 2008 3 1 2 2009 4 1 2 2010 5 1 2 2011 6 1 2 2012 7 1 3 2003 1 0 3 2004 2 0 3 2005 3 1 3 2006 4 1 3 2007 5 1 3 2008 6 1 3 2009 7 0 3 2010 8 0 3 2011 9 1 3 2012 10 1 end
Listed 24 out of 24 observations
I would really appreciate it if you could help me here. Many thanks in advance!
Comment