File Exchange

## Inequality Package

version 1.3 (7.76 KB) by

Inequality Metrics: Gini Coefficient associated to the Lorenz Curve, Theil and Atkinson indexes

Updated

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)

B

### B (view profile)

Got it thanks for the clarification, I didn't realize yours used the total size of the population.

Liber Eleutherios

### 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 PER-CAPITA 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

### 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/28080-gini-coefficient-and-the-lorentz-curve) 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

### 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

### 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

### 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

### martin (view profile)

very good, Thank you!

 12 Jan 2015 1.3 minor edits 18 Sep 2012 1.2 All functions have been entirely re-written. 8 Feb 2009 1.1 I have made two major corrections to the functions GiniCoeff and plotLorenzCurve
MATLAB 7 (R14)
##### Acknowledgements

Inspired by: Gini coefficient - population weighted

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

Play today