Last active
May 23, 2020 23:39
-
-
Save fernandobarbalho/b2064227ed750cb8870215c2c00831fe to your computer and use it in GitHub Desktop.
Função para baixar dados de todas ufs para o sistema SIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#para essa função usa-se o pacote microdatasus | |
# SALDANHA, Raphael de Freitas; BASTOS, Ronaldo Rocha; BARCELLOS, Christovam. Microdatasus: pacote para download e pré-processamento de microdados do Departamento de Informática do SUS (DATASUS). Cad. Saúde Pública, Rio de Janeiro , v. 35, n. 9, e00032419, 2019 . Available from http://ref.scielo.org/dhcq3y. | |
process_SIM_all_fu<- function(a_year_start, a_year_end){ | |
library(microdatasus) | |
library(dplyr) | |
library(purrr) | |
library(readr) | |
#TAbela com dados de municípios do IBGE no seguinte formato | |
#names(IBGE) | |
#"uf" "cod_uf" "cod_mun" "nome_municipio" "pop_estimada" | |
#Pode ser substituída por um vetor com as siglas das UFs. | |
#Fica aqui a sugestão desse tipo de tabela para algum desdobramento posterior da função, | |
#tal como tratamento demográfico ou foco em municípios | |
IBGE <- read_delim("IBGE.csv", ";", escape_double = FALSE, | |
locale = locale(encoding = "LATIN1"), | |
trim_ws = TRUE) | |
ufs<- | |
IBGE%>% | |
filter(!is.na(cod_uf)) %>% | |
distinct(uf) | |
map_dfr(ufs$uf, function(a_uf){ | |
dados <- fetch_datasus(year_start = a_year_start, year_end = a_year_end, uf = a_uf, information_system = "SIM-DO") | |
dados <- process_sim(dados) | |
dados | |
}) | |
} | |
#Exemplo de uso | |
df_2018_SIM_all<- process_SIM_all_fu(2018,2018) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment