Here is a part of the sample. (I randomly chose the numbers)
state | year | returns | income |
AL | 2017 | 53 | 1000 |
AL | 2018 | 45 | 1100 |
AL | 2019 | 63 | 1200 |
AK | 2018 | 21 | 500 |
AK | 2019 | 13 | 510 |
AZ | 2016 | 57 | 700 |
AZ | 2017 | 76 | 710 |
AZ | 2018 | 79 | 720 |
AZ | 2019 | 59 | 730 |
I have a formula for a weighed mean income for states: Sum of (each year' returns / total returns) * income
For Alabama, 53 / (53+45+63) *1000 + 45 / (53+45+63) *1100 + 63 / (53+45+63) *1200 = 1106.21
I want to create this below data set:
state | year | returns | income | WMincome |
AL | 2017 | 53 | 1000 | 1106.21 |
AL | 2018 | 45 | 1100 | 1106.21 |
AL | 2019 | 63 | 1200 | 1106.21 |
AK | 2018 | 21 | 500 | 503.82 |
AK | 2019 | 13 | 510 | 503.82 |
AZ | 2016 | 57 | 700 | 715.17 |
AZ | 2017 | 76 | 710 | 715.17 |
AZ | 2018 | 79 | 720 | 715.17 |
AZ | 2019 | 59 | 730 | 715.17 |
My final data set looks like this:
state | WMincome |
AL | 1106.21 |
AK | 503.82 |
AZ | 715.17 |
Thanks!
0 Response to How to calculate weighted mean income
Post a Comment