global data "C:\Users\mmabrigo\Google Drive\01 Data\PSA data\" ******************************************************************************** * Part I: Prepare main file ******************************************************************************** // Set macros global hhid reg prv urb hcn domain // Individual level data * Load data use "$data\Annual Poverty Indicators Survey\apis1999memv2.dta", clear sort $hhid col03 bysort $hhid: gen lno = _n label var lno "HH member - line number" * Generate main variables ren col05 age replace age = 80 if age > 80 label var age "Age" label val age age80 label def age80 80 "80 and up", modify ren rfact indw label var indw "Sampling weight - individuals" gen head = (col03 == 1) label var head "Household head" gen inschl = (col13_cur_attend == 1) label var inschl "Attending school" gen oschly = !(col13_cur_attend == 1)*inrange(age,3,24) label var oschl "Not attending school" gen sick = inlist(col07_got_ill,1,2,3) label var sick "Got ill/sick" gen visit = (col09_v_health == 1) label var visit "visited health facility" tostring col10_type_h, replace gen vhosp = strmatch(col10_type_h, "*1*") | strmatch(col10_type_h, "*2*") label var vhosp "visited hospital" gen vhoth = (visit == 1 & vhosp != 1) | (sick == 1 & vhosp == 0) label var vhoth "visited non-hospital health facility, or sick but not hospitalized" * Keep variables and save temporary file keep $hhid lno age head inschl oschly visit sick vhosp vhoth indw tempfile hhmem save `hhmem', replace // Household level data * Load data use "$data\Annual Poverty Indicators Survey\apis1999hhv2.dta", clear * Generate main variables egen educ = rowtotal(q32csh_41100 q32gft_41100) label var educ "Education" egen medic = rowtotal(q34csh_43100 q34gft_43100) label var medic "Medical care" ren q14tot_14000 tbcco label var tbcco "Tobacco" ren q13tot_13000 albev label var albev "Alcoholic beverages" egen double othex = rowtotal( /// /*hrent*/ g04a1_rent g04a2_rent /// /*food*/ food /// /*fuel*/ q21tot_21100 /// /*trcom*/ q22tot_22100 /// /*hoper*/ q23tot_23100 /// /*prcre*/ q24tot_31100 /// /*cloth*/ q31csh_32100 q31gft_32100 /// /*rcrtn*/ q33csh_42100 q33gft_42100 /// /*ndfur*/ q35csh_51100 q35gft_51100 /// /*occsn*/ q39csh_81100 q39gft_81100 /// /*othex*/ q311csh_83000 q311gft_83000 /// ) label var othex "Consumption NEC" ren rfact hhw label var hhw "Sampling weight - household" * Keep variables and save temporary file keep $hhid educ medic tbcco albev othex hhw tempfile hh save `hh', replace // Merge individual and household data use `hh', clear duplicates drop $hhid, force merge 1:m $hhid using `hhmem', nogen ******************************************************************************** * Private Education ******************************************************************************** *1) Generate number of in-school and out-of-school members by age group within hh * NOTE: age group coverage may differ cap drop hhage*inschl cap drop hhage*oschly forval x = 3(3)30 { egen hhage`x'inschl = total(inrange(age,`x',`x'+2) * inschl == 1), by($hhid) egen hhage`x'oschly = total(inrange(age,`x',`x'+2) * oschly == 1), by($hhid) } *2) Regress hh education consumption on (1). IMPORTANT: 1 observation per hh only reg educ hhage*inschl hhage*oschly if head == 1, nocons *3) Generate weights, replace negative weights with zero gen educw = 0 forval x = 3(3)30 { replace educw = _b[hhage`x'inschl] if (inrange(age,`x',`x'+2) * inschl == 1) replace educw = _b[hhage`x'oschly] if (inrange(age,`x',`x'+2) * oschly == 1) } replace educw = 0 if educw < 0 *4) Generate total of weights within household egen hheducw = total(educw), by($hhid) *5) Allocate household level consumption gen educ_allocated = educw/hheducw * educ replace educ_allocated = 0 if hheducw == 0 // replace missing with zero *6) Tabulate per capita values tabstat educ_allocated [aw = indw], by(age) *7) Housekeeping cap drop hhage*inschl cap drop hhage*oschly ******************************************************************************** * Private Health ******************************************************************************** // Consumption, Private Health: Approach 1 ************************************* *1) Generate number of members using health services by type by age-group * NOTE: age group coverage may differ cap drop hhage*vhosp cap drop hhage*vhoth forval x = 0(10)80 { egen hhage`x'vhosp = total(inrange(age,`x',`x'+9) * vhosp == 1), by($hhid) egen hhage`x'vhoth = total(inrange(age,`x',`x'+9) * vhoth == 1), by($hhid) } *2) Regress hh health consumption on (1). IMPORTANT: 1 observation per hh only reg medic hhage*vhosp hhage*vhoth if head == 1, nocons *3) Generate weights, replace negative weights with zero gen medicw1 = 0 forval x = 0(10)80 { replace medicw1 = _b[hhage`x'vhosp] if (inrange(age,`x',`x'+9) * vhosp == 1) replace medicw1 = medicw1 + _b[hhage`x'vhoth] if (inrange(age,`x',`x'+9) * vhoth == 1) } replace medicw1 = 0 if medicw1 < 0 *4) Generate total of weights within household egen hhmedicw1 = total(medicw1), by($hhid) *5) Allocate household level consumption gen medic_allocated1 = medicw1/hhmedicw1 * medic replace medic_allocated1 = 0 if hhmedicw1 == 0 // replace missing with zero *6) Tabulate per capita values tabstat medic_allocated1 [aw = indw], by(age) *7) Housekeeping cap drop hhage*vhosp cap drop hhage*vhoth // Consumption, Private Health: Approach 2 ************************************* *1a) Generate number of household members age group * NOTE: age group coverage may differ cap drop hhage*mem forval x = 0(10)80 { egen hhage`x'mem = total(inrange(age,`x',`x'+9)), by($hhid) } *1b) Generate utilization by age group gen age10 = floor(age/10)*10 egen utilization = wtmean(visit), by(age10) weight(indw) * ----- Linear model *2a) Regress hh health consumption on (1). IMPORTANT: 1 observation per hh only reg medic c.utilization#c.(hhage*mem) if head == 1, nocons *3a) Generate weights, replace negative weights with zero gen medicw2a = 0 forval x = 0(10)80 { replace medicw2a = _b[c.utilization#c.hhage`x'mem] if (inrange(age,`x',`x'+9)) } replace medicw2a = 0 if medicw2a < 0 *4a) Generate total of weights within household egen hhmedicw2a = total(medicw2a), by($hhid) *5a) Allocate household level consumption gen medic_allocated2a = medicw2a/hhmedicw2a * medic replace medic_allocated2a = 0 if hhmedicw2a == 0 // replace missing with zero *6a) Tabulate per capita values tabstat medic_allocated2a [aw = indw], by(age) * ----- Quadratic model *2b) Regress hh health consumption on (1). IMPORTANT: 1 observation per hh only reg medic c.utilization#c.(hhage*mem) /// c.age#c.utilization#c.(hhage*mem) /// c.age##c.age#c.utilization#c.(hhage*mem) if head == 1, nocons *3b) Generate weights, replace negative weights with zero gen medicw2b = 0 forval x = 0(10)80 { replace medicw2b = _b[c.utilization#c.hhage`x'mem]*utilization /// + _b[c.utilization#c.hhage`x'mem]*utilization*age /// + _b[c.utilization#c.hhage`x'mem]*utilization*age^2 /// if (inrange(age,`x',`x'+9)) } replace medicw2b = 0 if medicw2b < 0 *4a) Generate total of weights within household egen hhmedicw2b = total(medicw2b), by($hhid) *5a) Allocate household level consumption gen medic_allocated2b = medicw2b/hhmedicw2b * medic replace medic_allocated2b = 0 if hhmedicw2b == 0 // replace missing with zero *6a) Tabulate per capita values tabstat medic_allocated2b [aw = indw], by(age) * ----- *7) Housekeeping cap drop hhage*mem cap drop utilization cap drop age10 // Consumption, Private Health: Approach 3 ************************************* *1) Generate average health consumption per household egen fsize = count(lno), by($hhid) gen medic_iter1 = medic/fsize *2) Generate weight: per capita consumption by age group egen medicw3 = wtmean(medic_iter1), by(age) weight(indw) *3) Generate total of (2) within household egen hhmedicw3 = total(medicw3), by($hhid) *4) Allocate household level consumption gen medic_allocated3 = medicw3/hhmedicw3 * medic *5) Iterate (2)-(4), replacing medic_iter1 with allocated consumption, until converges *6) Tabulate tabstat medic_allocated3 [aw = indw], by(age) // Consumption, Private Health: Approach 4 ************************************* *1a) Generate number of household members age group * NOTE: age group coverage may differ cap drop hhage*mem forval x = 0(10)80 { egen hhage`x'mem = total(inrange(age,`x',`x'+9)), by($hhid) } *2) Regress hh health consumption on (1). IMPORTANT: 1 observation per hh only reg medic hhage*mem if head == 1, nocons *3) Generate weights, replace negative weights with zero gen medicw4 = 0 forval x = 0(10)80 { replace medicw4 = _b[hhage`x'mem] if (inrange(age,`x',`x'+9)) } replace medicw4 = 0 if medicw4 < 0 *4) Generate total of weights within household egen hhmedicw4 = total(medicw4), by($hhid) *5) Allocate household level consumption gen medic_allocated4 = medicw4/hhmedicw4 * medic replace medic_allocated4 = 0 if hhmedicw4 == 0 // replace missing with zero *6) Tabulate per capita values tabstat medic_allocated4 [aw = indw], by(age) *7) Housekeeping cap drop hhage*mem // Compare approaches tabstat medic_allocated* [aw = indw], by(age) ******************************************************************************** * Private Consumption other than Education and Health ******************************************************************************** * NOTE: separate profiles may be calculated for adult goods, e.g. tobacco and * alcoholic beverages, using methods discussed above egen othc = rowtotal(albev tbcco othex) *1) Generate weight based on equivalence scale gen ntaw = 1 - 0.6*inrange(age,5,19)*(20-age)/16 - 0.6*(age<=4) label var ntaw "NTA adult equivalence weight" *2) Generate total of weights within household egen hhntaw = total(ntaw), by($hhid) *3) Allocate other consumption gen othc_allocated = ntaw / hhntaw * othc ******************************************************************************** * Generate per capita age profiles ******************************************************************************** // Collapse to generate mean collapse (mean) *allocated* (count) n = lno /// [pw = indw], by(age) // Education: No need to smooth line educ_allocated age, sort // Health: Do not smooth early ages line medic_allocated1 age, sort supsmooth medic_allocated1 age if age >= 2 [aw = n], /// gen(medic_allocated1_s, replace) addplot(line medic_allocated1 age, sort) noscatter replace medic_allocated1_s = medic_allocated1 if age <= 2 line medic_allocated3 age, sort supsmooth medic_allocated3 age if age >= 2 [aw = n], /// gen(medic_allocated3_s, replace) addplot(line medic_allocated3 age, sort) noscatter replace medic_allocated3_s = medic_allocated3 if age <= 2 line medic_allocated1* medic_allocated3* age, sort // Other consumption line othc_allocated age, sort supsmooth othc_allocated age if age >= 15 [aw = n], /// gen(othc_allocated_s, replace) addplot(line othc_allocated age, sort) noscatter replace othc_allocated_s = othc_allocated if age <= 15