Averaging data over 5 years with Stata or Excel I need Stata commands or Excel function to calculate the average over 5 years groups of the values in a panel dataset. In particular, this procedure as to take into account the presence of possible missing values (empty cells in Excel) and thus adjust the computation accordingly to the actual number of non-missing in the period.
Is this what you want (in Stata)?

 clear all
 * Generate Data (n=5, T=20)
 set obs 100
 gen id = floor((_n-1)/20)+1
 by id, sort: gen year = 1990+_n
 gen x = rnormal()
 xtset id year
 * Convert
 gen t5 = floor((year-1991)/5)+1
 gen idt5 = id*10+t5 /* 10 can be 100, 1000, etc., depending on T */
 by idt5, sort: egen xbar5 = mean(x)
 *drop t5 idt5  /* drop if you want; you can also use tempvar */


If not, please clarify your question using an example.