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
Related Posts with Panel data: mean per person for certain time period
Xtreg vs REGFEHD, time varied weightsI am running a panel regression with the returns of various mutual funds as a function of time varie…
generate dummy variable using strposHi everyone! I have searched this forum and read the official stata help section, but I'm still not…
forvalues with indefinite end valueI would like to use a do loop to read in a series of excel files, save them as .dta files, then appe…
Interaction term and lincomHi all, I am running a basic interaction model y=b0 + b1X1 + b2D + b3X1*D. where D is a dummy varia…
advice on using duplicates drop commandHello, I would like to make use of "duplicates drop" command to drop out certain rows, For example,…
Subscribe to:
Post Comments (Atom)
0 Response to Panel data: mean per person for certain time period
Post a Comment