Title: | Downloading, Reading and Analyzing PNS Microdata |
---|---|
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'. |
Authors: | Gabriel Assuncao [aut, cre], Luna Hidalgo [aut], Douglas Braga [ctb], Viviane Quintaes [ctb] |
Maintainer: | Gabriel Assuncao <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2025-02-26 03:45:21 UTC |
Source: | https://github.com/gabriel-assuncao/pnsibge |
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.
get_pns( year, selected = FALSE, anthropometry = FALSE, vars = NULL, labels = TRUE, deflator = TRUE, design = TRUE, reload = TRUE, curlopts = list(), savedir = tempdir() )
get_pns( year, selected = FALSE, anthropometry = FALSE, 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 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. |
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.
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.
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.
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)
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)
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.
pns_deflator(data_pns, deflator.file)
pns_deflator(data_pns, deflator.file)
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/. |
A tibble with the data provided from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
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.
# 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)
# 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)
This function creates PNS survey object with its sample design for analysis using survey
package functions.
pns_design(data_pns)
pns_design(data_pns)
data_pns |
A tibble of PNS microdata read with |
An object of class survey.design
or svyrep.design
with the data from PNS and its sample design.
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.
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.
# 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)
# 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)
This function provides the path of the microdata from year 2019 of the PNS toy example files, loaded with this package.
pns_example(path = NULL)
pns_example(path = NULL)
path |
Name of file. If |
A vector with names of all the available PNS toy example files or the path for specific requested PNS toy example file.
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.
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.
pns_example() pns_example(path="exampledata.txt") pns_example(path="input_example.txt") pns_example(path="dictionaryexample.xls") pns_example(path="deflatorexample.xls")
pns_example() pns_example(path="exampledata.txt") pns_example(path="input_example.txt") pns_example(path="dictionaryexample.xls") pns_example(path="deflatorexample.xls")
This function labels categorical variables from PNS microdata.
pns_labeller(data_pns, dictionary.file)
pns_labeller(data_pns, dictionary.file)
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/. |
A tibble with the data provided from PNS 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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
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.
# 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)
# 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)
This function reads PNS microdata.
read_pns(microdata, input_txt, vars = NULL)
read_pns(microdata, input_txt, vars = NULL)
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. |
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-saude.html?=&t=o-que-e> and consult the other functions of this package, described below.
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.
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"))
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"))