Hi All,
I've been tasked with creating a Concentration curve based on some socioeconomic data and health data, but it's proving to be quite tricky to even find documentation on how to set things up. I've managed to find this paper about how to do it in STATA (http://repec.sowi.unibe.ch/files/wp15/jann-2016-lorenz.pdf) , but nothing for SAS. Normally I would include a sample dataset, but to be honest I can't even figure out how the data needs to be laid out. I am pretty sure it can be done, but I am at a loss as to where to begin.
Any help would be much appreciated.
Thanks so much
Mike
Hi @righcoastmike,
Please find below a program I wrote at home about one hour ago. 🙂
data have;
input population income;
cards;
24113 29393
6554 33011
19225 52976
19909 59591
22448 64511
24536 67992
;
data want;
output;
do until(eof1);
set have end=eof1;
total_pop+population;
total_inc+population*income;
end;
do until(eof2);
set have end=eof2;
share_inc=population*income/total_inc;
cum_pop+population/total_pop;
cum_inc+share_inc;
g+(cum_pop+max(lag(cum_pop),0))*share_inc;
output;
end;
gini=g-1;
call symput('gini', put(gini, 5.3)); /* change format 5.3 to 11.9 for comparison */
format cum: percent9.2;
label cum_pop='Cumulative shares of population'
cum_inc='Cumulative shares of income';
keep cum:;
stop;
run;
proc sgplot data=want;
title 'Lorenz curve';
series x=cum_pop y=cum_inc / legendlabel='Lorenz curve';
series x=cum_inc y=cum_inc / legendlabel='Perfect equality line';
xaxis offsetmin=0 offsetmax=0;
yaxis offsetmin=0 offsetmax=0;
inset "Gini coeff.: &gini" / border position=left textattrs=(Size=12);
refline 0.2 to 1 by 0.2;
run;
It replicates the results of the "complete handout" (section "2. Age inequalities", Table 3, Graph 3) linked in section "External links" of the Wikipedia article "Lorenz curve".
Graph:
This link https://groups.google.com/forum/#!topic/comp.soft-sys.sas/UaXlg153QpM is a Pace University revision of a program I wrote at Univ of Penn about 25 years ago.
Hi @righcoastmike,
Please find below a program I wrote at home about one hour ago. 🙂
data have;
input population income;
cards;
24113 29393
6554 33011
19225 52976
19909 59591
22448 64511
24536 67992
;
data want;
output;
do until(eof1);
set have end=eof1;
total_pop+population;
total_inc+population*income;
end;
do until(eof2);
set have end=eof2;
share_inc=population*income/total_inc;
cum_pop+population/total_pop;
cum_inc+share_inc;
g+(cum_pop+max(lag(cum_pop),0))*share_inc;
output;
end;
gini=g-1;
call symput('gini', put(gini, 5.3)); /* change format 5.3 to 11.9 for comparison */
format cum: percent9.2;
label cum_pop='Cumulative shares of population'
cum_inc='Cumulative shares of income';
keep cum:;
stop;
run;
proc sgplot data=want;
title 'Lorenz curve';
series x=cum_pop y=cum_inc / legendlabel='Lorenz curve';
series x=cum_inc y=cum_inc / legendlabel='Perfect equality line';
xaxis offsetmin=0 offsetmax=0;
yaxis offsetmin=0 offsetmax=0;
inset "Gini coeff.: &gini" / border position=left textattrs=(Size=12);
refline 0.2 to 1 by 0.2;
run;
It replicates the results of the "complete handout" (section "2. Age inequalities", Table 3, Graph 3) linked in section "External links" of the Wikipedia article "Lorenz curve".
Graph:
Thanks so much Freelance!
This is a huge help. It will take me a little bit to go through and figure out what you did, but that will be a good exercise all on its own. It's becoming clear to me that the "DO loop" is something I'm going to have to get more comfortable with.
Thanks again.
Mike
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.