Home » Topics » General » SCHOOL ATTENDANCE (Net and Gross Attendance Ratios(NAR_GAR_GPINDEX))
SCHOOL ATTENDANCE [message #23782] 
Tue, 30 November 2021 03:07 
Francois
Messages: 9 Registered: February 2017 Location: KIGALI

Member 


Hello,
I am trying to match with the Table 2.12 of Rwanda DHS 2019_30 using the GITHUB Codes but i don't see results matching with this table comparing with any of the used backgrounds.
here the codes used:
/*********************************************************** ******************************************
************************************************************ *****************************************/
/* 
Variables created in this file:
ph_sch_nar_prim "Primary school net attendance ratio (NAR)"
ph_sch_nar_sec "Secondary school net attendance ratio (NAR)"
ph_sch_gar_prim "Primary school gross attendance ratio (GAR)"
ph_sch_gar_sec "Secondary school gross attendance ratio (GAR)"
ph_sch_nar_prim_*_gpi "Gender parity index for NAR primary"
ph_sch_nar_sec_*_gpi "Gender parity index for NAR secondary"
ph_sch_gar_prim_*_gpi "Gender parity index for GAR primary"
ph_sch_gar_sec_*_gpi "Gender parity index for GAR secondary"
 */
clear all
set memory 1000m
set maxvar 10000
set more off
* For net attendance rates (NAR) and gross attendance rates (GAR) we need to know the age of children at the start of the school year.
* For this we need to get date of birth from birth history and attach to children's records in the PR file.
* open the birth history data to extract date of birth variables needed.
cd"C:\Users\ICF Rwanda\Desktop\district\DHS6"
use RWBR81FL, clear
* keep only the variables we need
keep v001 v002 v003 b3 b16
* drop if the child in the birth history was not in the household or not alive
drop if b16==0  b16==.
* rename key variables for matching
rename b16 hvidx
rename v001 hv001
rename v002 hv002
* sort on key variables
sort hv001 hv002 hvidx
* if there are some duplicates of line number in household questionnaire, we need to drop the duplicates
* gen dup = (hv001 == hv001[_n1] & hv002 == hv002[_n1] & hvidx == hvidx[_n1])
* drop if dup==1
* drop dup
* resort to make sure still sorted
* sort hv001 hv002 hvidx
* save a temporary file for merging
save tempBR, replace
use RWPR81FL, clear
* use the PR file for household members for the NAR and GAR indicators
* merge in the date of birth from the women's birth history for the household member
merge 1:1 hv001 hv002 hvidx using tempBR
* there are a few mismatches of line numbers (typically a small number of cases) coming rom the BR file, so let's drop those
drop if _merge==2
* restrict to de facto household members age 524, and drop all others
keep if hv103==1 & inrange(hv105,5,24)
* now we calculate the child's age at the start of the school year
* but first we have to specify the month and year of the start of the school year referred to in the survey
* example, for Zimbabwe 2015 survey this was January 2015
global school_start_yr = 2015
global school_start_mo = 1
* also need the age ranges for primary and secondary
* example, for Zimbabwe 2015, the age range is 612 for primary school and 1318 for secondary school
global age_prim_min = 7
global age_prim_max = 12
global age_sec_min = 13
global age_sec_max = 18
* produce century month code of start of school year for each state and phase
gen cmcSch = ($school_start_yr  1900)*12 + $school_start_mo
* calculate the age at the start of the school year, using the date of birth from the birth history if we have it
gen school_age = int((cmcSch  b3) / 12) if b3 != .
* Impute an age at the beginning of the school year when CMC of birth is unknown
* the random imputation below means that we won't get a perfect match with the report, but it will be close
gen xtemp = hv008  (hv105 * 12) if b3 == .
gen cmctemp = xtemp  int(uniform()*12) if b3 == .
replace school_age = int((cmcSch  cmctemp) / 12) if b3 == .
* Generate variables for whether the child is in the age group for primary or seconary school
gen prim_age = inrange(school_age,$age_prim_min,$age_prim_max)
gen sec_age = inrange(school_age,$age_sec_min ,$age_sec_max )
* create the school attendance variables, not restricted by age
gen prim = (hv122 == 1)
gen sec = (hv122 == 2)
* set sample weight
cap gen wt = hv005/1000000
* For NAR we can use this as just regular variables and can tabulate as follows, but can't do this for GAR as the numerator is not a subset of the denominator
* NAR is just the proportion attending primary/secondary school of children in the correct age range, for de facto children
gen nar_prim = prim if prim_age == 1
gen nar_sec = sec if sec_age == 1
lab var nar_prim "Primary school net attendance ratio (NAR)"
lab var nar_sec "Secondary school net attendance ratio (NAR)"
* tabulate primary school attendance
tab hv104 nar_prim [iw=wt] , row
tab hv025 nar_prim [iw=wt] , row
* tabulate secondary school attendance
tab hv104 nar_sec [iw=wt] , row
tab hv025 nar_sec [iw=wt] , row
* Program for calculating NAR or GAR
* NAR just uses a mean of one variable
* GAR uses a ratio of two variables
* Program to produce NAR or GAR for background characteristics (including total) for both sex, combined and separately
cap program drop nar_gar
program define nar_gar
* parameters
* type of rate  nar or gar
* type of schooling  prim or sec
* background variable for disaggregation
* generates variables of the following format
* ph_sch_`rate'_`sch'_`backvar'_`sex'
* e.g. ph_sch_nar_prim_total_0
* or ph_sch_gar_sec_hv025_2
* sex: 0 = both sexes combined, 1=male, 2=female
* type of rate  nar or gar
local rate `1'
if "`rate'" != "nar" & "`rate'" != "gar" {
di as error "specify type of rate as nar or gar"
exit 198
}
* type of schooling  prim or sec only
local sch `2'
if "`sch'" != "prim" & "`sch'" != "sec" {
di as error "specify schooling as prim or sec"
exit 198
}
* name of background variable
local backvar `3'
* do for total = 0, and each sex male = 1, female = 2
foreach sex in 0 1 2 {
if `sex' == 0 local select 0==0 /* always true */
else local select hv104==`sex'
if "`rate'" == "nar" { /* Net Attendance Rate (NAR) */
mean `sch' [iw=wt] if `select' & `sch'_age == 1, over(`backvar')
* results matrix for mean  used for NAR
mat x = e(b)
}
else { /* Gross Attendance Rate (GAR) */
ratio `sch' / `sch'_age [iw=wt] if `select', over(`backvar')
* results matrix for ratio  used for GAR
mat x = r(table)
}
* generate the output variable we will fill
gen ph_sch_`rate'_`sch'_`backvar'_`sex' = .
* get all of the characteristics of the background variable
cap levelsof `backvar'
local ix = 1
local lev `r(levels)'
* loop through the characteristics and get the result from matrix x
foreach i in `lev' {
* capture the result for this characteristic
replace ph_sch_`rate'_`sch'_`backvar'_`sex' = 100*x[1,`ix'] if `backvar' == `i'
local ix = `ix' + 1
}
* label the resulting variable
local schooling primary
if "`sch'" == "sec" local schooling secondary
local sexlabel both sexes
if `sex' == 1 local sexlabel males
if `sex' == 2 local sexlabel females
lab var ph_sch_`rate'_`sch'_`backvar'_`sex' "`rate' for `schooling' education for background characteristic `backvar' for `sexlabel'"
}
* gender parity index for a rate for a characteristic  female (2) rate divided by male (1) rate
gen ph_sch_`rate'_`sch'_`backvar'_gpi = 100 * (ph_sch_`rate'_`sch'_`backvar'_2 / ph_sch_`rate'_`sch'_`backvar'_1)
lab var ph_sch_`rate'_`sch'_`backvar'_gpi "gender parity index for `rate' for `schooling' education for background characteristic `backvar'"
end
* create total background characteristic
gen total = 0
lab var total "total"
* Caculate indicators and save them in the dataset
nar_gar nar prim total /* NAR primary  total population */
nar_gar nar prim hv025 /* NAR primary  urban/rural */
nar_gar nar prim hv024 /* NAR primary  region */
nar_gar nar prim hv270 /* NAR primary  wealth index */
nar_gar nar sec total /* NAR secondary  total population */
nar_gar nar sec hv025 /* NAR secondary  urban/rural */
nar_gar nar sec hv024 /* NAR secondary  region */
nar_gar nar sec hv270 /* NAR secondary  wealth index */
nar_gar gar prim total /* GAR primary  total population */
nar_gar gar prim hv025 /* GAR primary  urban/rural */
nar_gar gar prim hv024 /* GAR primary  region */
nar_gar gar prim hv270 /* GAR primary  wealth index */
nar_gar gar sec total /* GAR secondary  total population */
nar_gar gar sec hv025 /* GAR secondary  urban/rural */
nar_gar gar sec hv024 /* GAR secondary  region */
nar_gar gar sec hv270 /* GAR secondary  wealth index */
* Dividing GPI indicators by 100
foreach x in ph_sch_nar_prim_total_gpi ph_sch_nar_prim_hv025_gpi ph_sch_nar_prim_hv024_gpi ph_sch_nar_prim_hv270_gpi ph_sch_nar_sec_total_gpi ph_sch_nar_sec_hv025_gpi ph_sch_nar_sec_hv024_gpi ph_sch_nar_sec_hv270_gpi ph_sch_gar_prim_total_gpi ph_sch_gar_prim_hv025_gpi ph_sch_gar_prim_hv024_gpi ph_sch_gar_prim_hv270_gpi ph_sch_gar_sec_total_gpi ph_sch_gar_sec_hv025_gpi ph_sch_gar_sec_hv024_gpi ph_sch_gar_sec_hv270_gpi {
replace `x'=`x'/100
}
erase tempBR.dta
************************************************************ *****************************************
************************************************************ *****************************************
*Tabulating indicators by background variables and exporting estimates to excel table Tables_edu
*the tabulations will provide the estimates for the indicators for the total, males, and females and by hv025, hv024, and hv270
//Primary school net attendance ratio (NAR) and gender parity index
tab1 ph_sch_nar_prim* [iw=wt]
tabout ph_sch_nar_prim* using Tables_schol.xls [iw=wt] , oneway cells(cell) replace
//Secondary school net attendance ratio (NAR) and gender parity index
tab1 ph_sch_nar_sec* [iw=wt]
tabout ph_sch_nar_sec* using Tables_schol.xls [iw=wt] , oneway cells(cell) append
//Primary school gross attendance ratio (GAR) and gender parity index
tab1 ph_sch_gar_prim* [iw=wt]
tabout ph_sch_gar_prim* using Tables_schol.xls [iw=wt] , oneway cells(cell) append
//Secondary school gross attendance ratio (GAR) and gender parity index
tab1 ph_sch_gar_sec* [iw=wt]
tabout ph_sch_gar_sec* using Tables_schol.xls [iw=wt] , oneway cells(cell) append
*/
AF





Goto Forum:
Current Time: Sat Dec 9 10:24:52 Coordinated Universal Time 2023
