####################################################################################################
#
# 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)