A recent discussion (closed group/registration required) on the Stata users LinkedIn group highlights the use of recode to create 5 year periods in a panel dataset. The question asks how to take yearly data and create a variable that contains the 5-year average of some data.
The first step is to recode your year data to 5 year periods. One does this by running:
recode year2 (2001/2005 = 2000) (2006/2010 = 2006), gen(year2)
Then, to take care of creating averages of X by period one uses the -collapse- command by running:
collapse (mean) X, by(year2 id)
where id is a unique identifier for each cross-sectional entity in the dataset. Good luck!