Dear Statalist,

I'm trying to calculate the Gini of counties using the the population of 20+ income groups and the median income of said groups. An extract of the data I'm working on is as follows:

Code:
 
 * Example generated by -dataex-. To install: ssc install dataex clear input float countyid int(year pop_1_19 pop_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
I've tried to find a sollution as to calculate the Gini with the data being shaped the way it is, but being the Stata novice I am I haven't had any luck. However, I believe that I could be able to use the
ginidesc command if I reshape my data the following way:
Code:
 countyid year group population median  1 2015 1  xxx  xxx  1 2015 2  xxx  xxx  1 2015 3  xxx  xxx  1 2015 4  xxx  xxx  1 2015 5  xxx  xxx  1 2015 6  xxx  xxx  1 2015 7  xxx  xxx  1 2015 8  xxx  xxx  1 2015 9  xxx  xxx  1 2015 10  xxx  xxx  1 2015 11  xxx  xxx  1 2015 12  xxx  xxx  1 2015 13  xxx  xxx  1 2015 14  xxx  xxx  1 2015 15  xxx  xxx  1 2015 16  xxx  xxx  1 2015 17  xxx  xxx  1 2015 18  xxx  xxx  1 2015 19  xxx  xxx  1 2015 20  xxx  xxx  1 2015 21  xxx  xxx  1 2015 22  xxx  xxx  1 2015 23  xxx  xxx  1 2015 24  xxx  xxx  1 2015 25  xxx  xxx
I.e. if I could reshape my data so that group (income group) becomes a variable 1 if income group is income group 1-19 (pop_1_19 in my original data), 2 if income group is income group 20-39 (pop_20_39 in my original data)etc... population is the value of the variable of pop_xx_xx in my original data for it's corresponding group and median is the median vage of corresponding income group. Any ideas on how I could proceed with the reshaping? Or if there is any way to calculate the gini of each county for each year using the shape of my current data? Thanks in advance.