* NOTE: You need to set the Stata working directory to the path * where the data file is located. set more off clear quietly infix /// float hwtsupp 1-10 /// byte hflag 11-11 /// byte spmpov 16-16 /// double spmtotres 17-38 /// double spmthresh 39-60 /// double spmfamunit 61-68 /// float wtsupp 69-78 /// byte age 83-84 /// using "[your IPUMS data download with the variables above]" replace hwtsupp = hwtsupp / 10000 replace wtsupp = wtsupp / 10000 format hwtsupp %10.4f format spmtotres %22.0f format spmthresh %22.0f format spmfamunit %8.0f format wtsupp %10.4f label var hwtsupp "Household weight, Supplement" label var wtsupp "Supplement Weight" /* my code */ /* round weights so they work as SAS frequency weights, and divide by 2 because of 2014 CPS experimental redesign */ gen rhwtsupp = round(hwtsupp/2) gen rwtsupp = round(wtsupp/2) gen oneperfam = 0 bysort spmfamunit (age): replace oneperfam = 1 if _n==1 /* Now you can use oneperfam==1 to analyze family units instead of individuals. Because it's sorted by age within families, with onperfam if age <18 then the family unit includes a child under 18 */ gen povneed = spmthresh-spmtotres /* amount needed to bring the unit above SPM poverty */ gen kidpovcat=0 replace kidpovcat=1 if age<18 & spmpov==1 /* separate poor-kid fams from everyone else */ egen surpluscat = cut(povneed) if spmpov==0, group(10) /* create deciles of non-poor family units */ /* to get surplus per family for non-poor families - just using the youngest person in each fam unit */ bysort surpluscat: sum povneed [fweight=rhwtsupp] if oneperfam==1 /* to get deficit for poor families with children - just using the youngest person in each fam unit */ sum povneed [fweight=rhwtsupp] if oneperfam==1 & kidpovcat==1 /* diagnostic */ list spmfamunit spmthresh spmtotres povneed spmpov age kidpovcat sum povneed [fweight=rhwtsupp] if kidpovcat==1, det sum povneed [fweight=rhwtsupp] if spmpov==0, det