Running sum

#1
Dear All,

I have the following dataset
***********************************
clear
input rssd9001_bk1 rssd9001_bk2 year dealid obs
12311 60143 1998 34844 1
12311 60143 1999 867 1
12311 60143 2000 31386 1
12311 60143 2000 34844 1
12311 60143 2001 31386 1
12311 60143 2002 132471 1
12311 60143 2003 3571 1
12311 60143 2003 185393 1
12311 60143 2004 3571 1
12311 60143 2004 119602 1
12311 60143 2005 112613 1
12311 60143 2005 119602 1
12311 60143 2005 123326 1
12311 60143 2006 78468 1
12311 60143 2006 123326 1
12311 60143 2011 60178 1

end
*********************************
Briefly, I have bank relationships. The first observation shows that bank_bk1 has a collaboration with bank_bk2 for deal id 34844 in 1998. The second observation shows that bank_bk1 has a collaboration with bank_bk2 for dealid 867 in 1999.

I want to create a new variable (total) that will summarize the total number of observations between banks before the current year. For example i want something like the following one:

rssd9001_bk1 rssd9001_bk2 fyear dealid obs total
12311 60143 1998 34844 1 1
12311 60143 1999 867 1 2
12311 60143 2000 31386 1 3
12311 60143 2000 34844 1 4
12311 60143 2001 31386 1 5
12311 60143 2002 132471 1 6
12311 60143 2003 3571 1 7
12311 60143 2003 185393 1 8
12311 60143 2004 3571 1 9