Package on Inequality Metrics: the Gini Coefficient associated to the Lorenz Curve, the Theil and the Atkinson indexes.
For more references:
http://en.wikipedia.org/wiki/Lorenz_curve
http://en.wikipedia.org/wiki/Gini_coefficient
http://en.wikipedia.org/wiki/Theil_index
http://en.wikipedia.org/wiki/Atkinson_index
***************************
Note that contributions #15376 and #28080 DO NOT return the correct Gini coefficient, while #26452 does not apply to populations but only to individuals.
***************************
The zip file contains:
ginicoeff.m
lorenzcurve.m
theilt.m
theill.m
atkinsonineq.m
***************************
% Example for ginicoeff.m:
N = 1000;
p = rand(N, 1); w = rand(N, 1);
y = ginicoeff(p, w)
% ***************************
% Example for lorenzcurve.m:
N = 1000;
p = rand(N, 1);
w = exp(randn(N, 1));
h = lorenzcurve(p, w);
% ***************************
% Example for theilt.m:
N = 1000;
w = rand(N, 1);
y = theilt(w)
% ***************************
% Example for theill.m:
N = 1000;
w = rand(N, 1);
y = theill(w)
% ***************************
% Example for atkinsonineq.m:
N = 1000;
w = rand(N, 1);
epsilon = rand;
y = atkinsonineq(w, epsilon)
Liber Eleutherios (2020). Inequality Package (https://www.mathworks.com/matlabcentral/fileexchange/19968inequalitypackage), MATLAB Central File Exchange. Retrieved .
1.3.0.0  minor edits 

1.2.0.0  All functions have been entirely rewritten. 

1.1.0.0  I have made two major corrections to the functions GiniCoeff and plotLorenzCurve 

1.0.0.0  Minor corrections (deleted unnecessary semicolons and brackets) 
Inspired by: Gini coefficient  population weighted
Create scripts with code, output, and formatted text in a single executable document.
jingwen wu (view profile)
B (view profile)
Got it thanks for the clarification, I didn't realize yours used the total size of the population.
Liber Eleutherios (view profile)
Hi B, thank you for your question about a point that is often misunderstood. Let us try to clarify this point once and for all.
In my function, FEX 19968, ginicoeff requires two variables: p and w, respectively the size of the population and the TOTAL value associated with that population (for example population and TOTAL GDP).
In the function FEX 28080, gini requires two variables: pop and val, respectively the size of the population and the AVERAGE value associated with that population (for example population and PERCAPITA GDP).
Let
p = (1:100)'; % Population
w = (1:100)'; % Total GDP
g1 = ginicoeff(p, w)
FEX 19968 will return zero because 1 individual has a total value of 1, two individuals have a total value of 2, etc., and 100 individuals have a total value of 100. On average everyone has a value of 1, therefore this is the case of maximum dispersion, i.e. minimum inequality.
FEX 28080 will also return zero, IF you divide w by p:
g2 = gini(p, w ./ p)
I hope this helps.
B (view profile)
I downloaded this package for the lorenze curve plotting. However I was calculating the gini using this function and comparing it to an old calculation I had and to another package on FileExchange (http://www.mathworks.com/matlabcentral/fileexchange/28080ginicoefficientandthelorentzcurve) it seemed to differ. Has anyone else noticed the gini disagreeing with their own calculations? Maybe this gini requires a different format or something, but I didn't seem to notice a difference. The gini from the package was coming out higher than expected. Cheers
Liber Eleutherios (view profile)
@Martin, thank you for your comment but check it again: the Gini coefficient of your example IS NOT zero but some random number.
@Robert, thank you for your comment  I would use random data or the GDP and Population of a selection of countries.
Robert Root (view profile)
Excited to find this package. I'd like to use it in my courses. Where can I find actual data in the format this package accepts?
martin (view profile)
I want ask a question, why I set p=rand(100,1); w=p, and the GiniCoeff(p,w) is not o. Theoratically, the answer should be zero!
martin (view profile)
very good, Thank you!