Giter Site home page Giter Site logo

tbrugz / ribge Goto Github PK

View Code? Open in Web Editor NEW
55.0 9.0 14.0 786 KB

R package for (down)loading data from IBGE (Instituto Brasileiro de Geografia e Estatística)

License: GNU General Public License v3.0

R 100.00%
ibge r opendata dados-abertos ipea ipeadata tse

ribge's Introduction

ribge R package

R package for (down)loading data from IBGE (Instituto Brasileiro de Geografia e Estatística)

data: population

Yearly population for municipalities. See: Estimativas de População & estatísticas/Estimativas de Populacao (or ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/)

2007 data comes from Contegem da população: see https://www.ibge.gov.br/estatisticas/sociais/populacao/9065-contagem-da-populacao.html

2010 Census data gathered from: http://www.sidra.ibge.gov.br/bda/tabela/listabl.asp?z=t&o=25&i=P&c=1378

years avaiable: 2000-2022

see doc/populacao_sources.csv

data: GDP (gross domestic product) / PIB (produto interno bruto)

Municipalities GDP. See: Produto Interno Bruto dos Municípios

years avaiable: 1999-2021

data: cartography/territory

Municipalities area. See: Geociências » Organização do território » Estrutura territorial » Áreas Territoriais

years avaiable: 2015, 2020

data: price indexes & GDP deflator

INPC index. See: Índice de preços » INPC - Índice Nacional de Preços ao Consumidor

years avaiable: 1991+

IPCA index. See: Índice de preços » IPCA - Índice Nacional de Preços ao Consumidor Amplo

years avaiable: 1991+

SINAPI construction price index. See: Sistema Nacional de Pesquisa de Custos e Índices da Construção Civil & índice de preços » índices da construção civil

years avaiable: 1986+

GDP deflator. See: sistema de contas nacionais » contas nacionais

years avaiable: 1948+

statistical series API (series estatísticas)

Generic functions to gather data from Séries Históricas e Estatísticas website.

See avaiable series codes on doc/seriesEstatisticas.md.

municipalities codes: ibge/tse mapping

Mapping between IBGE's & TSE's municipalities names and codes.

Also avaiable as CSV file: IBGE vs TSE municipalities mapping.

See also TSE's municipalities csv file and TSE's municipalities with zones csv file

IPEA's & BCB's series (non-IBGE)

Function to gather data from Ipeadata

Function to gather data from BCB's Time Series Management System

install & load

# install.packages("devtools")
devtools::install_github("tbrugz/ribge")
library(ribge)

build from sources & load

# install.packages("devtools")
devtools::install_deps(".")
devtools::install(".")
library(ribge)

usage examples

population, main usage:

pop2000 <- populacao_municipios(2000)
# ...
pop2007 <- populacao_municipios(2007)
pop2008 <- populacao_municipios(2008)
pop2009 <- populacao_municipios(2009)
pop2010 <- populacao_municipios(2010)
pop2011 <- populacao_municipios(2011, dir="/tmp")
# ...
pop2021 <- populacao_municipios(2021)
pop2022 <- populacao_municipios(2022)

GDP (PIB) example:

# 18 variables
pib1999 <- pib_municipios(1999)
# ...
pib2009 <- pib_municipios(2009)

# 43 variables
pib2010 <- pib_municipios(2010)
# ...
pib2021 <- pib_municipios(2021)

inflation & GDP deflator:

inpc2015 <- precos_inpc(2015)
ipca2015 <- precos_ipca(2015)
sinapi2015 <- precos_sinapi(2015)
deflatorpib <- precos_deflatorpib()

municipalities area:

munArea <- area_municipios()              # defaults to 2020
munArea <- area_municipios(ano = 2015)

Gathering data from "séries estatísticas" (statistical series website):

# Efetivo dos rebanhos por tipo de rebanho
df <- series_estatisticas_carrega("PPM01_BR_ABS")
# Docentes com curso superior no ensino médio, rede pública e privada
df <- series_estatisticas_carrega("SEE10_BR_PERC", transpose = T)
# Taxa de desocupação das pessoas de 10 anos ou mais de idade, por sexo - todas localidades
df <- series_estatisticas_carrega_todas_localidades("PE62_RM_PERC", transpose = T)

# Ver `seriesEstatisticas` para prefixos de códigos:
seriesEstatisticas
View(seriesEstatisticas)

TSE municipalities:

tsemun <- tse_municipios()
# mapping between ibge & tse municipalities codes
data("municipioIbgeTseMap")

Ipeadata series:

# series 37667: real minimum wage / salário mínimo real
df <- ipea_serie_carrega(37667)

Brazil's central bank (BCB) series:

# series 193: Fipe IPC price index / Índice de Preços ao Consumidor da Fipe
df <- bcb_serie_carrega(193)

end notes

license: GPL-3

ribge's People

Contributors

tbrugz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ribge's Issues

Error in R 3.4

devtools::install_github("tbrugz/ribge")
Downloading GitHub repo tbrugz/ribge@master
from URL https://api.github.com/repos/tbrugz/ribge/zipball/master
Installing ribge
Installing 1 package: dplyr
Installing package into ‘C:/Users/Adilson/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/dplyr_0.7.2.zip'
Content type 'application/zip' length 2881035 bytes (2.7 MB)
downloaded 2.7 MB

package ‘dplyr’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘dplyr’

The downloaded binary packages are in
C:\Users\Adilson\AppData\Local\Temp\RtmpEZLxJA\downloaded_packages
"C:/PROGRA~1/R/R-3.4.0/bin/x64/R" --no-site-file --no-environ
--no-save --no-restore --quiet CMD INSTALL
"C:/Users/Adilson/AppData/Local/Temp/RtmpEZLxJA/devtoolsc84282d1c85/tbrugz-ribge-ef8ce06"
--library="C:/Users/Adilson/Documents/R/win-library/3.4"
--install-tests

ERROR: dependency 'dplyr' is not available for package 'ribge'

  • removing 'C:/Users/Adilson/Documents/R/win-library/3.4/ribge'
    Installation failed: Command failed (1)

Error in download.file(url, filename_download) : não foi possível abrir a URL ....

Olá! Muito interessante e útil este pacote! Obrigado por disponibilizar!

Entretanto, não estou conseguindo baixar os dados. Consegui apenas a população de 2010.

Quando tento baixar o PIB, tenho esse erro:

> pib2010 <- pib_municipios(2010)
tentando a URL 'ftp://ftp.ibge.gov.br/Pib_Municipios/2017/base/base_de_dados_2010_2017_xls.zip'
Error in download.file(url, filename_download) : 
  não foi possível abrir a URL 'ftp://ftp.ibge.gov.br/Pib_Municipios/2017/base/base_de_dados_2010_2017_xls.zip'
Além disso: Warning message:
In download.file(url, filename_download) :
  cannot open URL 'ftp://ftp.ibge.gov.br/Pib_Municipios/2017/base/base_de_dados_2010_2017_xls.zip': FTP status was '500 Unknown Error'

E quando eu tento baixar a população (diferente de 2010) , eu tenho:

> pop2012  <- populacao_municipios(2012)
tentando a URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2012/estimativa_2012_DOU_28_08_2012_xls.zip'
Error in download.file(url, filename_download) : 
  não foi possível abrir a URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2012/estimativa_2012_DOU_28_08_2012_xls.zip'
Além disso: Warning message:
In download.file(url, filename_download) :
  cannot open URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2012/estimativa_2012_DOU_28_08_2012_xls.zip': FTP status was '500 Unknown Error'

> pop2020 <- populacao_municipios(2020)
tentando a URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2020/estimativa_dou_2020.xls'
Error in download.file(url, filename_download) : 
  não foi possível abrir a URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2020/estimativa_dou_2020.xls'
Além disso: Warning message:
In download.file(url, filename_download) :
  cannot open URL 'ftp://ftp.ibge.gov.br/Estimativas_de_Populacao/Estimativas_2020/estimativa_dou_2020.xls': FTP status was '500 Unknown Error'

Penso que talvez o IBGE tenha mudado dos links de acesso, não sei.

Aproveitando, conhecem algum pacote que ajude a pegar dados do TabNet? (http://tabnet.datasus.gov.br/cgi/deftohtm.exe?popsvs/cnv/popbr.def)

Obrigado.

precos_ipca - missing information

Hi,

Using "precos_ipca" funcion, for 2006 year, we get only first 6 months.

Looking up the code,

precos_ipca <- function(ano, dir=NULL) {
if(ano<1991) {
stop(paste("data not avaiable for year",ano))
}
resource <- ifelse(ano<=1999, "IA47_BR_PERC",
ifelse(ano<=2006, "IA48_BR_PERC",
ifelse(ano<=2011, "IA55_BR_PERC",
"IA59_BR_PERC")))

FIXME: what about boundary years (1999 & 2006)? (2011/2012 is not a problem...)

file <- util.downloadSeries(resource, dir = dir)

loc <- readr::locale(decimal_mark = ",")
df <- readr::read_tsv(file, locale = loc)
#return(df)
df <- inflacao.transform.df(df)
df[df$ano==ano,]
}

one half of 2006 is inside "IA48_BR_PERC" file and the other is inside "IA55_BR_PERC" file. Same issue with 1999. Indeed, there is an observation in the code about that.

Is it possible to solve that? (maybe intersecting boundaries in the code)

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.