Hi,

I have data containing the population of certain income groups and the median income of those income groups in some municipalities for 5 years, I also have the population of the municipalities. I'm looking for a way to calculate the gini of these municipalities. Below is an extract of my data. Any ideas on how I could proceed?

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float kommunid int(year antal_1_19 antal_20_39) double(median_1_19 median_20_39)
 1 2015 1004  349  5.8 29.2
 1 2016  926  380  5.9   30
 1 2017  881  382  5.9 29.2
 1 2018  931  381  6.1 29.3
 1 2019  933  400  6.5 29.1
 2 2015 1068  508  5.4 29.9
 2 2016 1031  517  5.4 30.3
 2 2017  959  489  6.5 29.1
 2 2018  890  557  6.7 29.3
 2 2019  860  490  7.1 29.7
 3 2015  626  305  6.7 29.2
 3 2016  586  292  6.9 29.5
 3 2017  534  293  6.6 29.5
 3 2018  638  294  7.1 29.8
 3 2019  627  289  6.8 29.1
 4 2015  143   95  8.2 28.4
 4 2016  160   92  8.4 28.7
 4 2017  123   88  8.3   27
 4 2018  125   85  7.4 27.8
 4 2019  134   97    7 30.2
 5 2015  408  228  7.2 29.2
 5 2016  388  229  6.5 29.9
 5 2017  402  219    7 30.8
 5 2018  411  209  7.8 28.6
 5 2019  387  229  7.5 29.4
 6 2015   78   37  7.1 26.7
 6 2016   47   41  9.3 31.4
 6 2017   55   29    8 30.3
 6 2018   60   36  7.5 29.7
 6 2019   63   30  8.2 32.2
 7 2015  179   87  5.8 28.3
 7 2016  159   77  5.6 31.1
 7 2017  157   66  5.4 28.9
 7 2018  149   71  7.6 29.7
 7 2019  139   64  7.9 28.2
 8 2015  702  413  7.5 28.9
 8 2016  641  422  7.6 29.8
 8 2017  588  383    8 29.5
 8 2018  591  415  7.6 28.8
 8 2019  570  393  7.4 30.3
 9 2015  251  139  6.8 30.2
 9 2016  248  116  7.3 28.3
 9 2017  233  132    8 30.4
 9 2018  220  140  7.8 29.2
 9 2019  208  149  7.9 29.3
10 2015  533  326  9.1 29.2
10 2016  570  336  9.3   30
10 2017  631  325  9.1 28.5
10 2018  631  325  9.4 27.8
10 2019  551  306  9.6 29.7