Dear all,

Currently I have a database of funds holdings of a particular stock with the time series being in quarters. I would like to calculate how many portfolio firms held the investment company during a given quarter.

For example, in quarter 1, 5 different portfolios held the investment company, and in quarter 2, 5 different portfolios held the investment company and so forth. I would like to do this for the entire dataset, with roughly 1500 companies and 41 quarters, where I would like to calculate by stock and quarter, how many portfolios held the particular investment company.
year quarter investment company portfolio firm number of shares stock price of each holding firm
1996 1 1001 a 1000 3.33
1996 1 1001 b 1200 3.33
1996 1 1001 c 1300 3.33
1996 1 1001 d 1100 3.33
1996 1 1001 e 1050 3.33
1996 2 1001 a 1100 4.44
1996 2 1001 b 1100 4.44
1996 2 1001 c 1200 4.44
1996 2 1001 d 1400 4.44
1996 2 1001 e 0 4.44
1996 3 1001 a 900 5.55
1996 3 1001 b 1300 5.55
1996 3 1001 c 1200 5.55
1996 3 1001 d 1400 5.55
1996 4 1001 a 1200 6.66
1996 4 1001 b 1030 6.66
1996 4 1001 c 1000 6.66
1996 4 1001 d 1409 6.66
1997 1 1001 a 2000 7.77
1997 1 1001 b 1700 7.77
1997 1 1001 c 1344 7.77
1997 1 1001 d 1278 7.77
1997 2 1001 a 1900 8.88
1997 2 1001 b 2000 8.88
1997 2 1001 c 1300 8.88
1997 2 1001 d 700 8.88
Thank you all for your help!