Here diff has some estimate and for each observation - let's say if fyear = 2020, I need to calculate the sum of diff past 16 quarters including 2020.

gen sig = .
replace sig = sum(diff) if(co_code_i == co_code_i[_n] & co_code_j == co_code_j[_n] & nic_prod_code == nic_prod_code[_n] & fyear >= fyear[_n]-3 & fyear <= fyear[_n])

I'm not getting the desired output. Can anyone please suggest a way to perform this operation?