Package 'PNADcIBGE'

Title: Downloading, Reading and Analyzing PNADC Microdata
Description: Provides tools for downloading, reading and analyzing the Continuous National Household Sample Survey - PNADC, a household survey from Brazilian Institute of Geography and Statistics - IBGE. The data must be downloaded from the official website <https://www.ibge.gov.br/>. Further analysis must be made using package 'survey'.
Authors: Douglas Braga [aut], Gabriel Assuncao [aut, cre], Luna Hidalgo [ctb], Viviane Quintaes [ctb]
Maintainer: Gabriel Assuncao <[email protected]>
License: GPL-3
Version: 0.7.5
Built: 2025-03-28 04:06:08 UTC
Source: https://github.com/gabriel-assuncao/pnadcibge

Help Index


Download, label, deflate and create survey design object for PNADC microdata

Description

Core function of package. With this function only, the user can download a PNADC microdata from a year or quarter and get a sample design object ready to use with survey package functions.

Usage

get_pnadc(
  year,
  quarter = NULL,
  interview = NULL,
  topic = NULL,
  selected = FALSE,
  vars = NULL,
  defyear = NULL,
  defperiod = NULL,
  labels = TRUE,
  deflator = TRUE,
  design = TRUE,
  reload = TRUE,
  curlopts = list(),
  savedir = tempdir()
)

Arguments

year

The year of the data to be downloaded. Must be a number between 2012 and current year. Vector not accepted.

quarter

The quarter of the year of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. If NULL, interview or topic number must be provided.

interview

The interview number of the data to be downloaded. Must be number from 1 to 5. Vector not accepted. Using this option will get annual per interview data. If NULL, quarter or topic number must be provided.

topic

The quarter related to the topic of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. Using this option will get annual per topic data. If NULL, quarter or interview number must be provided.

selected

Logical value. If TRUE, the specific questionnaire for selected resident will be used. If FALSE, the basic questionnaire for household and residents will be used. For more information about these supplemental topics, please check the survey official website.

vars

Vector of variable names to be kept for analysis. Default is to keep all variables.

defyear

The year of the deflator data to be downloaded for annual microdata. Must be a number between 2017 and the last available year. Vector not accepted. If NULL, the deflator year will be defined as the last year available for interview microdata, or as equal to year for topic microdata. When quarter is defined, this argument will be ignored. This argument will be used only if deflator was set as TRUE.

defperiod

The quarter period of the deflator data to be downloaded for annual per topic microdata. Must be number from 1 to 4. Vector not accepted. If NULL, the deflator period will be defined as equal to topic. When quarter or interview is defined, this argument will be ignored. This argument will be used only if deflator was set as TRUE.

labels

Logical value. If TRUE, categorical variables will presented as factors with labels corresponding to the survey's dictionary.

deflator

Logical value. If TRUE, deflator variables will be available for use in the microdata.

design

Logical value. If TRUE, will return an object of class survey.design or svyrep.design. It is strongly recommended to keep this parameter as TRUE for further analysis. If FALSE, only the microdata will be returned.

reload

Logical value. If TRUE, will re-download the files even if they already exist in the save directory. If FALSE, will be checked if the files already exist in the save directory and the download will not be performed repeatedly, be careful with coinciding names of microdata files.

curlopts

A named list object identifying the curl options for the handle when using functions from RCurl package.

savedir

Directory to save the downloaded data. Default is to use a temporary directory.

Value

An object of class survey.design or svyrep.design with the data from PNADC and its sample design, or a tibble with selected variables of the microdata, including the necessary survey design ones.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

read_pnadc for reading PNADC microdata.
pnadc_labeller for labeling categorical variables from PNADC microdata.
pnadc_deflator for adding deflator variables to PNADC microdata.
pnadc_design for creating PNADC survey design object.
pnadc_example for getting the path of the quarter PNADC toy example files.

Examples

pnadc.svy <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"),
                       defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating proportion of employed and unemployed people
if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE)
pnadc.svy2 <- get_pnadc(year=2017, interview=5, selected=FALSE, vars=c("V4112","V4121B"),
                        defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE,
                        reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating average hours dedicated to the care of people or household chores
if (!is.null(pnadc.svy2)) survey::svymean(x=~V4121B, design=pnadc.svy2, na.rm=TRUE)
pnadc.svy3 <- get_pnadc(year=2017, topic=4, selected=FALSE, vars=c("S07006","S07007"),
                        defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE,
                        reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating proportion of cell phone for personal use with internet access
if (!is.null(pnadc.svy3)) survey::svymean(x=~S07007, design=pnadc.svy3, na.rm=TRUE)

Add deflator variables to PNADC microdata

Description

This function adds deflator variables to PNADC microdata. For deflation of income variables, the documentation provided through the following addresses must be used:
Quarter - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/PNADcIBGE_Deflator_Trimestral.pdf.
Annual per Interview - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/Documentacao_Geral/PNADcIBGE_Deflator_Anual_Visita.pdf.
Annual per Topic - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/Documentacao_Geral/PNADcIBGE_Deflator_Anual_Trimestre.pdf.

Usage

pnadc_deflator(data_pnadc, deflator.file)

Arguments

data_pnadc

A tibble of PNADC microdata read with read_pnadc function.

deflator.file

The deflator file for selected survey available on official website:
Quarter (select the deflator zip file) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/.
Annual per Interview (select a deflator xls file, according to the appropriated year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/Documentacao_Geral/.
Annual per Topic (select a deflator xls file, according to the appropriated period and, then, inside the documentation folder, choose the desired year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/.

Value

A tibble with the data provided from PNADC survey and the deflator variables added for use.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnadc for downloading, labeling, deflating and creating survey design object for PNADC microdata.
read_pnadc for reading PNADC microdata.
pnadc_labeller for labeling categorical variables from PNADC microdata.
pnadc_design for creating PNADC survey design object.
pnadc_example for getting the path of the quarter PNADC toy example files.

Examples

# Using data read from disk
input_path <- pnadc_example(path="input_example.txt")
data_path <- pnadc_example(path="exampledata.txt")
dictionary.path <- pnadc_example(path="dictionaryexample.xls")
deflator.path <- pnadc_example(path="deflatorexample.xls")
pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002"))
pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path)
pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path)

# Downloading data
pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"),
                       defyear=2017, defperiod=4, labels=TRUE, deflator=FALSE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
deflator.path2 <- pnadc_example(path="deflatorexample.xls")
pnadc.df2 <- pnadc_deflator(data_pnadc=pnadc.df2, deflator.file=deflator.path2)

Create PNADC survey object with its sample design

Description

This function creates PNADC survey object with its sample design for analysis using survey package functions.

Usage

pnadc_design(data_pnadc)

Arguments

data_pnadc

A tibble of PNADC microdata read with read_pnadc function.

Value

An object of class survey.design or svyrep.design with the data from PNADC and its sample design.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnadc for downloading, labeling, deflating and creating survey design object for PNADC microdata.
read_pnadc for reading PNADC microdata.
pnadc_labeller for labeling categorical variables from PNADC microdata.
pnadc_deflator for adding deflator variables to PNADC microdata.
pnadc_example for getting the path of the quarter PNADC toy example files.

Examples

# Using data read from disk
input_path <- pnadc_example(path="input_example.txt")
data_path <- pnadc_example(path="exampledata.txt")
dictionary.path <- pnadc_example(path="dictionaryexample.xls")
deflator.path <- pnadc_example(path="deflatorexample.xls")
pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002"))
pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path)
pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path)

pnadc.svy <- pnadc_design(data_pnadc=pnadc.df)
# Calculating proportion of employed and unemployed people
if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE)

# Downloading data
pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"),
                       defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
pnadc.svy2 <- pnadc_design(data_pnadc=pnadc.df2)
# Calculating proportion of employed and unemployed people
if (!is.null(pnadc.svy2)) survey::svymean(x=~VD4002, design=pnadc.svy2, na.rm=TRUE)

Get the path of the quarter PNADC toy example files

Description

This function provides the path of the microdata from quarter 4 of year 2017 of the PNADC toy example files, loaded with this package.

Usage

pnadc_example(path = NULL)

Arguments

path

Name of file. If NULL, the quarter PNADC toy example files names will be listed.

Value

A vector with names of all the available quarter PNADC toy example files or the path for specific requested quarter PNADC toy example file.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnadc for downloading, labeling, deflating and creating survey design object for PNADC microdata.
read_pnadc for reading PNADC microdata.
pnadc_labeller for labeling categorical variables from PNADC microdata.
pnadc_deflator for adding deflator variables to PNADC microdata.
pnadc_design for creating PNADC survey design object.

Examples

pnadc_example()
pnadc_example(path="exampledata.txt")
pnadc_example(path="input_example.txt")
pnadc_example(path="dictionaryexample.xls")
pnadc_example(path="deflatorexample.xls")

Label categorical variables from PNADC microdata

Description

This function labels categorical variables from PNADC microdata.

Usage

pnadc_labeller(data_pnadc, dictionary.file)

Arguments

data_pnadc

A tibble of PNADC microdata read with read_pnadc function.

dictionary.file

The dictionary file for selected survey available on official website:
Quarter (select the dictionary and input zip file) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/.
Annual per Interview (select a dictionary xls file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/.
Annual per Topic (select a dictionary xls file, according to the appropriated quarter related to the topic, inside the documentation folder) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/.

Value

A tibble with the data provided from PNADC survey and its categorical variables as factors with related labels.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnadc for downloading, labeling, deflating and creating survey design object for PNADC microdata.
read_pnadc for reading PNADC microdata.
pnadc_deflator for adding deflator variables to PNADC microdata.
pnadc_design for creating PNADC survey design object.
pnadc_example for getting the path of the quarter PNADC toy example files.

Examples

# Using data read from disk
input_path <- pnadc_example(path="input_example.txt")
data_path <- pnadc_example(path="exampledata.txt")
dictionary.path <- pnadc_example(path="dictionaryexample.xls")
pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002"))
pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path)

# Downloading data
pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"),
                       defyear=2017, defperiod=4, labels=FALSE, deflator=FALSE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
dictionary.path2 <- pnadc_example(path="dictionaryexample.xls")
pnadc.df2 <- pnadc_labeller(data_pnadc=pnadc.df2, dictionary.file=dictionary.path2)

Read PNADC microdata

Description

This function reads PNADC microdata.

Usage

read_pnadc(microdata, input_txt, vars = NULL)

Arguments

microdata

A text file containing microdata from PNADC survey, available on official website:
Quarter (select a microdata file, according to the appropriated year and, then, quarter) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/.
Annual per Interview (select a microdata file, according to the appropriated interview and, then, inside the data folder, choose the desired year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/.
Annual per Topic (select a microdata file, according to the appropriated quarter related to the topic and, then, inside the data folder, choose the desired year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/.

input_txt

A text file, related to the microdata, containing the input script for SAS, available on official website:
Quarter (select the dictionary and input zip file) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/.
Annual per Interview (select a input txt file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/.
Annual per Topic (select a input txt file, according to the appropriated quarter related to the topic, inside the documentation folder) - https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/.

vars

Vector of variable names to be kept for analysis. Default is to keep all variables.

Value

A tibble with selected variables of the microdata, including the necessary survey design ones.

Note

For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnadc for downloading, labeling, deflating and creating survey design object for PNADC microdata.
pnadc_labeller for labeling categorical variables from PNADC microdata.
pnadc_deflator for adding deflator variables to PNADC microdata.
pnadc_design for creating PNADC survey design object.
pnadc_example for getting the path of the quarter PNADC toy example files.

Examples

input_path <- pnadc_example(path="input_example.txt")
data_path <- pnadc_example(path="exampledata.txt")
pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002"))