Package 'PNDSIBGE'

Title: Downloading, Reading and Analyzing PNDS Microdata - Package in Development
Description: Provides tools for downloading, reading and analyzing the National Survey of Demographic and Health - PNDS, 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: Gabriel Assuncao [aut, cre], Luna Hidalgo [aut], Douglas Braga [ctb], Viviane Quintaes [ctb]
Maintainer: Gabriel Assuncao <[email protected]>
License: GPL-3
Version: 0.1.1
Built: 2025-02-27 03:00:56 UTC
Source: https://github.com/gabriel-assuncao/pndsibge

Help Index


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

Description

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

Usage

get_pnds(
  year,
  section = "Female",
  vars = 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 equal to 2023. Vector not accepted.

section

Argument corresponding to which section of the questionnaire will be obtained, being able to receive only the values of "Female" or "Male", the writing of the value must be identical to the indicated value. Default is to use the "Female" section of the questionnaire.

vars

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

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 PNDS 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/saude/9160-pesquisa-nacional-de-demografia-e-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

read_pnds for reading PNDS microdata.
pnds_labeller for labeling categorical variables from PNDS microdata.
pnds_deflator for adding deflator variables to PNDS microdata.
pnds_design for creating PNDS survey design object.
pnds_example for getting the path of the PNDS toy example files.

Examples

pnds.svy <- get_pnds(year=2023, section="Female", vars=c("J007","J009"),
                       labels=TRUE, deflator=TRUE, design=TRUE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating proportion of people diagnosed with chronic diseases
if (!is.null(pnds.svy)) survey::svymean(x=~J007, design=pnds.svy, na.rm=TRUE)
pnds.svy2 <- get_pnds(year=2023, section="Male", vars=c("N001","N00101"),
                       labels=TRUE, deflator=TRUE, design=TRUE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating proportion of people's self-rated health
if (!is.null(pnds.svy2)) survey::svymean(x=~N001, design=pnds.svy2, na.rm=TRUE)

Add deflator variables to PNDS microdata

Description

This function adds deflator variables to PNDS microdata. For deflation of income variables, the documentation provided through the following address must be used: ‘⁠https://ftp.ibge.gov.br/PNDS/Documentacao_Geral/PNDSIBGE_Deflator.pdf⁠’.

Usage

pnds_deflator(data_pnds, deflator.file)

Arguments

data_pnds

A tibble of PNDS microdata read with read_pnds function.

deflator.file

The deflator file for selected survey available on official website: (select the deflator zip file) - ‘⁠https://ftp.ibge.gov.br/PNDS/Documentacao_Geral/⁠’.

Value

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

Note

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

See Also

get_pnds for downloading, labeling, deflating and creating survey design object for PNDS microdata.
read_pnds for reading PNDS microdata.
pnds_labeller for labeling categorical variables from PNDS microdata.
pnds_design for creating PNDS survey design object.
pnds_example for getting the path of the PNDS toy example files.

Examples

# Using data read from disk
input_path <- pnds_example(path="input_example.txt")
data_path <- pnds_example(path="exampledata.txt")
dictionary.path <- pnds_example(path="dictionaryexample.xls")
deflator.path <- pnds_example(path="deflatorexample.xls")
pnds.df <- read_pnds(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pnds.df <- pnds.df[(pnds.df$M001 == "1" & !is.na(pnds.df$M001)),]
pnds.df <- pnds.df[,!(names(pnds.df) %in% c("V0029", "V00291", "V00292", "V00293"))]
pnds.df <- pnds_labeller(data_pnds=pnds.df, dictionary.file=dictionary.path)
pnds.df <- pnds_deflator(data_pnds=pnds.df, deflator.file=deflator.path)

# Downloading data
pnds.df2 <- get_pnds(year=2023, section="Female", vars=c("J007","J009"),
                       labels=TRUE, deflator=FALSE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
deflator.path2 <- pnds_example(path="deflatorexample.xls")
pnds.df2 <- pnds_deflator(data_pnds=pnds.df2, deflator.file=deflator.path2)

Create PNDS survey object with its sample design

Description

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

Usage

pnds_design(data_pnds)

Arguments

data_pnds

A tibble of PNDS microdata read with read_pnds function.

Value

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

Note

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

See Also

get_pnds for downloading, labeling, deflating and creating survey design object for PNDS microdata.
read_pnds for reading PNDS microdata.
pnds_labeller for labeling categorical variables from PNDS microdata.
pnds_deflator for adding deflator variables to PNDS microdata.
pnds_example for getting the path of the PNDS toy example files.

Examples

# Using data read from disk
input_path <- pnds_example(path="input_example.txt")
data_path <- pnds_example(path="exampledata.txt")
dictionary.path <- pnds_example(path="dictionaryexample.xls")
deflator.path <- pnds_example(path="deflatorexample.xls")
pnds.df <- read_pnds(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pnds.df <- pnds.df[(pnds.df$M001 == "1" & !is.na(pnds.df$M001)),]
pnds.df <- pnds.df[,!(names(pnds.df) %in% c("V0029", "V00291", "V00292", "V00293"))]
pnds.df <- pnds_labeller(data_pnds=pnds.df, dictionary.file=dictionary.path)
pnds.df <- pnds_deflator(data_pnds=pnds.df, deflator.file=deflator.path)

pnds.svy <- pnds_design(data_pnds=pnds.df)
# Calculating proportion of people diagnosed with chronic diseases
if (!is.null(pnds.svy)) survey::svymean(x=~J007, design=pnds.svy, na.rm=TRUE)

# Downloading data
pnds.df2 <- get_pnds(year=2023, section="Female", vars=c("J007","J009"),
                       labels=TRUE, deflator=TRUE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
pnds.svy2 <- pnds_design(data_pnds=pnds.df2)
# Calculating proportion of people diagnosed with chronic diseases
if (!is.null(pnds.svy2)) survey::svymean(x=~J007, design=pnds.svy2, na.rm=TRUE)

Get the path of the PNDS toy example files

Description

This function provides the path of the microdata from year 2023 of the PNDS toy example files, loaded with this package.

Usage

pnds_example(path = NULL)

Arguments

path

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

Value

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

Note

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

See Also

get_pnds for downloading, labeling, deflating and creating survey design object for PNDS microdata.
read_pnds for reading PNDS microdata.
pnds_labeller for labeling categorical variables from PNDS microdata.
pnds_deflator for adding deflator variables to PNDS microdata.
pnds_design for creating PNDS survey design object.

Examples

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

Label categorical variables from PNDS microdata

Description

This function labels categorical variables from PNDS microdata.

Usage

pnds_labeller(data_pnds, dictionary.file)

Arguments

data_pnds

A tibble of PNDS microdata read with read_pnds function.

dictionary.file

The dictionary file for selected survey available on official website: (select the dictionary and input zip file, according to the appropriated year, microdata folder and then, inside, documentation) - ‘⁠https://ftp.ibge.gov.br/PNDS/⁠’.

Value

A tibble with the data provided from PNDS 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/saude/9160-pesquisa-nacional-de-demografia-e-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnds for downloading, labeling, deflating and creating survey design object for PNDS microdata.
read_pnds for reading PNDS microdata.
pnds_deflator for adding deflator variables to PNDS microdata.
pnds_design for creating PNDS survey design object.
pnds_example for getting the path of the PNDS toy example files.

Examples

# Using data read from disk
input_path <- pnds_example(path="input_example.txt")
data_path <- pnds_example(path="exampledata.txt")
dictionary.path <- pnds_example(path="dictionaryexample.xls")
pnds.df <- read_pnds(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pnds.df <- pnds.df[(pnds.df$M001 == "1" & !is.na(pnds.df$M001)),]
pnds.df <- pnds.df[,!(names(pnds.df) %in% c("V0029", "V00291", "V00292", "V00293"))]
pnds.df <- pnds_labeller(data_pnds=pnds.df, dictionary.file=dictionary.path)

# Downloading data
pnds.df2 <- get_pnds(year=2023, section="Female", vars=c("J007","J009"),
                       labels=FALSE, deflator=FALSE, design=FALSE,
                       reload=TRUE, curlopts=list(), savedir=tempdir())
dictionary.path2 <- pnds_example(path="dictionaryexample.xls")
pnds.df2 <- pnds_labeller(data_pnds=pnds.df2, dictionary.file=dictionary.path2)

Read PNDS microdata

Description

This function reads PNDS microdata.

Usage

read_pnds(microdata, input_txt, vars = NULL)

Arguments

microdata

A text file containing microdata from PNDS survey, available on official website: (select a microdata file, according to the appropriated year, microdata folder and then, inside, data) - ‘⁠https://ftp.ibge.gov.br/PNDS/⁠’.

input_txt

A text file, related to the microdata, containing the input script for SAS, available on official website: (select the dictionary and input zip file, according to the appropriated year, microdata folder and then, inside, documentation) - ‘⁠https://ftp.ibge.gov.br/PNDS/⁠’.

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/saude/9160-pesquisa-nacional-de-demografia-e-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.

See Also

get_pnds for downloading, labeling, deflating and creating survey design object for PNDS microdata.
pnds_labeller for labeling categorical variables from PNDS microdata.
pnds_deflator for adding deflator variables to PNDS microdata.
pnds_design for creating PNDS survey design object.
pnds_example for getting the path of the PNDS toy example files.

Examples

input_path <- pnds_example(path="input_example.txt")
data_path <- pnds_example(path="exampledata.txt")
pnds.df <- read_pnds(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pnds.df <- pnds.df[(pnds.df$M001 == "1" & !is.na(pnds.df$M001)),]
pnds.df <- pnds.df[,!(names(pnds.df) %in% c("V0029", "V00291", "V00292", "V00293"))]