***
*** Example 3.2. Inequality measures for Côte d'Ivoire (Table 3.2)
***
*** The code calculates each of the inequality measures in Table 3.2,
*** with and without weights.
***
*** Note: The following provides the STATA code used to produce
*** results used in "The Analysis of Household Surveys:
*** A Microeconometric Approach to Development Policy", by Angus Deaton.
*** This book, published for the World Bank by The Johns Hopkins University
*** Press and scheduled for release in 1997.
***
version 4.0
#delimit ;
drop _all;
cap log close;
log using table32, replace;
/* defining program to calculate gini without weights */
cap program drop giniu;
program def giniu;
local yr=1985;
while `yr' <= 1988 {;
drop _all;
use cdi85_88;
keep if year==`yr';
gsort - pce;
gen hrnk=sum(hhs);
gen hhrnk=hrnk[_n-1]+1;
replace hhrnk=1 in 1;
qui summ hhs;
local bign=_result(1)*_result(3);
qui summ pce [aweight=hhs];
local mn=_result(3);
gen rnkx=pce*(hhrnk+0.5*(hhs-1));
qui summ rnkx [aweight=hhs];
local g=(`bign'+1)-(2/`mn')*_result(3);
local g=`g'/(`bign'-1);
dis("Gini coefficient `yr' =`g'");
local yr=`yr'+1;
};
end;
/* defining program to calculate gini with weights */
cap program drop giniw;
program def giniw;
local yr=1985;
while `yr' <= 1988 {;
drop _all;
use cdi85_88;
keep if year==`yr';
gsort - pce;
replace hhs=hhs*allwaitn;
gen hrnk=sum(hhs);
gen hhrnk=hrnk[_n-1]+1;
replace hhrnk=1 in 1;
qui summ hhs;
local bign=_result(1)*_result(3);
qui summ pce [aweight=hhs];
local mn=_result(3);
gen rnkx=pce*(hhrnk+0.5*(hhs-1));
qui summ rnkx [aweight=hhs];
local g=(`bign'+1)-(2/`mn')*_result(3);
local g=`g'/(`bign'-1);
dis("Gini coefficient `yr' =`g'");
local yr=`yr'+1;
};
end;
**Unweighted ginis;
giniu;
**Weighted ginis;
giniw;
/* program for Atkinson measures */
/* argument `1' is the inequality aversion */
cap program drop aba;
program def aba;
local yr=1985;
while `yr' <= 1988 {;
drop _all;
use cdi85_88;
keep if year==`yr';
replace hhs=hhs*allwaitn;
qui summ pce [aweight=hhs];
local mn=_result(3);
gen pcerat=pce/`mn';
if `1' ==1 {;
gen tm=ln(pce/`mn');
qui summ tm [aweight=hhs];
local ineq=1-exp(_result(3));};
else {;
gen tm=(pce/`mn')^`1';
qui summ tm [aweight=hhs];
local ineq=1-(_result(3))^(1/(1-`1'));};
dis("`yr' Atkinson coefficient, eps=`1' =`ineq'");
local yr=`yr'+1;
};
end;
aba 0.5;
aba 1;
aba 2;
/* program for standard deviation of logs */
cap program drop sdlogs;
program define sdlogs;
local yr=1985;
while `yr' <= 1988 {;
drop _all;
use cdi85_88;
keep if year==`yr';
replace hhs=hhs*allwaitn;
gen lnpce=ln(pce);
qui summ lnpce [aweight=hhs];
local sdln=sqrt(_result(4));
dis("`yr' s.d. of lnpce, = `sdln'");
local yr=`yr'+1;
};
end;
sdlogs;
/* program for coefficient of variation */
cap program drop coefvar;
program define coefvar;
local yr=1985;
while `yr' <= 1988 {;
drop _all;
use cdi85_88;
keep if year==`yr';
replace hhs=hhs*allwaitn;
qui summ pce [aweight=hhs];
local cv=sqrt(_result(4))/_result(3);
dis("`yr' c.o.v. of pce, = `cv'");
local yr=`yr'+1;
};
end;
coefvar;
log close;
[Return to Program List]