* do e:\DHS\programs\schooling\KE2014_in_school_do_16Nov2023.txt /* This program concerns the calculation of the net attendance ratio Kenya 2014 DHS The fieldwork was April-October 2014 Attendance is based on hv122, not hv121 label list HV122 0 no education, preschool 1 primary 2 secondary 3 higher 8 don't know Deviations from table 2.14 are plausibly due to the random component of imputation of age for children who were in the PR file but not the BR file */ ***************************************************** program define prepare_for_merge * Get cmc of birth for children in the BR file. * Otherwise we only have hv105 to work with and must impute cmc of birth. * Prepare BR file for merge use BR.dta, clear drop if b16==0 | b16==. keep v024 v001 v002 b16 b3 gen in_BR=1 rename v001 cluster rename v002 hh rename b16 line sort cluster hh line save BR.dta, replace * Prepare PR file for merge use PR.dta, clear * The following table shows month and year of fieldwork (all cases, not just children) tab hv006 hv007 rename hv001 cluster rename hv002 hh rename hvidx line * Child must be defacto and in the age range 5-24. * Later the age range is restricted further. keep if hv103==1 & hv105>=5 & hv105<=24 gen wt=hv005/1000000 keep cluster hh line wt hv005 hv006 hv007 hv008 hv024 hv025 hv101-hv105 hv121 hv122 gen in_PR=1 sort cluster hh line save PR.dta, replace end ***************************************************** program define merge_files use PR.dta, clear * Merge with BR merge cluster hh line using BR.dta keep if in_PR==1 drop _merge gen cmcdob=b3 sort cluster hh line ********************** * Impute month of birth for children not in the BR file ********************** gen max_cmcdob = hv008 - hv105*12 gen min_cmcdob = max_cmcdob - 11 gen rn=uniform() replace cmcdob = min_cmcdob+int(12*rn) if b3==. drop max_ min_ rn save merged_file.dta, replace end ***************************************************** program define calc_indicator use merged_file.dta, clear ********************** * Specify the cmc of eligibility ********************** * First specify yeareduc and mntheduc, the calendar year and month for eligibility. * Usually yeareduc will be the year of the interview. The month is survey-specific. * In the CSPro program for Kenya 2014, mntheduc is 2. * Perhaps it should have been another value, such as 1, but it is 2. scalar yeareduc = 2014 scalar mntheduc = 2 * Next specify cmceduc, the cmc for eligibility; this can increase by 12 during fieldwork. gen cmceduc = (yeareduc-1900)*12+mntheduc replace cmceduc = cmceduc+12 if hv008>=cmceduc+12 ********************** ********************** * Specify the age of the child, in completed years, in the cmc of eligibility ********************** gen age_schl = int((cmceduc-cmcdob)/12) ********************** * Specify the age range for primary and secondary school eligibility * L for low end of age range, H for high end of age range * p for primary, s for secondary * For example, primary ages 6-13, secondary ages 14-17 scalar Lp=6 scalar Hp=13 scalar Ls=14 scalar Hs=17 * Apparently if a primary-age child is in secondary, they are counted as not in school. * and if a secondary-age child is in post-secondary, they are counted as not in school (?!) * Determine whether the child's age was in the range for primary school and was attending gen in_schoolp=. replace in_schoolp=0 if hv103==1 & age_schl>=Lp & age_schl<=Hp *replace in_schoolp=100 if in_schoolp==0 & (hv122==1 | hv122==2) replace in_schoolp=100 if in_schoolp==0 & hv122==1 * Determine whether the child's age was in the range for secondary school and was attending gen in_schools=. replace in_schools=0 if hv103==1 & age_schl>=Ls & age_schl<=Hs *replace in_schools=100 if in_schools==0 & (hv122==2 | hv122==3) replace in_schools=100 if in_schools==0 & hv122==2 format in_school* %6.1f tab hv025 hv104 [fweight=hv005], summarize(in_schoolp) means noobs tab hv025 hv104 [fweight=hv005], summarize(in_schools) means noobs end ***************************************************** ***************************************************** ***************************************************** ***************************************************** ***************************************************** * EXECUTION BEGINS HERE * Specify a workspace cd e:\DHS\DHS_data\scratch * Read data files and save with generic file names local lfiles PR BR foreach lfn of local lfiles { use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\KE`lfn'72FL.DTA" , clear save `lfn'.dta, replace } prepare_for_merge merge_files calc_indicator