Dear all,
I am working on a panel dataset, in which the years (time dimension) available are 2001 2003 2005 2007 2009 and so on, every time skipping one year.
To make an example of the dataset:
I would like to insert for each ID a row for the missing years (2002 and 2004 in the example above) and for some selected variables (VarA and VarB in example) fill the gaps with the mean of the previous value with the following value. To give an example of the final result:
Do you know how to do this?
Thanks in advance for the help!
Luca.
I am working on a panel dataset, in which the years (time dimension) available are 2001 2003 2005 2007 2009 and so on, every time skipping one year.
To make an example of the dataset:
ID | Year | VarA | VarB |
1 | 2001 | 10 | 5 |
1 | 2003 | 20 | 15 |
1 | 2005 | 30 | 25 |
2 | 2001 | 15 | 10 |
2 | 2003 | 25 | 20 |
2 | 2005 | 35 | 30 |
3 | 2001 | 60 | 65 |
3 | 2003 | 70 | 75 |
3 | 2005 | 80 | 85 |
ID | Year | VarA | VarB |
1 | 2001 | 10 | 5 |
1 | 2002 | 15 | 10 |
1 | 2003 | 20 | 15 |
1 | 2004 | 25 | 20 |
1 | 2005 | 30 | 25 |
2 | 2001 | 15 | 10 |
2 | 2002 | 20 | 15 |
2 | 2003 | 25 | 20 |
2 | 2004 | 30 | 25 |
2 | 2005 | 35 | 30 |
3 | 2001 | 60 | 65 |
3 | 2002 | 65 | 70 |
3 | 2003 | 70 | 75 |
3 | 2004 | 75 | 80 |
3 | 2005 | 80 | 85 |
Thanks in advance for the help!
Luca.
Comment