Hello

I have a panel data with firm and year variables. I also have a dummy variable, litigation, which equals 1 if there are 1 or more litigations for a firm in a year and 0 if there is no litigation for the firm in that year. I want to create a new dummy variable, abovemedian_litigation, which equals 1 if the firm has 50% or more of the times with litigation==1 than litigation==0 over the sample period. How can I do this? Thanks a lot for any suggestions!
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float year double firm float litigation
2010  2 1
2011  2 1
2012  2 1
2013  2 1
2014  2 0
2015  2 0
2016  2 1
2017  2 1
2018  2 1
2019  2 1
2010  4 0
2011  4 0
2012  4 1
2013  4 1
2014  4 1
2015  4 0
2016  4 1
2017  4 0
2018  4 1
2019  4 1
2010  5 1
2011  5 1
2012  5 1
2013  5 1
2014  5 1
2015  5 0
2016  5 1
2017  5 1
2018  5 1
2019  5 1
2011  7 0
2012  7 0
2013  7 1
2014  7 0
2015  7 1
2016  7 0
2017  7 0
2018  7 0
2019  7 1