- Censo 2010
- Don't use R? See: using the package from Stata and Python
- vignettes and Portuguese documentation
- RAIS and CAGED (public versions) , PNAD_Continua
- Censo 1991, PNADs before 2001
- Support for data not fitting into memory.
IN near the future:
- variable name harmonization
this package contains functions to read most commonly used Brazilian microdata easily and quickly. Importing these microdata can be tedious. Most data is provided in fixed width files (fwf) with import instructions only for SAS and SPSS. The Data sometimes comes subdivided into serveral files, by state or macro regions. Also, it is common for file and variable names of the same dataset to vary overtime. microdadoBrasil
handles all these idiosyncrasies for you. In the background the package is running readr
for fwf data and data.table
for .csv data. Therefore reading is reasonably fast.
Currently the package includes import functions for:
Source | Dataset | Import_function | Period | Subdataset |
---|---|---|---|---|
IBGE | PNAD | read_PNAD | 2001 to 2014 | domicilios, pessoas |
IBGE | Censo Demográfico | read_CENSO | 2000 | domicilios, pessoas |
IBGE | PME | read_PME | 2002.01 to 2015.12 | vinculos |
IBGE | POF | read_POF | 2008 | several, see details |
INEP | Censo Escolar | read_CensoEscolar | 1995 to 2014 | escolas, ..., see details |
INEP | Censo da Educ. Superior | read_CensoEducacaoSuperior | 1995 to 2014 | see details |
MTE | CAGED | read_CAGED | 2009.01 to 2016.05 | vinculos |
MTE | RAIS | read_RAIS | 1998 to 2014 | estabelecimentos,vinculos |
For the datasets in fwf format, the package includes, internally, a list of import dictionaries. These were constructed with the import_SASdictionary
function, which users can use to import dictionaries from datasets not included here. Import dictionaries for the datasets included in the package can be accessed with the get_import_dictionary
function.
The package also harmonizes folder names, folder structure and file name that change overtime through a metadata table.It also unifies data that comes subdivides by regional subgroups (UF or região) into a single data object.
install.packages("devtools")
install.packages("stringi")
devtools::install_github("lucasmation/microdadosBrasil")
library('microdadosBrasil')
##############
# Censo Demográfico 2000
download_sourceData("CENSO", 2000, unzip = T)
d <- read_CENSO('domicilios',2000)
d <- read_CENSO('pessoas',2000)
#To import data from a specific path in your machine use:
d <- read_CENSO('domicilios',2000, root_path ="C:/....")
#To restrict the import to only one State use:
d <- read_CENSO('pessoas',2000, UF = "DF")
##############
# PNAD 2002
download_sourceData("PNAD", 2002, unzip = T)
d <- read_PNAD("domicilios", 2002)
d2 <- read_PNAD("pessoas", 2002)
##############
# Censo Escolar
download_sourceData('CensoEscolar', 2005, unzip=T)
d <- read_CensoEscolar('escola',2005)
d <- read_CensoEscolar('escola',2005,harmonize_varnames=T)
##############
#RAIS
#It will download files for all states and the selected year
download_sourceData("RAIS", i = "2000")
#To import data from all UFs in a single data.frame
d<- read_RAIS('vinculos', i = 2000)
#To import data from a selected group of UFs
d<- read_RAIS('vinculos', i = 2000, UF = c("DF","GO"))
##############
#PME
#It will download files for all months and the selected year:
download_sourceData("PME", i = "2012.01")
#'Period' argument should with quotes and formated as "YYYY.MM"
d <- read_PME("vinculos", "2012.01")
This package is highly influenced by similar efforts, which are great time savers, vastly used and often unrecognized:
- Anthony Damico's scripts to read most IBGE surveys. Great if you your data does not fit into memory and you want speed when working with complex survey design data.
- Data Zoom by Gustavo Gonzaga, Cláudio Ferraz and Juliano Assunção. Similar ease of use and harmonization of Brazilian microdada for Stata.
- dicionariosIBGE, by Alexandre Rademaker. A set of data.frames containing the information from SAS import dictionaries for IBGE datasets.
- IPUMS. Harmonization of Census data from several countries, including Brasil. Import functions for R, Stata, SAS and SPSS.
microdadosBrasil
differs from those packages in that it:
- updates import functions to more recent years
- includes non-IBGE data, such as INEP Education Census and MTE RAIS (de-identified)
- separates import code from dataset specific metadata, as explained bellow.
Nowadays packages are normally provided on-line (or in a physical CD for the older IBGE publications) as .zip files with the following structure:
dataset_year.zip
- dataset_year
- DICTIONARIES
- import_dictionary_subdatasetA.SAS
- DATA
- subdatasetA_state1.txt
- subdatasetA_state2.txt
- ...
- subdatasetA_stateN.txt
- ADITIONAL DOCUMENTATION
- subdatasetA_variables_and_cathegories_dictionary.xls
- DICTIONARIES
Users then normally manually reconstruct the import dictionaries in R by hand. Then, using this dictionary, run the import function, pointing to the DATA folder. Larger datasets (such as CENSUS or RAIS) come subdivided by state (or region), so the function must be repeated for all states. Then if the user needs more than one year of the dataset, the user repeats all the above, adjuting for changes fine and folder names.
(soon)
The main design principle was separating details of each dataset in each year - such as folder structure, data files and import dictionaries of the of original data - into metadata tables (saved as csv files at the extdata
folder). The elements in these tables, along with list of import dictionaries extracted from the SAS import instructions from the data provider, serve as parameters to import a dataset for a specific year. This separation of dataset specific details from the actual code makes code short and easier to extend to new packages.
ergonomics over speed (develop)