Hi all,

I am trying to accomplish a simple count, but I still am not able to get what I want after searching the forums and trying different commands.

I have the following dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str12 ISIN float Year str12 MergerISIN int MergerYear float dummy
"ANN2879J1070" 2010 ""                . 0
"ANN2879J1070" 2011 ""                . 0
"ANN4327C1220" 2002 ""                . 0
"ANN4327C1220" 2003 ""                . 0
"ANN4327C1220" 2004 ""                . 0
"ANN4327C1220" 2005 ""                . 0
"ANN4327C1220" 2006 ""                . 0
"ANN4327C1220" 2007 ""                . 0
"ANN4327C1220" 2008 ""                . 0
"ANN4327C1220" 2009 ""                . 0
"ANN4327C1220" 2010 ""                . 0
"ANN4327C1220" 2011 ""                . 0
"ANN4327C1220" 2012 ""                . 0
"ANN4327C1220" 2013 ""                . 0
"ANN4327C1220" 2014 ""                . 0
"ANN4327C1220" 2015 ""                . 0
"ANN4327C1220" 2016 ""                . 0
"ANN4327C1220" 2017 ""                . 0
"ANN4327C1220" 2018 ""                . 0
"ANN4327C1220" 2019 ""                . 0
"AT000000STR1" 2007 "AT000000STR1" 2007 1
"AT000000STR1" 2007 "AT000000STR1" 2007 1
"AT000000STR1" 2007 "AT000000STR1" 2007 1
"AT000000STR1" 2007 "AT000000STR1" 2007 1
"AT000000STR1" 2008 "AT000000STR1" 2008 1
"AT000000STR1" 2008 "AT000000STR1" 2008 1
"AT000000STR1" 2008 "AT000000STR1" 2008 1
"AT000000STR1" 2008 "AT000000STR1" 2008 1
"AT000000STR1" 2008 "AT000000STR1" 2008 1
"AT000000STR1" 2009 "AT000000STR1" 2009 1
"AT000000STR1" 2010 "AT000000STR1" 2010 1
"AT000000STR1" 2010 "AT000000STR1" 2010 1
"AT000000STR1" 2011 "AT000000STR1" 2011 1
"AT000000STR1" 2011 "AT000000STR1" 2011 1
"AT000000STR1" 2012 ""                . 0
"AT000000STR1" 2013 ""                . 0
"AT000000STR1" 2014 "AT000000STR1" 2014 1
"AT000000STR1" 2015 ""                . 0
"AT000000STR1" 2016 "AT000000STR1" 2016 1
"AT000000STR1" 2016 "AT000000STR1" 2016 1
"AT000000STR1" 2017 ""                . 0
"AT000000STR1" 2018 ""                . 0
"AT000000STR1" 2019 ""                . 0
"AT00000AMAG3" 2011 ""                . 0
"AT00000AMAG3" 2012 ""                . 0
"AT00000AMAG3" 2013 ""                . 0
"AT00000AMAG3" 2014 ""                . 0
"AT00000AMAG3" 2015 ""                . 0
"AT00000AMAG3" 2016 ""                . 0
"AT00000AMAG3" 2017 ""                . 0
"AT00000AMAG3" 2018 ""                . 0
"AT00000AMAG3" 2019 ""                . 0
"AT00000ATEC9" 2007 ""                . 0
"AT00000ATEC9" 2008 ""                . 0
"AT00000ATEC9" 2009 ""                . 0
"AT00000ATEC9" 2010 ""                . 0
"AT00000ATEC9" 2011 ""                . 0
"AT00000FACC2" 2017 ""                . 0
"AT00000FACC2" 2018 ""                . 0
"AT00000OESD0" 2018 ""                . 0
"AT00000OESD0" 2019 ""                . 0
"AT00000VIE62" 2007 ""                . 0
"AT00000VIE62" 2008 ""                . 0
"AT00000VIE62" 2009 ""                . 0
"AT00000VIE62" 2010 ""                . 0
"AT00000VIE62" 2011 ""                . 0
"AT00000VIE62" 2012 ""                . 0
"AT00000VIE62" 2013 ""                . 0
"AT00000VIE62" 2014 ""                . 0
"AT00000VIE62" 2015 ""                . 0
"AT00000VIE62" 2016 ""                . 0
"AT00000VIE62" 2017 ""                . 0
"AT00000VIE62" 2018 ""                . 0
"AT00000VIE62" 2019 ""                . 0
"AT0000609607" 2007 ""                . 0
"AT0000609607" 2008 ""                . 0
"AT0000609607" 2009 ""                . 0
"AT0000609607" 2010 ""                . 0
"AT0000609607" 2011 ""                . 0
"AT0000609607" 2012 ""                . 0
"AT0000609607" 2013 "AT0000609607" 2013 1
"AT0000609607" 2013 "AT0000609607" 2013 1
"AT0000609607" 2014 "AT0000609607" 2014 1
"AT0000609607" 2015 ""                . 0
"AT0000609607" 2016 ""                . 0
"AT0000609607" 2017 ""                . 0
"AT0000609607" 2018 "AT0000609607" 2018 1
"AT0000609607" 2018 "AT0000609607" 2018 1
"AT0000609607" 2019 "AT0000609607" 2019 1
"AT0000612601" 2007 ""                . 0
"AT0000612601" 2008 ""                . 0
"AT0000612601" 2009 ""                . 0
"AT0000612601" 2010 ""                . 0
"AT0000612601" 2011 ""                . 0
"AT0000612601" 2012 ""                . 0
"AT0000620158" 2007 ""                . 0
"AT0000620158" 2008 ""                . 0
"AT0000644505" 2007 ""                . 0
"AT0000644505" 2008 ""                . 0
"AT0000644505" 2009 ""                . 0
end
As can be seen, I have merged a financial database and an M&A database by ISIN and Year. When a merger is found for a specific ISIN and Year, I assign dummy code the observation with 1. This means that in my final dataset (after merging), a firm can have 0 mergers over the sample period, 1 merger, or multiple mergers in one year. Although my dummy does capture this, I want a variable that shows how many mergers a firm has done in an ISIN and Year. In the data example above, we see that AT000000STR1 has done 4 mergers in the year 2007. I want a variable that reports 4 for all of the ISIN-Years.

I am assuming this can be done with a bysort ISIN Year command, but I have no idea how, even after consulting the forum and documentation. Can someone steer me in the right directon?

Thank you