Type: | Package |
Title: | Downloading, Reading and Analyzing PNS Microdata |
Version: | 0.2.1 |
Description: | Provides tools for downloading, reading and analyzing the National Survey of Health - PNS, 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'. |
Depends: | R (≥ 3.2.0) |
Imports: | dplyr, httr, magrittr, projmgr, RCurl, readr, readxl, survey, tibble, timeDate, utils |
Suggests: | convey, SIPDIBGE, srvyr |
License: | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.1.2 |
NeedsCompilation: | no |
Author: | Gabriel Assuncao [aut, cre], Luna Hidalgo [aut], Douglas Braga [ctb], Viviane Quintaes [ctb] |
Maintainer: | Gabriel Assuncao <pacotesipd@ibge.gov.br> |
BugReports: | https://github.com/Gabriel-Assuncao/PNSIBGE/issues |
Packaged: | 2024-02-01 14:21:54 UTC; gabriel.assuncao |
Repository: | CRAN |
Date/Publication: | 2024-02-01 15:40:02 UTC |
Download, label, deflate and create survey design object for PNS microdata
Description
Core function of package. With this function only, the user can download a PNS microdata from a year and get a sample design object ready to use with survey
package functions.
Usage
get_pns(
year,
selected = FALSE,
anthropometry = FALSE,
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 2013 or 2019. Vector not accepted. |
selected |
Logical value. If |
anthropometry |
Logical value. If |
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. |
Value
An object of class survey.design
or svyrep.design
with the data from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
read_pns for reading PNS microdata.
pns_labeller for labeling categorical variables from PNS microdata.
pns_deflator for adding deflator variables to PNS microdata.
pns_design for creating PNS survey design object.
pns_example for getting the path of the PNS toy example files.
Examples
pns.svy <- get_pns(year=2019, selected=FALSE, anthropometry=FALSE, 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(pns.svy)) survey::svymean(x=~J007, design=pns.svy, na.rm=TRUE)
pns.svy2 <- get_pns(year=2019, selected=TRUE, anthropometry=FALSE, 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(pns.svy2)) survey::svymean(x=~N001, design=pns.svy2, na.rm=TRUE)
pns.svy3 <- get_pns(year=2019, selected=FALSE, anthropometry=TRUE, vars=c("W00101","W00201"),
labels=TRUE, deflator=TRUE, design=TRUE,
reload=TRUE, curlopts=list(), savedir=tempdir())
# Calculating the average weight of people
if (!is.null(pns.svy3)) survey::svymean(x=~W00101, design=pns.svy3, na.rm=TRUE)
Add deflator variables to PNS microdata
Description
This function adds deflator variables to PNS microdata. For deflation of income variables, the documentation provided through the following address must be used: https://ftp.ibge.gov.br/PNS/Documentacao_Geral/PNSIBGE_Deflator.pdf.
Usage
pns_deflator(data_pns, deflator.file)
Arguments
data_pns |
A tibble of PNS 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/PNS/Documentacao_Geral/. |
Value
A tibble with the data provided from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
get_pns for downloading, labeling, deflating and creating survey design object for PNS microdata.
read_pns for reading PNS microdata.
pns_labeller for labeling categorical variables from PNS microdata.
pns_design for creating PNS survey design object.
pns_example for getting the path of the PNS toy example files.
Examples
# Using data read from disk
input_path <- pns_example(path="input_example.txt")
data_path <- pns_example(path="exampledata.txt")
dictionary.path <- pns_example(path="dictionaryexample.xls")
deflator.path <- pns_example(path="deflatorexample.xls")
pns.df <- read_pns(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pns.df <- pns_labeller(data_pns=pns.df, dictionary.file=dictionary.path)
pns.df <- pns_deflator(data_pns=pns.df, deflator.file=deflator.path)
# Downloading data
pns.df2 <- get_pns(year=2019, selected=FALSE, anthropometry=FALSE, vars=c("J007","J009"),
labels=TRUE, deflator=FALSE, design=FALSE,
reload=TRUE, curlopts=list(), savedir=tempdir())
deflator.path2 <- pns_example(path="deflatorexample.xls")
pns.df2 <- pns_deflator(data_pns=pns.df2, deflator.file=deflator.path2)
Create PNS survey object with its sample design
Description
This function creates PNS survey object with its sample design for analysis using survey
package functions.
Usage
pns_design(data_pns)
Arguments
data_pns |
A tibble of PNS microdata read with |
Value
An object of class survey.design
or svyrep.design
with the data from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
get_pns for downloading, labeling, deflating and creating survey design object for PNS microdata.
read_pns for reading PNS microdata.
pns_labeller for labeling categorical variables from PNS microdata.
pns_deflator for adding deflator variables to PNS microdata.
pns_example for getting the path of the PNS toy example files.
Examples
# Using data read from disk
input_path <- pns_example(path="input_example.txt")
data_path <- pns_example(path="exampledata.txt")
dictionary.path <- pns_example(path="dictionaryexample.xls")
deflator.path <- pns_example(path="deflatorexample.xls")
pns.df <- read_pns(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pns.df <- pns_labeller(data_pns=pns.df, dictionary.file=dictionary.path)
pns.df <- pns_deflator(data_pns=pns.df, deflator.file=deflator.path)
pns.svy <- pns_design(data_pns=pns.df)
# Calculating proportion of people diagnosed with chronic diseases
if (!is.null(pns.svy)) survey::svymean(x=~J007, design=pns.svy, na.rm=TRUE)
# Downloading data
pns.df2 <- get_pns(year=2019, selected=FALSE, anthropometry=FALSE, vars=c("J007","J009"),
labels=TRUE, deflator=TRUE, design=FALSE,
reload=TRUE, curlopts=list(), savedir=tempdir())
pns.svy2 <- pns_design(data_pns=pns.df2)
# Calculating proportion of people diagnosed with chronic diseases
if (!is.null(pns.svy2)) survey::svymean(x=~J007, design=pns.svy2, na.rm=TRUE)
Get the path of the PNS toy example files
Description
This function provides the path of the microdata from year 2019 of the PNS toy example files, loaded with this package.
Usage
pns_example(path = NULL)
Arguments
path |
Name of file. If |
Value
A vector with names of all the available PNS toy example files or the path for specific requested PNS toy example file.
Note
For more information, visit the survey official website <https://www.ibge.gov.br/estatisticas/sociais/saude/9160-pesquisa-nacional-de-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
get_pns for downloading, labeling, deflating and creating survey design object for PNS microdata.
read_pns for reading PNS microdata.
pns_labeller for labeling categorical variables from PNS microdata.
pns_deflator for adding deflator variables to PNS microdata.
pns_design for creating PNS survey design object.
Examples
pns_example()
pns_example(path="exampledata.txt")
pns_example(path="input_example.txt")
pns_example(path="dictionaryexample.xls")
pns_example(path="deflatorexample.xls")
Label categorical variables from PNS microdata
Description
This function labels categorical variables from PNS microdata.
Usage
pns_labeller(data_pns, dictionary.file)
Arguments
data_pns |
A tibble of PNS 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/PNS/. |
Value
A tibble with the data provided from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
get_pns for downloading, labeling, deflating and creating survey design object for PNS microdata.
read_pns for reading PNS microdata.
pns_deflator for adding deflator variables to PNS microdata.
pns_design for creating PNS survey design object.
pns_example for getting the path of the PNS toy example files.
Examples
# Using data read from disk
input_path <- pns_example(path="input_example.txt")
data_path <- pns_example(path="exampledata.txt")
dictionary.path <- pns_example(path="dictionaryexample.xls")
pns.df <- read_pns(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))
pns.df <- pns_labeller(data_pns=pns.df, dictionary.file=dictionary.path)
# Downloading data
pns.df2 <- get_pns(year=2019, selected=FALSE, anthropometry=FALSE, vars=c("J007","J009"),
labels=FALSE, deflator=FALSE, design=FALSE,
reload=TRUE, curlopts=list(), savedir=tempdir())
dictionary.path2 <- pns_example(path="dictionaryexample.xls")
pns.df2 <- pns_labeller(data_pns=pns.df2, dictionary.file=dictionary.path2)
Read PNS microdata
Description
This function reads PNS microdata.
Usage
read_pns(microdata, input_txt, vars = NULL)
Arguments
microdata |
A text file containing microdata from PNS 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/PNS/. |
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/PNS/. |
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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
See Also
get_pns for downloading, labeling, deflating and creating survey design object for PNS microdata.
pns_labeller for labeling categorical variables from PNS microdata.
pns_deflator for adding deflator variables to PNS microdata.
pns_design for creating PNS survey design object.
pns_example for getting the path of the PNS toy example files.
Examples
input_path <- pns_example(path="input_example.txt")
data_path <- pns_example(path="exampledata.txt")
pns.df <- read_pns(microdata=data_path, input_txt=input_path, vars=c("J007","J009"))