Hello together!
I have Panel Data and I would like to create a variable which is the mean over the past 3 years per person.
bysort pid: gen sheep = (var1[_n-1]+var1[_n-2]+var1[_n-3])/3
would do the trick, if it wasn´t for missing values. For example if var1[_n-2] is missing, I´d like to have the mean with the remaining two values.
The "egen mean" function works wonderful with missing values, but I can´t find a way to change it so that is is only for a certain period of time.
For tips I would be very thankful.
Berit
0 Response to Panel data: mean per person for certain time period
Post a Comment