I am hitting a wall trying to create a variable that is a conditional sum where it looks at the score for a certain observation and sums all scores less than it in a particular day.

Here is some code to recreate the issue:

Code:
set obs 10000
set seed 1979

* Creating sample dataset
gen score = runiform()*100
gen day = runiformint(1,31)
bysort day (score): gen daily_rank = _n
Therefore, for each sorted observation, there would be a variable that is a reducing amount until the next day. That variable would look at the score for that observation (say, 80, for example) and sum all observations in that day that have scores from 0 to 79. I have not been able to figure out how to do this.

Thanks in advance!