Hi,
Consider the data below. I would like to calculate the number of years each worker has done the task 1 since he has been employed in an agency. As you can see there are some jumps and change of task in the data so I would like to include that. Also, I want the tenure variable to be the number of years each worker has done task==1 prior to that year. So for worker 1, his tenure in 1996 is equal to 0 and his tenure in 1997 is 1, and his tenure in 2000 is 3. How can I code this?
Hope it makes sense
Consider the data below. I would like to calculate the number of years each worker has done the task 1 since he has been employed in an agency. As you can see there are some jumps and change of task in the data so I would like to include that. Also, I want the tenure variable to be the number of years each worker has done task==1 prior to that year. So for worker 1, his tenure in 1996 is equal to 0 and his tenure in 1997 is 1, and his tenure in 2000 is 3. How can I code this?
Hope it makes sense
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(id year task) 1 1995 2 1 1996 1 1 1997 1 1 1998 1 1 1999 2 1 2000 1 1 2001 1 2 1998 1 2 1999 1 2 2003 1 2 2004 1 2 2005 1 2 2006 1 2 2007 1 end
Comment