Hello!
Currently, I am working with Stata 18.0. My data looks like,
Now, here, an event occurs at a different period for every ID, listed under the variable event. I want to create a variable Event_year, which will list the event period for every year. That is, I want to get the following result:
Could anyone please help me with the code here?
Thank you so much!
Currently, I am working with Stata 18.0. My data looks like,
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(ID event year Event_year) 1 . 2001 2002 1 2002 2002 2002 1 . 2003 2002 1 . 2004 2002 1 . 2005 2002 1 . 2006 2002 1 . 2007 2002 2 . 2001 2005 2 . 2002 2005 2 . 2003 2005 2 . 2004 2005 2 2005 2005 2005 2 . 2006 2005 2 . 2007 2005 3 . 2001 2003 3 . 2002 2003 3 2003 2003 2003 3 . 2004 2003 3 . 2005 2003 3 . 2006 2003 3 . 2007 2003 4 . 2001 . 4 . 2002 . 4 . 2003 . 4 . 2004 . 4 . 2005 . 4 . 2006 . 4 . 2007 . end
Now, here, an event occurs at a different period for every ID, listed under the variable event. I want to create a variable Event_year, which will list the event period for every year. That is, I want to get the following result:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(ID event year Event_year) 1 . 2001 2002 1 2002 2002 2002 1 . 2003 2002 1 . 2004 2002 1 . 2005 2002 1 . 2006 2002 1 . 2007 2002 2 . 2001 2005 2 . 2002 2005 2 . 2003 2005 2 . 2004 2005 2 2005 2005 2005 2 . 2006 2005 2 . 2007 2005 3 . 2001 2003 3 . 2002 2003 3 2003 2003 2003 3 . 2004 2003 3 . 2005 2003 3 . 2006 2003 3 . 2007 2003 4 . 2001 . 4 . 2002 . 4 . 2003 . 4 . 2004 . 4 . 2005 . 4 . 2006 . 4 . 2007 . end
Could anyone please help me with the code here?
Thank you so much!
Comment