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 |
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.
get_pnds( year, section = "Female", vars = NULL, labels = TRUE, deflator = TRUE, design = TRUE, reload = TRUE, curlopts = list(), savedir = tempdir() )
get_pnds( year, section = "Female", vars = NULL, labels = TRUE, deflator = TRUE, design = TRUE, reload = TRUE, curlopts = list(), savedir = tempdir() )
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 |
deflator |
Logical value. If |
design |
Logical value. If |
reload |
Logical value. If |
curlopts |
A named list object identifying the curl options for the handle when using functions from |
savedir |
Directory to save the downloaded data. Default is to use a temporary directory. |
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.
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.
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.
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)
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)
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’.
pnds_deflator(data_pnds, deflator.file)
pnds_deflator(data_pnds, deflator.file)
data_pnds |
A tibble of PNDS microdata read with |
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/’. |
A tibble with the data provided from PNDS survey and the deflator variables added for use.
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.
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.
# 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)
# 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)
This function creates PNDS survey object with its sample design for analysis using survey
package functions.
pnds_design(data_pnds)
pnds_design(data_pnds)
data_pnds |
A tibble of PNDS microdata read with |
An object of class survey.design
or svyrep.design
with the data from PNDS and its sample design.
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.
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.
# 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)
# 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)
This function provides the path of the microdata from year 2023 of the PNDS toy example files, loaded with this package.
pnds_example(path = NULL)
pnds_example(path = NULL)
path |
Name of file. If |
A vector with names of all the available PNDS toy example files or the path for specific requested PNDS toy example file.
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.
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.
pnds_example() pnds_example(path="exampledata.txt") pnds_example(path="input_example.txt") pnds_example(path="dictionaryexample.xls") pnds_example(path="deflatorexample.xls")
pnds_example() pnds_example(path="exampledata.txt") pnds_example(path="input_example.txt") pnds_example(path="dictionaryexample.xls") pnds_example(path="deflatorexample.xls")
This function labels categorical variables from PNDS microdata.
pnds_labeller(data_pnds, dictionary.file)
pnds_labeller(data_pnds, dictionary.file)
data_pnds |
A tibble of PNDS microdata read with |
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/’. |
A tibble with the data provided from PNDS survey and its categorical variables as factors with related labels.
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.
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.
# 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)
# 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)
This function reads PNDS microdata.
read_pnds(microdata, input_txt, vars = NULL)
read_pnds(microdata, input_txt, vars = NULL)
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. |
A tibble with selected variables of the microdata, including the necessary survey design ones.
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.
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.
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"))]
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"))]