3.3. Script 3: Base Mortality

This file creates mortality parameters based on demographic macro projections as typically available online e.g. from DemProj. These parameters can be used either directly in the model, or indirectly as alignment targets of demographic projections. Demographic scenario data are read in from CSV files and are not calculated from micro data.

3.3.1. File output

The code below generates model parameters stored in a Modgen .dat file

  • Mortality table by age and sex
  • Life expectancy by sex and year

3.3.2. Code

####################################################################################################
#
#  DYNAMIS-POP Parameter Generation File 02 - Demographic Projections
#  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(fmsb)

load(file="globals_for_analysis.RData")

# Set Parameter Output File

parafile  <- file(g_para_basemortality, "w")

####################################################################################################
# Write the parameters (converted from csv files to modgen dat formats
####################################################################################################

cat("parameters { \n", file=parafile)

cat("//EN Life Expectancy\ndouble LifeExpectancy[SIM_YEAR_RANGE][SEX]  = {\n", file=parafile, append=TRUE)
cat(dp_expectancy_dat, file=parafile, sep=", ", append=TRUE)
cat("\n};\n\n", file=parafile, append=TRUE)

cat("//EN Mortality hazard by age\ndouble	MortalityTable[AGE_RANGE][SEX] = {\n", file=parafile, append=TRUE)
cat(dp_mortality_dat, file=parafile, sep=", ", append=TRUE)
cat("\n};\n\n", file=parafile, append=TRUE)

cat("\n};\n", file=parafile, append=TRUE)
close(parafile)