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
Local and global macro are not capturing variables' names but the values in the first rowDear all, I have a problem when using the local and global macro. When I set up a local macro base…
Nested Variables in glmI am trying to use nested variables in glm because I have a non-normal dependent variable potentiall…
Foreach Loop to Rename VariableDear all, I was trying to use foreach loop to rename variables, I wanted to names of the variables …
How to calculate ten-year moving average of variable x by the dummy variable europe in a dataset as the following? Many thanks! Code: * Example generated by -dataex-. To install: ssc install dataex clear input float id_number i…
clustering and concentration Stata code Hi everyone, I am in the process of writing one of my dissertation chapters. Using US Census and A…
Subscribe to:
Post Comments (Atom)
0 Response to Panel data: mean per person for certain time period
Post a Comment