Hello together,
I use Stata 17 and have data that looks like this:
I want to create a new variable that takes the mean of growlag6_1 (December-April) per year and contains this mean value in its value slots for all 12 months of the given year. I tried to solve this by using
However, it seems like this command cannot handle the missing values because the resulting mean is incorrect. Do you have an idea how to solve this? Thank you!
Best,
Peter
I use Stata 17 and have data that looks like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte month float growlag6_1 1982 1 . 1982 2 . 1982 3 . 1982 4 . 1982 5 . 1982 6 . 1982 7 . 1982 8 . 1982 9 . 1982 10 . 1982 11 . 1982 12 . 1983 1 -.8965766 1983 2 -.8536214 1983 3 -1.1194961 1983 4 -.7394078 1983 5 . 1983 6 . 1983 7 . 1983 8 . 1983 9 . 1983 10 . 1983 11 . 1983 12 1.0059717 1984 1 .461578 1984 2 -.064775355 1984 3 -.4874977 1984 4 -.6169059 1984 5 . 1984 6 . 1984 7 . 1984 8 . 1984 9 . 1984 10 . 1984 11 . 1984 12 .021989904 1985 1 .05275526 1985 2 .3495794 1985 3 .0751656 1985 4 -.3113486 1985 5 . 1985 6 . 1985 7 . 1985 8 . 1985 9 . 1985 10 . 1985 11 . 1985 12 .3685137 1986 1 .13611127 1986 2 .021089263 1986 3 -.09093564 1986 4 -.10236227 1986 5 . 1986 6 . 1986 7 . 1986 8 . 1986 9 . 1986 10 . 1986 11 . 1986 12 -1.581145 1987 1 -1.7825167 1987 2 -1.7077404 1987 3 -1.1667379 1987 4 -1.1837677 1987 5 . 1987 6 . 1987 7 . 1987 8 . 1987 9 . 1987 10 . 1987 11 . 1987 12 .9539546 1988 1 .3803727 1988 2 .4067596 1988 3 -.04841128 1988 4 -.72443 1988 5 . 1988 6 . 1988 7 . 1988 8 . 1988 9 . 1988 10 . 1988 11 . 1988 12 .51243 1989 1 -.03726343 1989 2 -.32369575 1989 3 .13528158 1989 4 .1882625 1989 5 . 1989 6 . 1989 7 . 1989 8 . 1989 9 . 1989 10 . 1989 11 . 1989 12 .6406555 1990 1 .5858638 1990 2 1.0911701 1990 3 1.127725 1990 4 1.0045696 end
Code:
egen meanlag6=mean(growlag6_1), by(year)
Best,
Peter

Comment