get_pns: Download, label, deflate and create survey design object for...

Description Usage Arguments Value Note See Also Examples

View source: R/get_pns.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
get_pns(
  year,
  selected = FALSE,
  anthropometry = FALSE,
  vars = NULL,
  labels = TRUE,
  deflator = TRUE,
  design = TRUE,
  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 TRUE, the specific questionnaire for selected resident will be used. If FALSE, the basic questionnaire for household and residents will be used.

anthropometry

Logical value. If TRUE, the specific questionnaire for the anthropometry module of the selected resident will be used. If FALSE, the questionnaire defined by the selected argument of this function will be used. This argument will be used only if year is equal to 2019.

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 variable will be available for use in the microdata.

design

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

savedir

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

Value

An object of class survey.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 labelling categorical variables from PNS microdata.
pns_deflator for adding deflator variable to PNS microdata.
pns_design for creating PNS survey design object.
pns_example for getting the path of the PNS example files.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
pns.svy <- get_pns(year=2019, selected=FALSE, anthropometry=FALSE, vars=c("J007","J009"),
                       labels=TRUE, deflator=TRUE, design=TRUE, 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, 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, savedir=tempdir())
# Calculating the average weight of people
if (!is.null(pns.svy3)) survey::svymean(x=~W00101, design=pns.svy3, na.rm=TRUE)

PNSIBGE documentation built on Oct. 16, 2021, 1:07 a.m.