***
*** Example 3.3. Poverty measures for Côte d'Ivoire (Table 3.3)
***
*** The code calculates the four poverty measures, together with 
*** their bootstrapped standard errors.
*** 
*** 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 table33,replace;
/* setting the poverty line */
global pline=128.6; 
/* program for various poverty measures */
/* this iterates over the four years */
cap program drop peas;
program def peas;
local yr=1985;
while `yr' <= 1988 {;
use cdi85_88;
keep if year==`yr';
gen wt=hhs*allwaitn;
gen pind=pce <= $pline;
qui summ pind [aweight=wt];
local p0=_result(3);
gen df=(1-pce/$pline)*pind;
qui summ df [aweight=wt];
local p1=_result(3);
gen dfa=(1-pce/$pline)^2*pind;
qui summ dfa [aweight=wt];
local p2=_result(3);
drop if pce > $pline;
giniw;
local psen=`p0'*$g+`p1'*(1-$g);
dis("P0=`p0',P1=`p1',P2=`p2',Psen=`psen'");
drop _all;
local yr=`yr'+1;
};
end; 
/* we need this for the gini among the poor */
cap program drop giniw;
program def giniw;
gsort - pce;
qui {;
gen hrnk=sum(wt);
gen hhrnk=hrnk[_n-1]+1;
replace hhrnk=1 in 1;};
qui summ wt;
local bign=_result(1)*_result(3);
qui summ pce [aweight=wt];
local mn=_result(3);
gen rnkx=pce*(hhrnk+0.5*(wt-1));
qui summ rnkx [aweight=wt];
global g=(`bign'+1)-(2/`mn')*_result(3);
global g=$g/(`bign'-1);
end; 
peas;

/* bootstrapping the measures*/ 
drop _all;
set more 1;
cap log close;
log using t33boot, replace; 
/* program for creating clustered bootstrap sample */
/* and calculating poverty measures */
cap program drop bootit;
program def bootit;
use tempclus;
bsample _N;
sort clus;
qui {;
by clus: gen nreps=_N;
by clus: keep if _n==1;
merge clus using tempall;
keep if _merge==3;
expand nreps;
drop nreps;};
weepeas;
drop _all;
end; 
/* control program */ 
cap program drop runit;
cap program def runit;
local yr=1985;
while `yr' <= 1988 {;
use cdi85_88;
keep if year==`yr';
gen wt=hhs*allwaitn;
keep clus hhid pce wt;
sort clus;
save tempall, replace;
keep clus;
qui by clus: keep if _n==1;
save tempclus, replace;
drop _all;
local mcrep=1;
while `mcrep' <= 100 {;
dis ("Year `yr', Replication `mcrep'");
bootit;
drop _all;
qui set obs 1;
gen year=`yr';
gen p0=$p0;
gen p1=$p1;
gen p2=$p2;
gen psen=$psen;
if `mcrep' != 1 | `yr' != 1985 {;
append using t33boot;
};
qui save t33boot, replace;
drop _all;
local mcrep=`mcrep'+1;
};
local yr=`yr'+1;
};
end; 
/* calculates the various measures */
cap program drop weepeas;
program def weepeas;
global pline=128.6;
qui {; 
gen pind=pce <= $pline;
qui summ pind [aweight=wt];
global p0=_result(3);
gen df=(1-pce/$pline)*pind;
qui summ df [aweight=wt];
global p1=_result(3);
gen dfa=(1-pce/$pline)^2*pind;
qui summ dfa [aweight=wt];
global p2=_result(3);
drop if pce > $pline;
giniw;
global psen=$p0*$g+$p1*(1-$g);
drop _all;
};
end; 
runit;
drop _all;
use t33boot;
sort year;
by year: summ;
log close;

[Return to Program List]