I hope you guys are all kidding. There is a very efficient way that any high school graduate should be able to figure out. It uses the following very difficult theorem:

Let 1 < x - 250 < x

Summation from (x-249) to (x) = summation from (1) to (x) - summation from (1) to (x-250)

In Stata, write:

gen log_return = log(return+1)

bysort firm (day): gen cumulative_sum = sum(log_return)

bysort firm (day): long_window_return = cumulative_sum[_n] - cumulative_sum[_n-250]

This cascading feature of Stata using `_n' comes in handy when you want to fill in missing values in a group with numbers that are already present in the group.