Imagine that you have the following dataframe: Now, what we want to compute is the INDUSTRY average historical ROE, and place this number in a new column.
Date ROE id
30-06-2013 2% 1
30-06-2013 1% 2
30-09-2013 5% 1
30-09-2013 6% 2
30-09-2013 4% 3
31-12-2013 10% 1
31-12-2013 5% 2
31-12-2013 3% 3
31-03-2014 11% 1
31-03-2014 6% 2
31-03-2014 4% 3
When computing the historical ROE we want to rely on a minimum of 4 different dates. The resulting dataframe should look the following:
Date ROE id Hist. avg. ROE
30-06-2013 2% 1 NaN
30-06-2013 1% 2 NaN
30-09-2013 5% 1 NaN
30-09-2013 6% 2 NaN
30-09-2013 4% 3 NaN
31-12-2013 10% 1 NaN
31-12-2013 5% 2 NaN
31-12-2013 3% 3 NaN
31-03-2014 11% 1 5.2%
31-03-2014 6% 2 5.2%
31-03-2014 4% 3 5.2%