I found this posting useful:
https://www.statalist.org/forums/for...rage-by-groups
My bad that I didn't check the previous questions
(may discard below)
/*------------------------------------------------------------------------------------------------------------------
Hello,
I got into a weird and simple trouble when I tried to generate a three-year moving average.
My commands are followed ("id" is the unique identifier and "year" is the time variable):
And I get this error: "not sorted"
I don't have duplicates when I do "duplicates list id year".
What could be potential issues here??
I have 514 id's.
By the way, I am using State 14.0 in Windows 10.
https://www.statalist.org/forums/for...rage-by-groups
My bad that I didn't check the previous questions
(may discard below)
/*------------------------------------------------------------------------------------------------------------------
Hello,
I got into a weird and simple trouble when I tried to generate a three-year moving average.
My commands are followed ("id" is the unique identifier and "year" is the time variable):
Code:
xtset id year
[output]
panel variable: id (unbalanced)
time variable: year, 1979 to 2015, but with gaps
delta: 1 unit
sort id year
bysort id year: egen average= mean(L.k1 + L2.k1 + L3.k1)
I don't have duplicates when I do "duplicates list id year".
What could be potential issues here??
I have 514 id's.
By the way, I am using State 14.0 in Windows 10.

Comment