* user = your-id
* password = your-password
* package = STATA
* project = LIS

#delimit;
global keepit "casenum hweight d4 d5 d27 d3 dpi married";
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;
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 totchild;
quietly sum ey [w=cweight], de;
generate numtot =_result(2);
end;
program define lonechild;
quietly sum ey [w=cweight], de;
generate numlone =_result(2);
end;
program define povl;
quietly summ ey [w=pweight], de;
* create poverty lines equal to 50, 75, 150% of median ey;
qui gen povl1=_result(10)*.5;
qui gen povl2=_result(10)*.75;
qui gen povl3=_result(10)*1.5;
end;

use $keepit using $CCYYh;
bottom;
top;
povl;
*********************************************;
* the definition of two parent families allows other adults to be present ;
* the two parents may be married or living as married ;
*********************************************;
keep if married>0;
keep if (d4-d27)>1;
display "Children Poverty Rates TWO PARENT - CCYY";
povdeco ey [w=cweight], varpl(povl1);


use $keepit using $CCYYh,clear;
bottom;
top;
povl;
totchild ;
*******************************************;
* the definition of single mothers households allows other adults to be present *;
*******************************************;
keep if d3==2 & married==0 ;
keep if d27 >0;
display "Children Poverty Rates SINGLE MOTHER - CCYY";

povdeco ey [w=cweight], varpl(povl1);
lonechild ;
generate perclone = numlone/(numtot) ;
display "PERCENTAGE of Children in SINGLE MOTHER households- CCYY";
summ perclone ;

use $keepit using $CCYYh,clear;
bottom;
top;
povl;
povdeco ey [w=cweight], varpl(povl1);
generate u50m = $S_FGT0 ;
povdeco ey [w=cweight], varpl(povl2);
generate u75m = $S_FGT0 ;
povdeco ey [w=cweight], varpl(povl3);
generate u150m = $S_FGT0 ;

generate d50 = u50m ;
generate d5075 = u75m - u50m ;
generate d75150 = u150m - u75m ;
generate d150 = 1 - u150m ;

display "DISTRIBUTION of Children in different income households- CCYY";
summ d50 d5075 d75150 d150 ;