Hello together,

I have a data set with companies, which conduct deals. Furthermore, these deals have the variables entry year, exit year, entryy_count and exity_count. Each deal has its own ID.

Here a short outline of my data set
Company Deal Entry year Exit year Entryy_count Exity_count Active_deals
1 1 2004 2006 3 2 4
1 2 2004 2006 3 2 4
1 3 2004 2007 3 3 4
1 4 2001 2004 2 1 2
1 5 2001 2007 2 3 2
1 7 2000 2007 1 3 1
2 8 ... ... ... ...
2 9 ... ... ... ...
The variable that I want to calculate in stata is "Active_deals". This variable is the sum of the number of deal entries (Entryy_count) in one investment year + the number of deal exits (Exity_count) that were made in this investment year.

For Deal #1 - #3 the "Active_Deals" Variable should be "4" because these deals are made in 2004 and in addition, one firm is sold (Deal #4) in 2004 by Company # 1. Consequently, 4 deals are active in the investment year 2004 for Company #1.

I tried several commands (e.g. egen and by) but I did not find the right way to calculate the active_deals variable.

I am happy for suggestions.

Regards,
Sebastian