PING  0.9
Statistical data handling and processing in production environment
gini

Compute the Gini index of a set of observations.

%gini(dsn, var, weight=, _gini_=, method=, issorted=no, lib=WORK);

Arguments

  • dsn : a dataset reference with continuous observations;
  • var : variable of the input dataset dsn on which the Gini index will be computed;
  • weight : (option) weight (frequencies), either a variable in dsn to use to weight the values of var, or a constant value; default: weight=1, i.e. it is not used;
  • method : (option) method used to compute the Gini index; it can be: LAEKEN, or CANONICAL; default: LAEKEN, i.e. the formula used for computing the Gini index (which is 100* Gini coefficient) as:
    gini = 100 * (( 2 * swtvarcw - swt2var ) / ( swt * swtvar ) - 1)
    
  • issorted : (option) boolean flag (yes/no) set when the input data is already sorted; default: issorted=no, and the input will be sorted;
  • lib : (option) name of the input library; by default: empty, i.e. WORK is used.

Returns

_gini_ : name of the macro variable storing the value of the Gini index.

Examples

Considering the following datasets gini10_1:

Obsx
A 2
A 2
A 2
B 3
B 3

and gini10_2;

Obsx w
A 2 3
B 3 2

both calls to the macro:

%let gini=;
%gini(gini10_1, x, _gini_=gini);
%gini(gini10_2, x, weight=w, _gini_=gini);

actually return the Gini index: gini=10.

Run macro %_example_gini for examples.

Note

The default LAEKEN method implements the approach of Alfons & Templ. In short, this means that the macro %gini runs the following DATA step over already sorted data:

DATA _null_;
SET &lib..&dsn end=__last;
retain swt swtvar swt2var swtvarcw ss 0;
xwgh = &weight * &x;
ss + 1;
swt + &weight;
swtvar + xwgh;
swt2var + &weight * xwgh;
swtvarcw + swt * xwgh;
if __last then
do;
gini = 100 * (( 2 * swtvarcw - swt2var ) / ( swt * swtvar ) - 1);
call symput("&_gini_",gini);
end;
run;

References

  1. Gastwirth, J. L. (1972). "The estimation of the Lorenz curve and Gini index", The Review of Economics and Statistics, 306-316.
  2. Templ, M. and Alfons, A. (2011): "Variance Estimation of Indicators on Social Exclusion and Poverty using the R Package laeken".
  3. Yitzhaki, S. and Schechtman, E. (2012): "More than a dozen alternative ways of spelling Gini".
  4. Alfons, A. and Templ, M. (2014): "Estimation of social exclusion indicators from complex surveys: The R package laeken".
  5. Creedy, J. (2015): "A note on computing the Gini inequality measure with weighted data".
  6. Web link on Gini Coefficient of inequality.

See also

%income_components_gini.