* user = your-id
* password = your-password
* package = stata
* project = lis

#delimit;
global keepit "casenum hweight d4 d5 d27 num6574 numge75 dpi";

program define setups;
*** avoid double counting of household records;
drop if d5==3;
*** select only records if DPI filled;
drop if dpi==.;
drop if dpi==0;
*** set equivalence scale as square root of number of persons;
generate ey=(dpi/(d4^0.5));
*** standardise weights so that average weight = 1 ;
qui sum hweight, detail;
gen nwgt=hweight/_result(3);
generate pweight=(nwgt*d4);
generate cweight=(nwgt*d27);
generate eweight=nwgt*(num6574+numge75);
end;
*** bottomcoding at one percent equivalized mean;
program define bottom;
setups;
quietly sum ey [w=pweight];
generate botlin=0.01*_result(3);
replace ey=botlin if ey<botlin;
end;
*** topcoding at ten times unequivalized median;
program define top;
quietly sum dpi [w=pweight], de;
generate toplin=10*_result(10);
replace ey=(toplin/(d4^0.5)) if dpi>toplin;
end;

*** standard error in overall poverty rate ;
use $keepit using $ccyyh;
bottom;
top;
qui summ ey [w=pweight], de;
qui gen povl=_result(10)*.5;
set seed 100001;
version 7 : bs "povdeco ey [w=pweight], varpl(povl)" "S_FGT0", reps(500);

*** standard error in child poverty rate ;
use $keepit using $ccyyh, replace ;
bottom;
top;
qui summ ey [w=pweight], de;
qui gen povl=_result(10)*.5;
set seed 100001;
drop if d27<1;
version 7 : bs "povdeco ey [w=cweight], varpl(povl)" "S_FGT0", reps(500);

*** standard error in elderly poverty rate ;
use $keepit using $ccyyh, replace ;
bottom;
top;
qui summ ey [w=pweight], de;
qui gen povl=_result(10)*.5;
set seed 100001;
drop if num6574<1 & numge75<1;
version 7 : bs "povdeco ey [w=eweight], varpl(povl)" "S_FGT0", reps(500);