3.4. Script 4: Base Fertility

This file creates the fertility 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.4.1. File output

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

  • Age-specific fertility distribution by calendar year
  • Total Fertility Rate (TFR) by calendar year
  • Sex ratio by calendar year

3.4.2. Code

####################################################################################################
#
#  DYNAMIS-POP Parameter Generation File 4 - 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_basefertility, "w")

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

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

cat("//EN Sex Ratio\ndouble SexRatio[SIM_YEAR_RANGE] = {(101) ",g_sexratio," };\n\n", file=parafile, append=TRUE)

cat("//EN Total Fertility Rate\ndouble	TotalFertilityRate[SIM_YEAR_RANGE] = {\n", file=parafile, append=TRUE)
cat(dp_tfr_dat, file=parafile, sep=", ", append=TRUE)
cat("\n};\n\n", file=parafile, append=TRUE)

cat("//EN Fertility Age Distribution\ndouble AgeSpecificFertility[FERTILE_AGE_RANGE][SIM_YEAR_RANGE] = {\n", file=parafile, append=TRUE)
cat(dp_fertility_dat, file=parafile, sep=", ", append=TRUE)
cat("\n};\n\n", file=parafile, append=TRUE)

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