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
multiple imputation (-mi-) with the synthetic control method (-synth-)Has anyone combined multiple imputation with the synthetic control method (https://fmwww.bc.edu/repe…
P-values and CI's for dotplot?Hi you helpful people. I have measured a concentration of a medical drug 1 week after operation in …
Including prevalence ratio in table after glm using asdocHello, I would like to export prevalence ratios into a word table after a glm poisson model using t…
Plotting trends in relative and absolute inequalities using riigen and marginsHello, In a repeated cross-sectional designed study I would like to calculate the relative and abso…
Remove observations of a panel data set based on observations of specific yearsHi All, I have a panel data set as below (only an example and may not be balanced). I want to drop …
Subscribe to:
Post Comments (Atom)
0 Response to Panel data: mean per person for certain time period
Post a Comment