Skip to content

Commit

Permalink
Population estimates for specific age groups
Browse files Browse the repository at this point in the history
  • Loading branch information
odeleongt committed May 17, 2017
2 parents ec73b93 + c352c18 commit c8c4386
Show file tree
Hide file tree
Showing 7 changed files with 621 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ data/raw/*
*.xls*
*.RData
*.rds

# Ignore output
output/
1 change: 1 addition & 0 deletions lastest-prerelease
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.0.1
Empty file added output/.gitkeep
Empty file.
43 changes: 33 additions & 10 deletions scripts/collect-raw-municipality.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ file.remove(file_list)


#------------------------------------------------------------------------------*
# Collect data from 2000-2010 period ----
# Collect data from 2011-2015 period ----
#------------------------------------------------------------------------------*

# Zip path
Expand Down Expand Up @@ -178,20 +178,40 @@ read_population_2011 <- function(file_path, skip = 3){
# Report sheet (year)
cat(" ", sheet)

fixes <- c(

#--------------------------------------------------------------------------*
# Fix parameters for specific files / sheets
#--------------------------------------------------------------------------*

# Fix individual skip parameters
fixes_skip <- c(
"Totonicapan", "Suchitepequez", "Retalhuleu", "Quiche", "Alta Verapaz",
"Peten", "Jutiapa", " Jalapa", "Chiquimula", "Izabal", "Santa Rosa"
)

# Configuration exceptions
skip <- case_when(
# department == "Santa Rosa" & sheet == "2012" ~ 4,
# department == "Santa Rosa" & sheet == "2015" ~ 5,
department %in% fixes & sheet == "2012" ~ 4,
department %in% fixes & sheet == "2015" ~ 5,
department %in% fixes_skip & sheet == "2012" ~ 4,
department %in% fixes_skip & sheet == "2015" ~ 5,
TRUE ~ skip
)

# Fix missing municipality names
fix_municipalities <- function(.data){
.data %>%
# Setup fixing rules
mutate(
municipality = case_when(
department == "Santa Rosa" & grepl("^X", municipality) ~ "Nueva Santa Rosa",
TRUE ~ municipality
)
) %>%
return()
}

#--------------------------------------------------------------------------*
# Get data
#--------------------------------------------------------------------------*

# Read file contents
pop_sheet <- read_excel(
path = file, sheet = sheet, skip = skip_lines , na = "?"
Expand Down Expand Up @@ -230,6 +250,8 @@ read_population_2011 <- function(file_path, skip = 3){
),
department = department
) %>%
# Fix missingmunicipality names
fix_municipalities() %>%
select(year, department, municipality, sex = sexo, age, population) %>%
mutate(
# Fix factors
Expand Down Expand Up @@ -568,12 +590,13 @@ pop_2016_2020 <- pop_2016_2020_predicted %>%
population <- pop_2000_2015 %>%
bind_rows(pop_2016_2020)

processed_file <- "data/processed/gt_2000_2020_municipality_population.RData"

# Save population data for use in R
save(
population, file = "data/processed/gt_2000_2020_municipality_population.RData"
population, file = processed_file
)



cat(processed_file)

# End of script
Loading

0 comments on commit c8c4386

Please sign in to comment.