You are on page 1of 4

OPTION macrogen;

libname distrib 'F:\distrib';

/******** macro utiles *******************/


%macro transp (in=,nvar=,var=,varnouv=,intitule=,mod=,out=);
%do i=1 %to &nvar;
%let x=%scan(&var,&i);
%let y=%scan(&mod,&i);
data xx&i;
set ∈
&varnouv='MMMMMMMMMMMMMMMMM';
&intitule='MMMMMMMMMMMMMMM';
&varnouv=&x;
&intitule="&y";
drop &var;
run;
%end;

data &out;
set %do i=1 %to &nvar;
%let x=%scan(&var,&i);
xx&i %end; ;
run;
%mend;
%macro REDUCT (in=, strates=,out=,mean=,pond=);
proc means data=&in mean nway noprint;
var &mean;
class &strates;
weight &pond;
output out=xx1 mean=;
run;
proc means data=&in sum nway noprint;
var &pond;
class &strates ;
output out=xx2 sum=;
run;
data &out;
merge xx1 xx2;
by &strates;
drop _type_ _freq_;
run;
%mend;
%macro GINI (in=,id=,vargroup=,ngroup=,listmod=,var=);
proc sort data=&in out=z1;
by &var &id ;
run;

/* on renomme les groupes */


data z1;
set z1;
groupj='MMMMMMMM';
%do i=1 %to &ngroup;
%let x=%scan(&listmod,&i);
if &vargroup="&x" then groupj="&i";
%end;
revenuj=&var;ident=&id;
run;

/* premier passage : on calcule des quantites agregees par salarie : SM&i


somme des salaires du groupe i inferieurs au salaire de l'individu, etc */
data z2;
set z1 (keep=groupj revenuj ident);
by revenuj ident;
if first.ident;
%do i=1 %to &ngroup;
retain SM&i 0;
retain Nm&i 0;
%end;
%do i=1 %to &ngroup;
if groupj="&i" then do;
SM&i=SM&i+revenuj;
nm&i =nm&i+1;
end; %end;
run;
proc sort data=z2 out=z3;
by descending revenuj descending ident;
run;
data z4;
set z3;
by descending revenuj descending ident;
%do i=1 %to &ngroup;
retain SP&i 0;
retain Np&i 0;
%end;
%do i=1 %to &ngroup;
if groupj="&i" then do;
Sp&i=Sp&i+revenuj;
np&i =np&i+1;
end;
%end;

/*verif */
%do i=1 %to &ngroup;
%let x=%scan(&listmod,&i);
TOTS&i=SP&i+SM&i;
TOTN&i=NP&i+NM&i;
if groupj="&i" then do;
tots&i=tots&i-revenuj;
totn&i=totn&i-1;
end;
%end;
run;
data z5;
set z4;
%do i=1 %to &ngroup;
delta&i=(NM&i-NP&i)*revenuj+SP&i-SM&i;
d&i=(NM&i)*revenuj-SM&i;
%end;
effj=1;
run;

/* deuxieme passage : on somme */


proc means data=z5 sum nway noprint;
var delta1-delta&ngroup d1-d&ngroup effj revenuj ;
class groupj;
output out=z6 sum=;
run;
data effec;
set z6 (keep=groupj effj revenuj);
rename groupj=grouph effj=effh revenuj=revenuh;
run;
proc means data=effec sum nway noprint;
var effh revenuh;
output out=total sum=efftot revtot;
run;
data total;
set total (keep=efftot revtot);
bidon=0;run;
%transp (in=z6, nvar=&ngroup, var=%do i=1 %to &ngroup;
delta&i %end;
, varnouv=DELTA, intitule=grouph, mod=%do i=1 %to &ngroup;
&i %end;
,out=delta);
%transp (in=z6, nvar=&ngroup, var=%do i=1 %to &ngroup;
d&i %end;
, varnouv=D, intitule=grouph, mod=%do i=1 %to &ngroup;
&i %end;,out=d);
proc sort data=delta out=z8;
by grouph;
run;
proc sort data=effec out=z9;
by grouph;run;
data delta;merge z8 z9;
by grouph;
deltajh=delta/effj/effh;
Gjh=deltajh/(revenuh/effh+revenuj/effj);
drop _type_ _freq_;
run;
proc sort data=delta out=z8;
by groupj grouph ;
run;
proc sort data=d out=z9;
by groupj grouph ;
run;
data delta;
merge z8 z9;
by groupj grouph;
djh=d/effj/effh;
run;
data z7;
set delta (keep= groupj grouph djh);
c=groupj;
groupj=grouph;
grouph=c;
pjh=djh;
drop c djh;
run;
proc sort data=z7 out=z8;
by groupj grouph ;
run;
proc sort data=delta out=z9;
by groupj grouph ;
run;
data delta;
merge z8 z9;
by groupj grouph;
DDjh=(djh-pjh)/(djh+pjh);
DD2jh= (djh-pjh)/(deltajh);
run;
data z8;
set delta;
bidon=0;
run;
data delta;
merge z8 total;
by bidon;
pj=effj/efftot;
ph=effh/efftot;
sj=revenuj/revtot;
sh=revenuh/revtot;
muj=revenuj/effj;
muh=revenuh/effh;
&vargroup.j='MMMMMMMM';
&vargroup.h='MMMMMMMM';
%do i=1 %to &ngroup;
%let x=%scan(&listmod,&i);
if groupj="&i" then &vargroup.j="&x" ;
if grouph="&i" then &vargroup.h="&x" ;
%end;
keep groupj grouph pj ph sj sh muj muh djh ddjh gjh &vargroup.j
&vargroup.h;run; data z8; set delta; indjh=(muj>muh);
indjj=(groupj=grouph);
Gw=indjj*gjh*pj*sh;
Gb=indjh*gjh*ddjh*(pj*sh+ph*sj);
Gt=indjh*gjh*(1-ddjh)*(pj*sh+ph*sj);
keep groupj grouph gw gb gt;
run;
proc means data=z8 sum nway noprint; var gw gb gt;
output out=res sum=;
run;
%mend GINI;
/* premier essai */ /* %GINI
(in=travail.mussard,id=id,vargroup=cs,ngroup=3,listmod=Profint Cadre
Ouv_Emp,var=sn); */