Hello,
I'm working on a thesis data project where I need to calculate the average income of each individual over the past 16 years but for each of their recorded years in the panel data. For instance, an individual might have 25 years of income observations, but for each year, I want to calulate the average of the last 16 years. The reasoning behind this is that this data is for parents and will later be matched with their 16-year-old children to act as a control for average parental income during childhood.
I assume that a loop is the best method here, however I cannot figure out how to write the code.
Please see an example of the panel data (for one individual out of a million) I'm using:
Any help and guidance would be greatly appreciated. I apologise if my explanation is unclear.
Many thanks,
Elsa
I'm working on a thesis data project where I need to calculate the average income of each individual over the past 16 years but for each of their recorded years in the panel data. For instance, an individual might have 25 years of income observations, but for each year, I want to calulate the average of the last 16 years. The reasoning behind this is that this data is for parents and will later be matched with their 16-year-old children to act as a control for average parental income during childhood.
I assume that a loop is the best method here, however I cannot figure out how to write the code.
Please see an example of the panel data (for one individual out of a million) I'm using:
Individual ID code | Year | Income |
12 | 1989 | 20000 |
12 | 1990 | 20100 |
12 | 1991 | 20200 |
12 | 1992 | 21000 |
12 | 1993 | 0 |
12 | 1994 | 22000 |
12 | 1995 | 22200 |
12 | 1996 | 23000 |
12 | 1997 | 24000 |
12 | 1998 | 25000 |
12 | 1999 | 26000 |
12 | 2000 | 30000 |
12 | 2001 | 30000 |
12 | 2002 | 30100 |
12 | 2003 | 31000 |
12 | 2004 | 32000 |
12 | 2005 | 32000 |
12 | 2006 | 33000 |
12 | 2007 | 33100 |
Any help and guidance would be greatly appreciated. I apologise if my explanation is unclear.
Many thanks,
Elsa
Comment