Dear all,
I am trying calculate the number of alliances that a given firm formed with other partners five years before forming the focal alliance. My dataset has the variables firm_1, firm_2, and alliance_year. Importantly, the counter should ignore alliances that were formed in the same year with other partners as well as past alliances that were formed with the same partner as in the focal alliance. Here is an example of the dataset and the variable count_firm_1 (same for firm_2) that I would like to create:
Example:
I have tried various solutions that were posted on related topics but none of those seemed to work for me. Any help would be appreciated.
Best,
Marvin
I am trying calculate the number of alliances that a given firm formed with other partners five years before forming the focal alliance. My dataset has the variables firm_1, firm_2, and alliance_year. Importantly, the counter should ignore alliances that were formed in the same year with other partners as well as past alliances that were formed with the same partner as in the focal alliance. Here is an example of the dataset and the variable count_firm_1 (same for firm_2) that I would like to create:
Example:
id | firm_1 | firm_2 | alliance_year | count_firm_1 | explanation |
1 | a | b | 2007 | 0 | none before 2007 |
2 | a | c | 2007 | 0 | none before 2007 |
3 | a | d | 2008 | 2 | prior alliances with b and c |
4 | a | d | 2011 | 2 | prior alliances with b and c (alliance with the same partner d is ignored) |
5 | a | e | 2014 | 1 | only alliance with d in 2011 is counted - all other alliances date back more than five years |
6 | x | b | 2011 | 0 | none before 2011 |
7 | x | c | 2012 | 1 | prior alliance b |
8 | x | d | 2013 | 2 | prior alliances with b and c |
9 | x | e | 2013 | 2 | prior alliances with b and c (alliance in the same year with d is ignored) |
10 | x | e | 2013 | 2 | prior alliances with b and c (alliances in the same year / with the same are ignored) |
11 | x | f | 2014 | 3 | prior alliances with b, c and e (alliance with e in the same year is counted only once; alliance with e would be counted twice if the alliances between x and e were in different years) |
12 | x | d | 2015 | 4 | prior alliances with b, c, e, and f |
I have tried various solutions that were posted on related topics but none of those seemed to work for me. Any help would be appreciated.
Best,
Marvin
Comment