Need cumulative sum but not for the entire series

#1
Hello,

I need to create the cumulative sum for a time variable for each person.

The first column has the personid. The second column has the information about time spent (time_spent) at each point.

Now, i want another column which gives me the cumulative time spent (CUMUL_TIME) by the person. Thus, the CUMUL_TIME variable always starts with zero and goes until the maximum value for each person. Can anyone please suggest me a way to do this?
 
#2
Here you go:

Code:
sort cases by personid.
compute cumul_time = time_spent.
if (personid = lag(personid)) cumul_time = cumul_time + lag(cumul_time).
exe.