Dear all,

I'm trying to keep observations that satisfy a relatively simple condition, but am unable to do so.
I want to keep all observations within 365 days of a non-missing "score" observation, and that for each ID (I was thinking about a bysort ID: keep if ... expression, but couldn't come up with anything that works).
So, using the below example, for ID "045429", with score "46.561", I'd like to keep the four observations before that as well, since those are within 365 days of the focal observation of interest.

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str6 ID float date_completed double score
"045429" 19676                .
"045429" 19683                .
"045429" 19927                .
"045429" 20104                .
"045429" 20251                .
"045429" 20292                .
"045429" 20842 79.4864121235747
"045429" 20867 79.4864121235747
"045429" 21160                .
"045429" 21517                .
"045429" 21517                .
"045429" 21523                .
"045429" 21551                .
"045429" 21551                .
"045429" 21592                .
"045429" 21718                .
"045429" 21922                .
"045429" 21922                .
"045429" 21948                .
"045429" 22027                .
"045429" 22211 46.5613695595023
"04542L" 15330                .
"04543M" 17533                .
"04543M" 18567                .
"04543M" 19159                .
"04543P" 16919                .
"04543P" 18568                .
"04543V" 14889                .
"04543V" 14889                .
"04543V" 14889                .
"04543V" 15288                .
"04545E" 19464                .
end
format %d date_completed
Thanks for any help!