I have the following issue with my dataset. Every observation applies to multiple years (beginning year until ending year) but only a single observation is created. Because of this I want to create new observations for the missing ones. For example, the first observation applies to 2002 and 2003 but only 2002 is present in my dataset so I want to add 2003. I was able to create a variable years_to_fill that states how many observations I want to create after the current observation. So for the first observation, I want to create 1 new observation and label that with year+1. I tried using tsset with tsfill but this doesn't work for all my observations. For example, for id 4 I want to create three new observations, 1991 1992 and 1993. If I do tsfill id year it however doesn't create any new observations. Can somebody please tell me how I am supposed to do this?
Thanks in advance
Norbert Langerak
id | year | beg_year | end_year | years_to_fill |
1 | 2002 | 2002 | 2003 | 1 |
1 | 2004 | 2004 | 2005 | 1 |
1 | 2006 | 2006 | 2007 | 1 |
2 | 2004 | 2004 | 2005 | 1 |
2 | 2006 | 2006 | 2007 | 1 |
3 | 1998 | 1998 | 2000 | 1 |
3 | 2000 | 2000 | 2002 | 1 |
3 | 2002 | 2002 | 2003 | 1 |
3 | 2004 | 2004 | 2005 | 1 |
4 | 1990 | 1990 | 1993 | 3 |
5 | 1998 | 1998 | 2000 | 1 |
5 | 2000 | 2000 | 2002 | 1 |
5 | 2002 | 2002 | 2003 | 1 |
6 | 1990 | 1990 | 1993 | 2 |
6 | 1993 | 1993 | 1995 | 1 |
6 | 1995 | 1995 | 1998 | 3 |
7 | 1993 | 1993 | 1995 | 1 |
7 | 1995 | 1995 | 1998 | 2 |
7 | 1998 | 1998 | 2000 | 1 |
7 | 2000 | 2000 | 2002 | 1 |
7 | 2002 | 2002 | 2003 | 1 |
7 | 2004 | 2004 | 2005 | 1 |
7 | 2006 | 2006 | 2007 | 1 |
8 | 2006 | 2006 | 2007 | 1 |
9 | 2004 | 2004 | 2005 | 1 |
9 | 2006 | 2006 | 2007 | 1 |
10 | 1990 | 1990 | 1993 | 2 |
10 | 1993 | 1993 | 1995 | 1 |
10 | 1995 | 1995 | 1998 | 3 |
10 | 2002 | 2002 | 2003 | 1 |
10 | 2004 | 2004 | 2005 | 1 |
10 | 2006 | 2006 | 2007 | 1 |
11 | 2006 | 2006 | 2007 | 1 |
12 | 1990 | 1990 | 1993 | 3 |
0 Response to Creating new years
Post a Comment