options crt ; supres smpl ; name gini "Example of Computing Gini Coefficients" ; ? ? TSP 4.2A (Sept 1992) ? Author: Clint Cummins ? set n = 400; smpl 1,n; title 'Uniform Distribution' ; random(uniform) u; cgini u n gini; print gini ; title 'Normal(5,1) Distribution' ; random(mean=5) n5; cgini n5 n gini; print gini ; title 'Normal(5,.1) Distribution' ; random(mean=5,stdev=.1) n5; cgini n5 n gini; print gini ; title 'Normal(5,.01) Distribution' ; random(mean=5,stdev=.01) n5; cgini n5 n gini; print gini ; ? proc cgini y n gini; ? ? Proc to Compute Gini Coefficient. ? y is series and n is its length. ? gini is returned. ? smpl 1,n; msd (noprint) y; sort y; trend t; cumey = @mean*t; ? cumulative income if distributed equally set tarea = @mean*n*(n+1)/2; ? total area under equal distribution cumy = y; smpl 2,n; cumy = y + cumy(-1); ? cumulative actual income smpl 1,n; cumdiff = cumey-cumy; msd(noprint) cumdiff; set gini = @sum/tarea; endproc cgini ; stop ; end ;