Dear all
I have daily minimum and maximum temperature data from 697 weather stations across 311 districts.
For each district i in month m of year t, I need to aggregate the daily temperature data into two threshold-based heat stress variables which are (1) growing degree-days GDD and (2) stress degree-days or SDD.

The GDD and SDD variables are defined as follows
Array
Where Tlow and Thigh are the maximum and minimum temperature in oC for district i on day d of month m and year t.
Tlow is the lower threshold and takes the value of 10, Thigh is upper threshold and takes the value 30 and Tk takes the value 35

GDDimt is heat accumulated within temperatures Tlow and Thigh and SDDimt is heat accumulated above Tk.

Any suggestions how to implement these specifications?