I have a question that I cannot seem to figure out by myself and I can't find an answer on the internet.
I want to look at the average of wind speeds over the five previous and how it affects wind turbine construction.
My data currently looks like this:
dist_code | year | wind_speed |
3154 | 1995 | 3.7 |
3154 | 1996 | 3.728947 |
3154 | 1997 | 4.152822 |
3154 | 1998 | 4.138276 |
3154 | 1999 | 3.912632 |
3154 | 2000 | 3.830851 |
3154 | 2001 | 3.751 |
3154 | 2002 | 4.137689 |
3155 | 1995 | 2.952615 |
3155 | 1996 | 2.832849 |
3155 | 1997 | 3.146398 |
3155 | 1998 | 3.342508 |
3155 | 1999 | 3.167976 |
3155 | 2000 | 3.104127 |
3155 | 2001 | 2.838462 |
3155 | 2002 | 2.686159 |
However, I would like to have a fourth column, showing the average wind speed over the last 5 years, so something like:
dist_code | year | wind_speed | wind_speed_prev_5yr_avg |
3154 | 1995 | 3.7 | |
3154 | 1996 | 3.728947 | |
3154 | 1997 | 4.152822 | |
3154 | 1998 | 4.138276 | |
3154 | 1999 | 3.912632 | |
3154 | 2000 | 3.830851 | 3.884 |
3154 | 2001 | 3.751 | 3.91 |
3154 | 2002 | 4.137689 | 3.82 |
3155 | 1995 | 2.952615 | |
3155 | 1996 | 2.832849 | |
3155 | 1997 | 3.146398 | |
3155 | 1998 | 3.342508 | |
3155 | 1999 | 3.167976 | |
3155 | 2000 | 3.104127 | 3.084 |
3155 | 2001 | 2.838462 | 3.015 |
3155 | 2002 | 2.686159 | 2.97 |
Is there an easy way to do this?
Thank you very much in advance.
0 Response to Generating the average of previous observations in a panel
Post a Comment