Dear all,

I am trying to sum the profitability of a given target firm for the period year-1 to year+2, where year=0 is the year of the date on which a merger or an acquisition was announced.

I have the profitability data for the years 1993 to 2019 for each firm and I then matched this sample with the information regarding M&A transactions (_merge==3 for matched obs).

I have something like this now:

Year. ID. Profitability _merge
1993 ABC 123456. 1
1994 ABC 2536848 1
1995 ABC 273474. 1
1996 ABC 3883747. 1
1997 ABC 8474758. 3
1998 ABC 28474. 1
1999 ABC 9458. 1
2000 ABC 204955. 1
2001 ABC 39485. 1
2002 ABC 545959. 1
1994 XYZ 8237985. 1
1995 XYZ 14955. 1
1996 XYZ 33333 1
1997 XYZ 44444 1
1998 XYZ 593456 1
1999 XYZ 34975916. 3
2000 XYZ 34986 1
2001 XYZ 136316 1
2002 XYZ 65246 1
2003 XYZ 3457467 1
2004 XYZ 27576 1
2005 XYZ 67354. 1
...

I would like to, for example, get the sum of Profitability from 1996 up to 1999 for ABC and from 1998 up to 2001 for XYZ.

I tried the following code but didn't work:

Code:
gen year_dateann = year(DateAnnounced)
gen year_minusone = year_dateann - 1
gen year_plustwo = year_dateann + 2 
gen profitability_minusone = Profitability if year==year_minusone
gen profitability_plustwo = Profitability if year==year_plustwo
gen profitability_zero = Profitability if year==year_dateann
gen profitability_threeyears = profitability_zero + profitability_plustwo + profitability_minusone
or also

Code:
gen profitability_threeyears = total(Profitability) if year==year_minusone | year==year_plustwo | year==year_dateann
Do you have any tips/recommendations?

Thank you in advance!