BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
righcoastmike
Quartz | Level 8

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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:

Lorenz_curve.png

 

View solution in original post

4 REPLIES 4
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
righcoastmike
Quartz | Level 8
Thanks so much for this mkeitz, I'll take a closer look at this and hopefully get a better sense of how things need to get set up.

Rightcoast.
FreelanceReinh
Jade | Level 19

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:

Lorenz_curve.png

 

righcoastmike
Quartz | Level 8

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 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3259 views
  • 0 likes
  • 3 in conversation