Summing values up

#1
Hi!

I have a payoff variable for individuals, each uniquely identified by their ID variable. The payoff for each person also each spans over four consecutive days (not necessarily the same ones), which has its own variable with values ranging from 1-4.

My question is how would you generate a variable that displays the accumulating payoffs for days 1-4 for each ID?

For example, if the payoff for person A is 1 1 1 1 for each day respectively and for person B this is 2 2 2 2,
the new variable should then show payoffs for A: 1 2 3 4 and for B: 2 4 6 8.

Any help is much appreciated!
Cheers!
 

bukharin

RoboStataRaptor
#2
bysort person (day): gen newvar=sum(payoff)

What this does is:
1. sorts by person then day
2. for each person, newvar is calculated as a running sum of the payoffs (the sum() function calculates running sums)