# Script 9: Primary Education Refined Fate > This code calculates individual level differences in primary entry and retention rates by individual characteristics. The list of population groups is model specific, in the current implementation mother's primary education is used. The code below uses the the analysis file of residents typically stemming from a population census. As this file includes household IDs but no information on how people relate together, some simplified assumptions are used to create the variable for mother's education. - We use the highest education of all famale household members at least 15 years older than the studied child as proxy for mother's education - Children selected for the analysis of entry into primary school are children age 8-11 who live in a household with at least one female older than 27 - Children selected for the analysis of primary school graduation are children age 12-13 who live in a household with at least one female older than 30 The reulting parameters are: - Odds ratios of starting primary school by mother's education (1 for mothers without schooling) - Odds ratios of remaining in primary school until graduation by mother's education (1 for mothers without schooling) - A model selection parameter - The starting year from which on the refined model is to be used ## Code ```{r, message=FALSE, warning=FALSE} #################################################################################################### # # DYNAMIS-POP Parameter Generation File 9 - Refined Primary Education Fate # This file is generic and works for all country contexts. # Input file: globals_for_analysis.RData (To generate such a file run the setup script) # Last Update: Martin Spielauer 2018-06-29 # #################################################################################################### #################################################################################################### # Clear work space, load required packages and the input object file #################################################################################################### rm(list=ls()) library(haven) library(dplyr) library(data.table) library(sp) library(maptools) library(survival) library(fmsb) library(eha) # Set Parameter Output File load(file="globals_for_analysis.RData") parafile <- file(g_para_primaryeducrefined, "w") #################################################################################################### # Analysis #################################################################################################### # School entry # highest education of females >27 in household - m_educmo - children 8-11 dat <- as.data.table(g_residents_dat) dat$M_WEIGHT <- dat$M_WEIGHT / g_reweight #dat[,m_moeduc:=max(M_EDUC[which(M_MALE == 0 & M_AGE > 27)]),by=M_HHID] dat[,m_moeduc:=as.integer(max(M_EDUC[which(M_MALE == 0 & M_AGE > 27)])),by=M_HHID] dat <- dat[dat$M_AGE>=8 & dat$M_AGE<=12 & dat$m_moeduc>=0] dat$m_enter <- 0 dat$m_enter[dat$M_EDUC > 0] <- 1 # male dat_male <- dat[dat$M_MALE==1] EnterMale <- glm(m_enter ~ factor(m_moeduc),#+factor(M_DOB), family = quasibinomial, weights = M_WEIGHT, data = dat_male) m_odds_entermale <- exp(EnterMale$coefficients) m_odds_entermale # female dat_female <- dat[dat$M_MALE==0] EnterFemale <- glm(m_enter ~ factor(m_moeduc),#+factor(M_DOB), family = quasibinomial, weights = M_WEIGHT, data = dat_female) m_odds_enterfemale <- exp(EnterFemale$coefficients) m_odds_enterfemale # School graduation # highest education of females >30 in household - m_educmo - children 12-13 dat <- as.data.table(g_residents_dat) dat$M_WEIGHT <- dat$M_WEIGHT / g_reweight #dat[,m_moeduc:=max(M_EDUC[which(M_MALE == 0 & M_AGE > 30)]),by=M_HHID] dat[,m_moeduc:=as.integer(max(M_EDUC[which(M_MALE == 0 & M_AGE > 30)])),by=M_HHID] dat <- dat[dat$M_AGE>=12 & dat$M_AGE<=14 & dat$m_moeduc>=0] dat <- dat[dat$M_EDUC>0] dat$m_grad <- 0 dat$m_grad[dat$M_EDUC > 1] <- 1 # male dat_male <- dat[dat$M_MALE==1] GradMale <- glm(m_grad ~ factor(m_moeduc),#+factor(M_DOB), family = quasibinomial, weights = M_WEIGHT, data = dat_male) m_odds_gradmale <- exp(GradMale$coefficients) m_odds_gradmale # female dat_female <- dat[dat$M_MALE==0] GradFemale <- glm(m_grad ~ factor(m_moeduc),#+factor(M_DOB), family = quasibinomial, weights = M_WEIGHT, data = dat_female) m_odds_gradfemale <- exp(GradFemale$coefficients) m_odds_gradfemale #################################################################################################### # Write the parameters #################################################################################################### cat("parameters { \n", file=parafile) cat("double Educ1StartOdds[EDUC1_GROUP][SEX] = {(2) 1.0,", m_odds_enterfemale[2],", ", m_odds_entermale[2],", ", m_odds_enterfemale[3],", ", m_odds_entermale[3],", }; //EN Odds of starting primary school\n", file=parafile, append=TRUE) cat("double Educ1GradOdds[EDUC1_GROUP][SEX] = {(2) 1.0,", m_odds_gradfemale[2],", ", m_odds_gradmale[2],", ", m_odds_gradfemale[3],", ", m_odds_gradmale[3],", }; //EN Odds primary school graduation\n", file=parafile, append=TRUE) cat("EDUC1_MODEL Educ1Model = E1M_BASE; //EN Model Selection\n", file=parafile, append=TRUE) cat("int Educ1FirstCohortRefinedModel = 2000; //EN First birth cohort to apply refined model\n", file=parafile, append=TRUE) cat("\n};\n", file=parafile, append=TRUE) close(parafile) ```