Dear Forum,

first of all thank you for all previous answers you have provided - I would hav finished no project so far without your help.
I am currently facing a problem about counting observations, but could not find an answer in the forum so far. Possibly you could help?

My problem is the following.
I have a data set with investments of firms into companies over years. I am seeking to count the number of previous and current investments a firm has made (the variable thus changes over time). For example (see data below): I want for fund "a" a variable that counts the number of investment made in THIS AND IN PREVIOUS years. For example in 2001 it made two investments, in 2002 another two investments (combined with +2 from the previous years) etc.
I was thinking about doing this with a loop, but am unsure about it?

Help is very much appreciated!
Thank you very much!

Silke

Sample data:
Company Firm Year Variable I want
qw a 2001 2
ef a 2001 2
sg a 2002 4
rh a 2002 4
yf a 2008 5
ff a 2012 7
kr b 2012 7
fg b 2001 1
fj b 2002 2
ki b 2007 3