Reading of PNAD 2016 data

1

When reading Pnad 2016, I ran the code below in r studio

# Ler o dicionário de variáveis com as posições
#devtools::install_github("tidyverse/readr")

library(readxl)
library(dplyr)
library(readr)

dic = read_xls("dicionario_das_variaveis_PNAD_Continua_microdados.xls", 
skip=4, 
           col_names = F)
dic = dic %>% select(1:3) %>% na.omit
dic$inicio = as.integer(dic$inicio)
names(dic) = c("inicio", "tamanho", "nome")
dic

# Lendo a PNAD
# Primeiro, vamos definir um objeto com o formato das variáveis de interesse
 ?read_fwf
 posicoes = fwf_positions(start = dic$inicio, end = dic$inicio + (dic$tamanho - 1),
                     col_names = dic$nome)
posicoes$begin = posicoes$begin + 1

pnad16.1 = read_fwf("PNADC_012016_20180816.txt", col_positions = posicoes)

But in the end, the program does not run and displays the error:

Error in guess_types_(datasource, tokenizer, locale, n = guess_max) : 
Begin offset (5) must be smaller than end offset (5)

Thanks for the help !!

    
asked by anonymous 20.11.2018 / 01:06

1 answer

1

There is a package designed to make it easier to download and read microdata from Brazil. The package is named microdadosBrasil and is not yet in CRAN. To download it run:

# Precisa ter o pacote devtools instalado
devtools::install_github("lucasmation/microdadosBrasil")

Using this packet to read data from the PNAD Continuous 2016 is as difficult as:

library(microdadosBrasil)
download_sourceData("PnadContinua", "2016-anual-1v", unzip = TRUE)
pessoas <- read_PNADcontinua("pessoas", "2016-anual-1v")
head(names(pessoas))
  

[1] "Year" "Quarter" "UF" "Capital" "RM_RIDE" "UPA"

For more package options see the documentation for the ?read_PNADcontinua function, or visit the project README, available at English or Portuguese (a little outdated).

p>     
23.11.2018 / 13:07