Not sure if this is on-topic, but I'll give a simple solution. It's perhaps not the most efficient, but should be easy enough to follow.
Assuming you also want to keep "category" and not just "id", how about something like the following:
use sample.dta, clear
keep if month==8 | month==9
collapse value , by(year ...