/* Calculate Gini coefficient from a data set Philip Dixon, Mar 1992 */ /* read the data */ /* details will need to change for other data formats */ /* the data step that does the calculation assumes that */ /* the variable of interest is called X */ data ginix; retain npt 0; input x @@; /* read a data value, possibly more than one */ iboot = 1; /* on a line */ npt = npt + 1; /* update the number of data values */ call symput("npt", npt); /* store a macro variable with the number of points */ cards; 20 23 18 25 28 18 ; /* Calculate Gini coefficient for the original data */ proc sort data=ginix; /* sort each bootstrap sample so that the */ by x; /* values are in increasing order. This */ /* is required by the Dixon et al algorithm */ /* to calculate the Gini coeff. */ /* (Ecology 1987) */ data gini; set ginix end = last; retain ginisum 0 /* Accumulates (2i-n-1)*X */ sum 0 /* Accumulates X, so we can calculate mean */ ipt 0; /* index of data value, 1 for smallest, /* npt for largest value. */ npt = symget('npt'); /* number of points in the data set*/ ipt = ipt + 1; /* Then add 1 to the number of data points */ sum = sum + x; /* Add the value to the sum */ ginisum = ginisum + (2*ipt - (npt + 1))*x; /* and add (2i-n-1)X to its sum */ if last then do; /* if this was the last observation */ gini = ginisum /((npt-1)*sum); /* calculate Gini coeff. for sample */ mean = sum/npt; output; /* store on boots data set */ end; keep npt gini mean; proc print; title 'Gini coefficient';