* 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));
*** create person weight as hweight times number of persons;
generate pweight=hweight*d4;
*** create child weight as hweight times number of children;
generate cweight=hweight*d27;
*** create elderly weight as hweight times number of elderly persons;
generate eweight=hweight*(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;
program define povl;
summ ey [w=pweight], de;
*** create poverty lines equal to 40, 50, & 60% of median ey;
qui gen povl1=_result(10)*.4;
qui gen povl2=_result(10)*.5;
qui gen povl3=_result(10)*.6;
end;

use $keepit using $ccyyh;
bottom;
top;
povl;
povdeco ey [w=pweight], varpl(povl1);
povdeco ey [w=pweight], varpl(povl2);
povdeco ey [w=pweight], varpl(povl3);
povdeco ey [w=cweight], varpl(povl1);
povdeco ey [w=cweight], varpl(povl2);
povdeco ey [w=cweight], varpl(povl3);
povdeco ey [w=eweight], varpl(povl1);
povdeco ey [w=eweight], varpl(povl2);
povdeco ey [w=eweight], varpl(povl3);