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

View source: R/get_pns.R

get_pnsR Documentation

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,
  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 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.

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, 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, 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, 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 Nov. 19, 2023, 1:08 a.m.