Reading data from PNAD 2016

Asked

Viewed 304 times

3

When reading the Pnad 2016, I executed 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 presents the error:

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

I appreciate help!!

  • Danielle, the dictionary you are using may not be from this PNAD report. Try downloading the dictionary from the same address you downloaded Pnad. https://servicodados.ibge.gov.br/download/DownloadArvore.aspx?f=1&camio=Trabalho_e_Rendimento/Pesquisa_nacional_por_amostra_de_domicilios_continua/Trimestral/Microdados/2016

1 answer

3

There is a package created to facilitate the download and reading of microdata from Brazil. The package is called microdadosBrasil and still not in the CRAN. To lower it rotate:

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

Using this package reading the 2016 Continuous PNAD data 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 function documentation?read_PNADcontinua, or visit the README of the project, available at english or in portuguese (a little outdated).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.