├── DESCRIPTION ├── MD5 ├── NAMESPACE ├── R ├── example.R ├── get_pnadc.R ├── pnadc_deflator.R ├── pnadc_design.R ├── pnadc_labeller.R └── read_pnadc.R ├── README.md ├── inst └── extdata │ ├── deflatorexample.xls │ ├── dictionaryexample.xls │ ├── exampledata.txt │ └── input_example.txt └── man ├── get_pnadc.Rd ├── pnadc_deflator.Rd ├── pnadc_design.Rd ├── pnadc_example.Rd ├── pnadc_labeller.Rd └── read_pnadc.Rd /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: PNADcIBGE 2 | Type: Package 3 | Title: Downloading, Reading and Analyzing PNADC Microdata 4 | Version: 0.7.5 5 | Authors@R: c(person("Douglas", "Braga", email = "pacotesipd@ibge.gov.br", 6 | role = c("aut")), 7 | person("Gabriel", "Assuncao", email = "pacotesipd@ibge.gov.br", 8 | role = c("aut", "cre")), 9 | person("Luna", "Hidalgo", email = "pacotesipd@ibge.gov.br", 10 | role = c("ctb")), 11 | person("Viviane", "Quintaes", email = "pacotesipd@ibge.gov.br", 12 | role = c("ctb"))) 13 | Description: Provides tools for downloading, reading and analyzing the Continuous National 14 | Household Sample Survey - PNADC, a household survey from Brazilian Institute 15 | of Geography and Statistics - IBGE. The data must be downloaded from the official 16 | website . Further analysis must be made using package 'survey'. 17 | Depends: R (>= 3.2.0) 18 | Imports: dplyr, httr, magrittr, projmgr, RCurl, readr, readxl, survey, 19 | tibble, timeDate, utils 20 | Suggests: convey, SIPDIBGE, srvyr 21 | License: GPL-3 22 | Encoding: UTF-8 23 | RoxygenNote: 7.1.2 24 | NeedsCompilation: no 25 | Author: Douglas Braga [aut], 26 | Gabriel Assuncao [aut, cre], 27 | Luna Hidalgo [ctb], 28 | Viviane Quintaes [ctb] 29 | Maintainer: Gabriel Assuncao 30 | BugReports: https://github.com/Gabriel-Assuncao/PNADcIBGE/issues 31 | Packaged: 2024-02-01 14:09:08 UTC; gabriel.assuncao 32 | Repository: CRAN 33 | Date/Publication: 2024-02-01 15:40:06 UTC 34 | -------------------------------------------------------------------------------- /MD5: -------------------------------------------------------------------------------- 1 | aab621a79f7be7eb1ceaa2cf4c2f5289 *DESCRIPTION 2 | 6decbd208cf796c300bb7ead158073c5 *NAMESPACE 3 | 56c615e7888dc2fdba340fbe244d9a17 *R/example.R 4 | 7908e82073d2c9dc1d705306c56ee781 *R/get_pnadc.R 5 | 5fd3a4c5793712f9e0ee00ed805190ab *R/pnadc_deflator.R 6 | cd27d85358e9e40895178f0b0f245918 *R/pnadc_design.R 7 | b69afa0417f347dae8069656c37fe9ea *R/pnadc_labeller.R 8 | f91f4b0b1e83479db2c3d39f507c35e7 *R/read_pnadc.R 9 | 29cc801e129ab9eb2635f27b410f8a59 *README.md 10 | 9ccca52574f68fe6860f2b395702f33a *inst/extdata/deflatorexample.xls 11 | d10e8245d66fa52552a44fd4f013c266 *inst/extdata/dictionaryexample.xls 12 | 52efec701f05546c2964b8c9c77d8cfc *inst/extdata/exampledata.txt 13 | 9968b588734160713e5fe4534f60442f *inst/extdata/input_example.txt 14 | 020c906ae19b68391cf13b1b7c649fd6 *man/get_pnadc.Rd 15 | cb477894bf01da61f289bc51d474ecc4 *man/pnadc_deflator.Rd 16 | a98e39046593985a039e96ab7140f545 *man/pnadc_design.Rd 17 | 60d07166758d44c515a1adb13676cd08 *man/pnadc_example.Rd 18 | 3f21c8508b55ca9caca288e23164b0b2 *man/pnadc_labeller.Rd 19 | c237a3291b6c7a1d4c07ef719d689f44 *man/read_pnadc.Rd 20 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(get_pnadc) 4 | export(pnadc_deflator) 5 | export(pnadc_design) 6 | export(pnadc_example) 7 | export(pnadc_labeller) 8 | export(read_pnadc) 9 | import(RCurl) 10 | import(dplyr) 11 | import(httr) 12 | import(magrittr) 13 | import(projmgr) 14 | import(readr) 15 | import(readxl) 16 | import(survey) 17 | import(tibble) 18 | import(timeDate) 19 | import(utils) 20 | -------------------------------------------------------------------------------- /R/example.R: -------------------------------------------------------------------------------- 1 | #' Get the path of the quarter PNADC toy example files 2 | #' @description This function provides the path of the microdata from quarter 4 of year 2017 of the PNADC toy example files, loaded with this package. 3 | #' @import dplyr httr magrittr projmgr RCurl readr readxl survey tibble timeDate utils 4 | #' @param path Name of file. If \code{NULL}, the quarter PNADC toy example files names will be listed. 5 | #' @return A vector with names of all the available quarter PNADC toy example files or the path for specific requested quarter PNADC toy example file. 6 | #' @note For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 7 | #' @seealso \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object. 8 | #' @examples 9 | #' pnadc_example() 10 | #' pnadc_example(path="exampledata.txt") 11 | #' pnadc_example(path="input_example.txt") 12 | #' pnadc_example(path="dictionaryexample.xls") 13 | #' pnadc_example(path="deflatorexample.xls") 14 | #' @export 15 | 16 | pnadc_example <- function(path = NULL) { 17 | if (is.null(path)) { 18 | dir(system.file("extdata", package="PNADcIBGE")) 19 | } 20 | else { 21 | system.file("extdata", path, package="PNADcIBGE", mustWork=TRUE) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /R/get_pnadc.R: -------------------------------------------------------------------------------- 1 | #' Download, label, deflate and create survey design object for PNADC microdata 2 | #' @description Core function of package. With this function only, the user can download a PNADC microdata from a year or quarter and get a sample design object ready to use with \code{survey} package functions. 3 | #' @import dplyr httr magrittr projmgr RCurl readr readxl survey tibble timeDate utils 4 | #' @param year The year of the data to be downloaded. Must be a number between 2012 and current year. Vector not accepted. 5 | #' @param quarter The quarter of the year of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. If \code{NULL}, \code{interview} or \code{topic} number must be provided. 6 | #' @param interview The interview number of the data to be downloaded. Must be number from 1 to 5. Vector not accepted. Using this option will get annual per interview data. If \code{NULL}, \code{quarter} or \code{topic} number must be provided. 7 | #' @param topic The quarter related to the topic of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. Using this option will get annual per topic data. If \code{NULL}, \code{quarter} or \code{interview} number must be provided. 8 | #' @param selected Logical value. If \code{TRUE}, the specific questionnaire for selected resident will be used. If \code{FALSE}, the basic questionnaire for household and residents will be used. For more information about these supplemental topics, please check the survey official website. 9 | #' @param vars Vector of variable names to be kept for analysis. Default is to keep all variables. 10 | #' @param defyear The year of the deflator data to be downloaded for annual microdata. Must be a number between 2017 and the last available year. Vector not accepted. If \code{NULL}, the deflator year will be defined as the last year available for interview microdata, or as equal to \code{year} for topic microdata. When \code{quarter} is defined, this argument will be ignored. This argument will be used only if \code{deflator} was set as \code{TRUE}. 11 | #' @param defperiod The quarter period of the deflator data to be downloaded for annual per topic microdata. Must be number from 1 to 4. Vector not accepted. If \code{NULL}, the deflator period will be defined as equal to \code{topic}. When \code{quarter} or \code{interview} is defined, this argument will be ignored. This argument will be used only if \code{deflator} was set as \code{TRUE}. 12 | #' @param labels Logical value. If \code{TRUE}, categorical variables will presented as factors with labels corresponding to the survey's dictionary. 13 | #' @param deflator Logical value. If \code{TRUE}, deflator variables will be available for use in the microdata. 14 | #' @param design Logical value. If \code{TRUE}, will return an object of class \code{survey.design} or \code{svyrep.design}. It is strongly recommended to keep this parameter as \code{TRUE} for further analysis. If \code{FALSE}, only the microdata will be returned. 15 | #' @param reload Logical value. If \code{TRUE}, will re-download the files even if they already exist in the save directory. If \code{FALSE}, will be checked if the files already exist in the save directory and the download will not be performed repeatedly, be careful with coinciding names of microdata files. 16 | #' @param curlopts A named list object identifying the curl options for the handle when using functions from \code{RCurl} package. 17 | #' @param savedir Directory to save the downloaded data. Default is to use a temporary directory. 18 | #' @return An object of class \code{survey.design} or \code{svyrep.design} with the data from PNADC and its sample design, or a tibble with selected variables of the microdata, including the necessary survey design ones. 19 | #' @note For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 20 | #' @seealso \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 21 | #' @examples 22 | #' \donttest{ 23 | #' pnadc.svy <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 24 | #' defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 25 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 26 | #' # Calculating proportion of employed and unemployed people 27 | #' if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE) 28 | #' pnadc.svy2 <- get_pnadc(year=2017, interview=5, selected=FALSE, vars=c("V4112","V4121B"), 29 | #' defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 30 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 31 | #' # Calculating average hours dedicated to the care of people or household chores 32 | #' if (!is.null(pnadc.svy2)) survey::svymean(x=~V4121B, design=pnadc.svy2, na.rm=TRUE) 33 | #' pnadc.svy3 <- get_pnadc(year=2017, topic=4, selected=FALSE, vars=c("S07006","S07007"), 34 | #' defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 35 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 36 | #' # Calculating proportion of cell phone for personal use with internet access 37 | #' if (!is.null(pnadc.svy3)) survey::svymean(x=~S07007, design=pnadc.svy3, na.rm=TRUE)} 38 | #' @export 39 | 40 | get_pnadc <- function(year, quarter = NULL, interview = NULL, topic = NULL, selected = FALSE, vars = NULL, defyear = NULL, defperiod = NULL, 41 | labels = TRUE, deflator = TRUE, design = TRUE, reload = TRUE, curlopts = list(), savedir = tempdir()) 42 | { 43 | if (is.null(quarter) & is.null(interview) & is.null(topic)) { 44 | message("Quarter number or interview number or topic number must be provided.\n") 45 | return(NULL) 46 | } 47 | if ((!is.null(quarter) & !is.null(interview)) | 48 | (!is.null(quarter) & !is.null(topic)) | 49 | (!is.null(interview) & !is.null(topic)) | 50 | (!is.null(quarter) & !is.null(interview) & !is.null(topic))) { 51 | message("Must be provided only one between quarter number, interview number and topic number.\n") 52 | return(NULL) 53 | } 54 | if (year < 2012) { 55 | message("Year must be greater or equal to 2012.\n") 56 | return(NULL) 57 | } 58 | if (year > timeDate::getRmetricsOptions("currentYear")) { 59 | message("Year cannot be greater than current year.\n") 60 | return(NULL) 61 | } 62 | if (!(selected %in% c(TRUE, FALSE))) { 63 | selected <- FALSE 64 | message("Invalid value provided for selected argument, so default value FALSE was set to this argument.\n") 65 | } 66 | if (!(labels %in% c(TRUE, FALSE))) { 67 | labels <- TRUE 68 | message("Invalid value provided for labels argument, so default value TRUE was set to this argument.\n") 69 | } 70 | if (!(deflator %in% c(TRUE, FALSE))) { 71 | deflator <- TRUE 72 | message("Invalid value provided for deflator argument, so default value TRUE was set to this argument.\n") 73 | } 74 | if (!(design %in% c(TRUE, FALSE))) { 75 | design <- TRUE 76 | message("Invalid value provided for design argument, so default value TRUE was set to this argument.\n") 77 | } 78 | if (!(reload %in% c(TRUE, FALSE))) { 79 | reload <- TRUE 80 | message("Invalid value provided for reload argument, so default value TRUE was set to this argument.\n") 81 | } 82 | if (!is.list(curlopts)) { 83 | curlopts <- list() 84 | message("Invalid value provided for curlopts argument, as the value of this argument needs to be a list, so the value provided will be ignored.\n") 85 | } 86 | if (!dir.exists(savedir)) { 87 | savedir <- tempdir() 88 | message(paste0("The directory provided does not exist, so the directory was set to '", savedir), "'.\n") 89 | } 90 | if (savedir != tempdir()) { 91 | printpath <- TRUE 92 | } 93 | else { 94 | printpath <- FALSE 95 | } 96 | if (substr(savedir, nchar(savedir), nchar(savedir)) == "/" | substr(savedir, nchar(savedir), nchar(savedir)) == "\\") { 97 | savedir <- substr(savedir, 1, nchar(savedir)-1) 98 | } 99 | if (!is.null(quarter)) { 100 | if (quarter < 1 | quarter > 4) { 101 | message("Quarter number must be an integer from 1 to 4.\n") 102 | return(NULL) 103 | } 104 | ftpdir <- ("https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/") 105 | if (!projmgr::check_internet()) { 106 | message("The internet connection is unavailable.\n") 107 | return(NULL) 108 | } 109 | if (httr::http_error(httr::GET(ftpdir, httr::timeout(60)))) { 110 | message("The microdata server is unavailable.\n") 111 | return(NULL) 112 | } 113 | restime <- getOption("timeout") 114 | on.exit(options(timeout=restime)) 115 | options(timeout=max(600, restime)) 116 | ftpdata <- paste0(ftpdir, year, "/") 117 | datayear <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(ftpdata, dirlistonly=TRUE, .opts=curlopts)), "\n")), " 1) { 124 | message("There is more than one file available for the requested microdata, please contact the package maintainer.\n") 125 | return(NULL) 126 | } 127 | else { 128 | dataname <- paste0(dataname, ".zip") 129 | } 130 | if (reload == FALSE & file.exists(paste0(savedir, "/", dataname))) { 131 | message("The reload argument was defined as FALSE and the file of microdata was already downloaded, so the download process will not execute again.\n") 132 | } 133 | else { 134 | utils::download.file(url=paste0(ftpdata, dataname), destfile=paste0(savedir, "/", dataname), mode="wb") 135 | if (suppressWarnings(class(try(utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir), silent=TRUE)) == "try-error")) { 136 | message("The directory defined to save the downloaded data is denied permission to overwrite the existing files, please clear or change this directory.\n") 137 | return(NULL) 138 | } 139 | if (reload == FALSE) { 140 | message("The definition of FALSE for the reload argument will be ignored, since the file of microdata was not downloaded yet.\n") 141 | } 142 | } 143 | utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir) 144 | docfiles <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(paste0(ftpdir, "Documentacao/"), dirlistonly=TRUE, .opts=curlopts)), "\n")), " 5) { 206 | message("Interview number must be a integer from 1 to 5.\n") 207 | return(NULL) 208 | } 209 | ftpdir <- ("https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/") 210 | if (!projmgr::check_internet()) { 211 | message("The internet connection is unavailable.\n") 212 | return(NULL) 213 | } 214 | if (httr::http_error(httr::GET(ftpdir, httr::timeout(60)))) { 215 | message("The microdata server is unavailable.\n") 216 | return(NULL) 217 | } 218 | restime <- getOption("timeout") 219 | on.exit(options(timeout=restime)) 220 | options(timeout=max(600, restime)) 221 | ftpdata <- paste0(ftpdir, "Visita_", interview, "/Dados/") 222 | datayear <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(ftpdata, dirlistonly=TRUE, .opts=curlopts)), "\n")), " 1) { 229 | message("There is more than one file available for the requested microdata, please contact the package maintainer.\n") 230 | return(NULL) 231 | } 232 | else { 233 | dataname <- paste0(dataname, ".zip") 234 | } 235 | if (reload == FALSE & file.exists(paste0(savedir, "/", dataname))) { 236 | message("The reload argument was defined as FALSE and the file of microdata was already downloaded, so the download process will not execute again.\n") 237 | } 238 | else { 239 | utils::download.file(url=paste0(ftpdata, dataname), destfile=paste0(savedir, "/", dataname), mode="wb") 240 | if (suppressWarnings(class(try(utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir), silent=TRUE)) == "try-error")) { 241 | message("The directory defined to save the downloaded data is denied permission to overwrite the existing files, please clear or change this directory.\n") 242 | return(NULL) 243 | } 244 | if (reload == FALSE) { 245 | message("The definition of FALSE for the reload argument will be ignored, since the file of microdata was not downloaded yet.\n") 246 | } 247 | } 248 | utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir) 249 | docfiles <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(paste0(ftpdir, "Visita_", interview, "/Documentacao/"), dirlistonly=TRUE, .opts=curlopts)), "\n")), "= timeDate::getRmetricsOptions("currentYear")) { 328 | defyear <- timeDate::getRmetricsOptions("currentYear") - 1 329 | message(paste0("Deflator year must be greater or equal to 2017 and cannot be greater or equal than current year, so deflator year was changed to ", defyear, ".\n")) 330 | } 331 | if (length(arcfiles[which(startsWith(arcfiles, paste0("deflator_PNADC_", defyear)))]) == 0) { 332 | defyear <- defyear - 1 333 | message(paste0("Deflator data unavailable for selected year, so deflator year was changed to ", defyear, ".\n")) 334 | } 335 | defpre <- paste0(arcfiles[which(startsWith(arcfiles, paste0("deflator_PNADC_", defyear)))], ".xls") 336 | if (reload == FALSE & file.exists(paste0(savedir, "/", defpre))) { 337 | message("The reload argument was defined as FALSE and the file of deflator was already downloaded, so the download process will not execute again.\n") 338 | } 339 | else { 340 | utils::download.file(url=paste0(ftpdir, "Documentacao_Geral/", defpre), destfile=paste0(savedir, "/", defpre), mode="wb") 341 | if (reload == FALSE) { 342 | message("The definition of FALSE for the reload argument will be ignored, since the file of deflator was not downloaded yet.\n") 343 | } 344 | } 345 | defname <- dir(savedir, pattern=paste0("^deflator_PNADC_", defyear, ".*\\.xls$"), ignore.case=FALSE) 346 | deffile <- paste0(savedir, "/", defname) 347 | deffile <- rownames(file.info(deffile)[order(file.info(deffile)$mtime),])[length(deffile)] 348 | data_pnadc <- PNADcIBGE::pnadc_deflator(data_pnadc=data_pnadc, deflator.file=deffile) 349 | } 350 | else { 351 | message("Deflator function is unavailable in package PNADcIBGE.\n") 352 | } 353 | } 354 | } 355 | if (!is.null(topic)) { 356 | if (topic < 1 | topic > 4) { 357 | message("Topic number must be a integer from 1 to 4.\n") 358 | return(NULL) 359 | } 360 | ftpdir <- ("https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/") 361 | if (!projmgr::check_internet()) { 362 | message("The internet connection is unavailable.\n") 363 | return(NULL) 364 | } 365 | if (httr::http_error(httr::GET(ftpdir, httr::timeout(60)))) { 366 | message("The microdata server is unavailable.\n") 367 | return(NULL) 368 | } 369 | restime <- getOption("timeout") 370 | on.exit(options(timeout=restime)) 371 | options(timeout=max(600, restime)) 372 | ftpdata <- paste0(ftpdir, "Trimestre_", topic, "/Dados/") 373 | datayear <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(ftpdata, dirlistonly=TRUE, .opts=curlopts)), "\n")), " 1) { 380 | message("There is more than one file available for the requested microdata, please contact the package maintainer.\n") 381 | return(NULL) 382 | } 383 | else { 384 | dataname <- paste0(dataname, ".zip") 385 | } 386 | if (reload == FALSE & file.exists(paste0(savedir, "/", dataname))) { 387 | message("The reload argument was defined as FALSE and the file of microdata was already downloaded, so the download process will not execute again.\n") 388 | } 389 | else { 390 | utils::download.file(url=paste0(ftpdata, dataname), destfile=paste0(savedir, "/", dataname), mode="wb") 391 | if (suppressWarnings(class(try(utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir), silent=TRUE)) == "try-error")) { 392 | message("The directory defined to save the downloaded data is denied permission to overwrite the existing files, please clear or change this directory.\n") 393 | return(NULL) 394 | } 395 | if (reload == FALSE) { 396 | message("The definition of FALSE for the reload argument will be ignored, since the file of microdata was not downloaded yet.\n") 397 | } 398 | } 399 | utils::unzip(zipfile=paste0(savedir, "/", dataname), exdir=savedir) 400 | docfiles <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(paste0(ftpdir, "Trimestre_", topic, "/Documentacao/"), dirlistonly=TRUE, .opts=curlopts)), "\n")), " timeDate::getRmetricsOptions("currentYear")) { 476 | defyear <- year 477 | message(paste0("Deflator year must be greater or equal to 2017 and cannot be greater than current year, so deflator year was changed to ", defyear, ".\n")) 478 | } 479 | if (defyear == year & defperiod < topic) { 480 | defperiod <- topic 481 | message(paste0("For ", defyear, ", deflator period must be greater or equal to microdata topic, so deflator period was changed to ", defperiod, ".\n")) 482 | } 483 | if (defperiod < 1 | defperiod > 4) { 484 | defperiod <- topic 485 | message(paste0("Deflator period must be greater or equal to 1 and cannot be greater than 4, so deflator period was changed to ", defperiod, ".\n")) 486 | } 487 | perfiles <- unlist(strsplit(unlist(strsplit(unlist(strsplit(gsub("\r\n", "\n", RCurl::getURL(paste0(ftpdir, "Trimestre_", defperiod, "/Documentacao/"), dirlistonly=TRUE, .opts=curlopts)), "\n")), " and consult the other functions of this package, described below. 8 | #' @seealso \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 9 | #' @examples 10 | #' # Using data read from disk 11 | #' input_path <- pnadc_example(path="input_example.txt") 12 | #' data_path <- pnadc_example(path="exampledata.txt") 13 | #' dictionary.path <- pnadc_example(path="dictionaryexample.xls") 14 | #' deflator.path <- pnadc_example(path="deflatorexample.xls") 15 | #' pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 16 | #' pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 17 | #' pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path) 18 | #' \donttest{ 19 | #' # Downloading data 20 | #' pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 21 | #' defyear=2017, defperiod=4, labels=TRUE, deflator=FALSE, design=FALSE, 22 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 23 | #' deflator.path2 <- pnadc_example(path="deflatorexample.xls") 24 | #' pnadc.df2 <- pnadc_deflator(data_pnadc=pnadc.df2, deflator.file=deflator.path2)} 25 | #' @export 26 | 27 | pnadc_deflator <- function(data_pnadc, deflator.file) { 28 | if (sum(class(data_pnadc) == "tbl_df") > 0) { 29 | if (!(FALSE %in% (c("Ano", "Trimestre", "UF") %in% names(data_pnadc)))) { 30 | data_pnadc <- data_pnadc[, !names(data_pnadc) %in% c("Habitual", "Efetivo", "CO1", "CO1e", "CO2", "CO2e", "CO3"), drop=FALSE] 31 | deflator <- suppressMessages(readxl::read_excel(deflator.file)) 32 | colnames(deflator)[c(1:3)] <- c("Ano", "Trimestre", "UF") 33 | deflator$Trimestre <- ifelse(deflator$Trimestre == "01-02-03","1", 34 | ifelse(deflator$Trimestre == "04-05-06","2", 35 | ifelse(deflator$Trimestre == "07-08-09","3", 36 | ifelse(deflator$Trimestre == "10-11-12","4", 37 | ifelse(nchar(deflator$Trimestre) > 1,"", 38 | ifelse(deflator$Trimestre %in% c("1","2","3","4"),deflator$Trimestre,"")))))) 39 | deflator <- deflator[deflator$Trimestre != "",] 40 | deflator$UF <- as.factor(deflator$UF) 41 | if (identical(intersect(levels(deflator$UF), levels(as.factor(data_pnadc$UF))), character(0)) & length(levels(deflator$UF)) == length(levels(as.factor(data_pnadc$UF)))) { 42 | levels(deflator$UF) <- levels(as.factor(data_pnadc$UF)) 43 | } 44 | data_pnadc <- merge(x=data_pnadc, y=deflator, by.x=c("Ano", "Trimestre", "UF"), by.y=c("Ano", "Trimestre", "UF"), all.x=TRUE, all.y=FALSE) 45 | if (!(FALSE %in% (c("ID_DOMICILIO") %in% names(data_pnadc)))) { 46 | data_pnadc <- data_pnadc[order(data_pnadc$Estrato, data_pnadc$ID_DOMICILIO, data_pnadc$V2003),] 47 | } 48 | else { 49 | data_pnadc <- data_pnadc[order(data_pnadc$Estrato, data_pnadc$UPA, data_pnadc$V1008, data_pnadc$V1014, data_pnadc$V2003),] 50 | } 51 | data_pnadc <- tibble::as_tibble(data_pnadc) 52 | } 53 | else { 54 | message("Merge variables required for adding deflator variables are missing.\n") 55 | } 56 | } 57 | else { 58 | message("The microdata object is not of the tibble class or sample design was already defined for microdata, so adding deflator variables is not possible.\n") 59 | } 60 | return(data_pnadc) 61 | } 62 | -------------------------------------------------------------------------------- /R/pnadc_design.R: -------------------------------------------------------------------------------- 1 | #' Create PNADC survey object with its sample design 2 | #' @description This function creates PNADC survey object with its sample design for analysis using \code{survey} package functions. 3 | #' @import dplyr httr magrittr projmgr RCurl readr readxl survey tibble timeDate utils 4 | #' @param data_pnadc A tibble of PNADC microdata read with \code{read_pnadc} function. 5 | #' @return An object of class \code{survey.design} or \code{svyrep.design} with the data from PNADC and its sample design. 6 | #' @note For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 7 | #' @seealso \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 8 | #' @examples 9 | #' # Using data read from disk 10 | #' input_path <- pnadc_example(path="input_example.txt") 11 | #' data_path <- pnadc_example(path="exampledata.txt") 12 | #' dictionary.path <- pnadc_example(path="dictionaryexample.xls") 13 | #' deflator.path <- pnadc_example(path="deflatorexample.xls") 14 | #' pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 15 | #' pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 16 | #' pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path) 17 | #' \donttest{ 18 | #' pnadc.svy <- pnadc_design(data_pnadc=pnadc.df) 19 | #' # Calculating proportion of employed and unemployed people 20 | #' if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE)} 21 | #' \donttest{ 22 | #' # Downloading data 23 | #' pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 24 | #' defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=FALSE, 25 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 26 | #' pnadc.svy2 <- pnadc_design(data_pnadc=pnadc.df2) 27 | #' # Calculating proportion of employed and unemployed people 28 | #' if (!is.null(pnadc.svy2)) survey::svymean(x=~VD4002, design=pnadc.svy2, na.rm=TRUE)} 29 | #' @export 30 | 31 | pnadc_design <- function(data_pnadc) { 32 | if (sum(class(data_pnadc) == "tbl_df") > 0) { 33 | if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1027", "V1028", "V1029", "V1033", "posest", "posest_sxi") %in% names(data_pnadc))) | 34 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1030", "V1031", "V1032", "V1034", "posest", "posest_sxi") %in% names(data_pnadc))) | 35 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1027", "V1028", "V1029", "posest") %in% names(data_pnadc))) | 36 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1030", "V1031", "V1032", "posest") %in% names(data_pnadc))) | 37 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1035", "V1036", "V1037", "V1038", "posest", "posest_sxi") %in% names(data_pnadc))) | 38 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1039", "V1040", "V1041", "V1042", "posest", "posest_sxi") %in% names(data_pnadc))) | 39 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1035", "V1036", "V1037", "posest") %in% names(data_pnadc))) | 40 | !(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1039", "V1040", "V1041", "posest") %in% names(data_pnadc)))) { 41 | options(survey.lonely.psu="adjust") 42 | options(survey.adjust.domain.lonely=TRUE) 43 | if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1027", "V1028", "V1029", "V1033", "posest", "posest_sxi") %in% names(data_pnadc)))) { 44 | if (!(FALSE %in% (sprintf("V1028%03d", seq(1:200)) %in% names(data_pnadc)))) { 45 | data_posterior <- survey::svrepdesign(data=data_pnadc, weight=~V1028, type="bootstrap", repweights="V1028[0-9]+", mse=TRUE, replicates=length(sprintf("V1028%03d", seq(1:200))), df=length(sprintf("V1028%03d", seq(1:200)))) 46 | } 47 | else { 48 | data_prior <- survey::svydesign(ids=~UPA+ID_DOMICILIO, strata=~Estrato, data=data_pnadc, weights=~V1027, nest=TRUE) 49 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1029))) 50 | popc.types <- popc.types[order(popc.types$posest),] 51 | popi.types <- data.frame(posest_sxi=as.character(unique(data_pnadc$posest_sxi)), Freq=as.numeric(unique(data_pnadc$V1033))) 52 | popi.types <- popi.types[order(popi.types$posest_sxi),] 53 | pop.rake.calib <- c(sum(popc.types$Freq), popc.types$Freq[-1], popi.types$Freq[-1]) 54 | data_posterior <- survey::calibrate(design=data_prior, formula=~posest+posest_sxi, pop=pop.rake.calib, calfun="raking", aggregate.stage=2, bounds=c(0.2,5), multicore=TRUE) 55 | } 56 | } 57 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1030", "V1031", "V1032", "V1034", "posest", "posest_sxi") %in% names(data_pnadc)))) { 58 | if (!(FALSE %in% (sprintf("V1032%03d", seq(1:200)) %in% names(data_pnadc)))) { 59 | data_posterior <- survey::svrepdesign(data=data_pnadc, weight=~V1032, type="bootstrap", repweights="V1032[0-9]+", mse=TRUE, replicates=length(sprintf("V1032%03d", seq(1:200))), df=length(sprintf("V1032%03d", seq(1:200)))) 60 | } 61 | else { 62 | data_prior <- survey::svydesign(ids=~UPA+ID_DOMICILIO, strata=~Estrato, data=data_pnadc, weights=~V1031, nest=TRUE) 63 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1030))) 64 | popc.types <- popc.types[order(popc.types$posest),] 65 | popi.types <- data.frame(posest_sxi=as.character(unique(data_pnadc$posest_sxi)), Freq=as.numeric(unique(data_pnadc$V1034))) 66 | popi.types <- popi.types[order(popi.types$posest_sxi),] 67 | pop.rake.calib <- c(sum(popc.types$Freq), popc.types$Freq[-1], popi.types$Freq[-1]) 68 | data_posterior <- survey::calibrate(design=data_prior, formula=~posest+posest_sxi, pop=pop.rake.calib, calfun="raking", aggregate.stage=2, bounds=c(0.2,5), multicore=TRUE) 69 | } 70 | } 71 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1027", "V1028", "V1029", "posest") %in% names(data_pnadc)))) { 72 | data_prior <- survey::svydesign(ids=~UPA, strata=~Estrato, data=data_pnadc, weights=~V1027, nest=TRUE) 73 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1029))) 74 | popc.types <- popc.types[order(popc.types$posest),] 75 | data_posterior <- survey::postStratify(design=data_prior, strata=~posest, population=popc.types) 76 | } 77 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1030", "V1031", "V1032", "posest") %in% names(data_pnadc)))) { 78 | data_prior <- survey::svydesign(ids=~UPA, strata=~Estrato, data=data_pnadc, weights=~V1031, nest=TRUE) 79 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1030))) 80 | popc.types <- popc.types[order(popc.types$posest),] 81 | data_posterior <- survey::postStratify(design=data_prior, strata=~posest, population=popc.types) 82 | } 83 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1035", "V1036", "V1037", "V1038", "posest", "posest_sxi") %in% names(data_pnadc)))) { 84 | if (!(FALSE %in% (sprintf("V1036%03d", seq(1:200)) %in% names(data_pnadc)))) { 85 | data_posterior <- survey::svrepdesign(data=data_pnadc, weight=~V1036, type="bootstrap", repweights="V1036[0-9]+", mse=TRUE, replicates=length(sprintf("V1036%03d", seq(1:200))), df=length(sprintf("V1036%03d", seq(1:200)))) 86 | } 87 | else { 88 | data_prior <- survey::svydesign(ids=~UPA+ID_DOMICILIO, strata=~Estrato, data=data_pnadc, weights=~V1035, nest=TRUE) 89 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1037))) 90 | popc.types <- popc.types[order(popc.types$posest),] 91 | popi.types <- data.frame(posest_sxi=as.character(unique(data_pnadc$posest_sxi)), Freq=as.numeric(unique(data_pnadc$V1038))) 92 | popi.types <- popi.types[order(popi.types$posest_sxi),] 93 | pop.rake.calib <- c(sum(popc.types$Freq), popc.types$Freq[-1], popi.types$Freq[-1]) 94 | data_posterior <- survey::calibrate(design=data_prior, formula=~posest+posest_sxi, pop=pop.rake.calib, calfun="raking", aggregate.stage=2, bounds=c(0.2,5), multicore=TRUE) 95 | } 96 | } 97 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1039", "V1040", "V1041", "V1042", "posest", "posest_sxi") %in% names(data_pnadc)))) { 98 | if (!(FALSE %in% (sprintf("V1040%03d", seq(1:200)) %in% names(data_pnadc)))) { 99 | data_posterior <- survey::svrepdesign(data=data_pnadc, weight=~V1040, type="bootstrap", repweights="V1040[0-9]+", mse=TRUE, replicates=length(sprintf("V1040%03d", seq(1:200))), df=length(sprintf("V1040%03d", seq(1:200)))) 100 | } 101 | else { 102 | data_prior <- survey::svydesign(ids=~UPA+ID_DOMICILIO, strata=~Estrato, data=data_pnadc, weights=~V1039, nest=TRUE) 103 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1041))) 104 | popc.types <- popc.types[order(popc.types$posest),] 105 | popi.types <- data.frame(posest_sxi=as.character(unique(data_pnadc$posest_sxi)), Freq=as.numeric(unique(data_pnadc$V1042))) 106 | popi.types <- popi.types[order(popi.types$posest_sxi),] 107 | pop.rake.calib <- c(sum(popc.types$Freq), popc.types$Freq[-1], popi.types$Freq[-1]) 108 | data_posterior <- survey::calibrate(design=data_prior, formula=~posest+posest_sxi, pop=pop.rake.calib, calfun="raking", aggregate.stage=2, bounds=c(0.2,5), multicore=TRUE) 109 | } 110 | } 111 | else if (!(FALSE %in% (c("UPA", "ID_DOMICILIO", "Estrato", "V1035", "V1036", "V1037", "posest") %in% names(data_pnadc)))) { 112 | data_prior <- survey::svydesign(ids=~UPA, strata=~Estrato, data=data_pnadc, weights=~V1035, nest=TRUE) 113 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1037))) 114 | popc.types <- popc.types[order(popc.types$posest),] 115 | data_posterior <- survey::postStratify(design=data_prior, strata=~posest, population=popc.types) 116 | } 117 | else { 118 | data_prior <- survey::svydesign(ids=~UPA, strata=~Estrato, data=data_pnadc, weights=~V1039, nest=TRUE) 119 | popc.types <- data.frame(posest=as.character(unique(data_pnadc$posest)), Freq=as.numeric(unique(data_pnadc$V1041))) 120 | popc.types <- popc.types[order(popc.types$posest),] 121 | data_posterior <- survey::postStratify(design=data_prior, strata=~posest, population=popc.types) 122 | } 123 | } 124 | else { 125 | message("Weight variables required for sample design are missing.\n") 126 | data_posterior <- data_pnadc 127 | } 128 | } 129 | else { 130 | message("The microdata object is not of the tibble class or sample design was already defined for microdata, so applying another design is not possible.\n") 131 | data_posterior <- data_pnadc 132 | } 133 | return(data_posterior) 134 | } 135 | -------------------------------------------------------------------------------- /R/pnadc_labeller.R: -------------------------------------------------------------------------------- 1 | #' Label categorical variables from PNADC microdata 2 | #' @description This function labels categorical variables from PNADC microdata. 3 | #' @import dplyr httr magrittr projmgr RCurl readr readxl survey tibble timeDate utils 4 | #' @param data_pnadc A tibble of PNADC microdata read with \code{read_pnadc} function. 5 | #' @param dictionary.file The dictionary file for selected survey available on official website:\cr Quarter (select the dictionary and input zip file) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/}.\cr Annual per Interview (select a dictionary xls file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a dictionary xls file, according to the appropriated quarter related to the topic, inside the documentation folder) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}. 6 | #' @return A tibble with the data provided from PNADC survey and its categorical variables as factors with related labels. 7 | #' @note For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 8 | #' @seealso \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 9 | #' @examples 10 | #' # Using data read from disk 11 | #' input_path <- pnadc_example(path="input_example.txt") 12 | #' data_path <- pnadc_example(path="exampledata.txt") 13 | #' dictionary.path <- pnadc_example(path="dictionaryexample.xls") 14 | #' pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 15 | #' pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 16 | #' \donttest{ 17 | #' # Downloading data 18 | #' pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 19 | #' defyear=2017, defperiod=4, labels=FALSE, deflator=FALSE, design=FALSE, 20 | #' reload=TRUE, curlopts=list(), savedir=tempdir()) 21 | #' dictionary.path2 <- pnadc_example(path="dictionaryexample.xls") 22 | #' pnadc.df2 <- pnadc_labeller(data_pnadc=pnadc.df2, dictionary.file=dictionary.path2)} 23 | #' @export 24 | 25 | pnadc_labeller <- function(data_pnadc, dictionary.file) { 26 | if (sum(class(data_pnadc) == "tbl_df") > 0) { 27 | dictionary <- suppressMessages(readxl::read_excel(dictionary.file)) 28 | X__3 = X__6 = X__7 = NULL 29 | colnames(dictionary) <- paste0("X__",1:dim(dictionary)[2]) 30 | dictionary %<>% subset(!is.na(X__6)) 31 | codcurrent <- dictionary$X__3 32 | for (i in 1:dim(dictionary)[1]) { 33 | if (is.na(dictionary$X__3[i])) { 34 | dictionary$X__3[i] <- codcurrent 35 | } 36 | else { 37 | codcurrent <- dictionary$X__3[i] 38 | } 39 | } 40 | notlabel <- c("Ano", "Trimestre", "UPA", "ID_DOMICILIO", "Estrato", "V1008", "V1014", "V1016", 41 | "V1027", "V1028", sprintf("V1028%03d", seq(1:200)), "V1029", 42 | "V1030", "V1031", "V1032", sprintf("V1032%03d", seq(1:200)), 43 | "V1033", "V1034", "posest", "posest_sxi", 44 | "V1035", "V1036", sprintf("V1036%03d", seq(1:200)), "V1037", "V1038", 45 | "V1039", "V1040", sprintf("V1040%03d", seq(1:200)), "V1041", "V1042", 46 | "V2003", "V2008", "V20081", "V20082", 47 | "V40081", "V40082", "V40083", "V4010", "V4013", 48 | "V4041", "V4044", "V4075A1", "VD4031", "VD4035", 49 | "V401511", "V401512", "V40161", "V40162", "V40163", 50 | "V401711", "V40181", "V40182", "V40183", "S08002", 51 | "S080062", "S080063", "S08007", "S08008", "S080091", 52 | "S080192", "S080193", "S08020", "S08021", "S080221", 53 | "S080322", "S080323", "S08033", "S08034", "S080351", 54 | "S080442", "S0804431", "S080444", "S08044B", 55 | "S080462", "S0804631", "S080464", "S08046B", 56 | "Habitual", "Efetivo", "CO1", "CO1e", "CO2", "CO2e", "CO3") 57 | vars <- names(data_pnadc) 58 | varsc <- vars[sapply(data_pnadc, class) == "character"] 59 | varsf <- setdiff(varsc, notlabel) 60 | for (i in 1:length(varsf)) { 61 | if (i > 0 & varsf[i] %in% (dictionary$X__3)) { 62 | data_pnadc[varsf[i]] <- factor(suppressWarnings(as.numeric(unlist(data_pnadc[varsf[i]]))), 63 | levels=suppressWarnings(as.numeric(unlist(dictionary %>% subset(X__3 == varsf[i]) %>% select(X__6)))), 64 | labels=unlist(dictionary %>% subset(X__3 == varsf[i]) %>% select(X__7))) 65 | } 66 | } 67 | } 68 | else { 69 | message("The microdata object is not of the tibble class or sample design was already defined for microdata, so labeling categorical variables is not possible.\n") 70 | } 71 | return(data_pnadc) 72 | } 73 | -------------------------------------------------------------------------------- /R/read_pnadc.R: -------------------------------------------------------------------------------- 1 | #' Read PNADC microdata 2 | #' @description This function reads PNADC microdata. 3 | #' @import dplyr httr magrittr projmgr RCurl readr readxl survey tibble timeDate utils 4 | #' @param microdata A text file containing microdata from PNADC survey, available on official website:\cr Quarter (select a microdata file, according to the appropriated year and, then, quarter) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/}.\cr Annual per Interview (select a microdata file, according to the appropriated interview and, then, inside the data folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a microdata file, according to the appropriated quarter related to the topic and, then, inside the data folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}. 5 | #' @param input_txt A text file, related to the microdata, containing the input script for SAS, available on official website:\cr Quarter (select the dictionary and input zip file) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/}.\cr Annual per Interview (select a input txt file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a input txt file, according to the appropriated quarter related to the topic, inside the documentation folder) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}. 6 | #' @param vars Vector of variable names to be kept for analysis. Default is to keep all variables. 7 | #' @return A tibble with selected variables of the microdata, including the necessary survey design ones. 8 | #' @note For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 9 | #' @seealso \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 10 | #' @examples 11 | #' input_path <- pnadc_example(path="input_example.txt") 12 | #' data_path <- pnadc_example(path="exampledata.txt") 13 | #' pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 14 | #' @export 15 | 16 | read_pnadc <- function(microdata, input_txt, vars = NULL) { 17 | X1 = X2 = X3 = start = end = NULL 18 | input <- suppressWarnings(suppressMessages({readr::read_table(input_txt, col_names=FALSE) %>% subset(substr(X1, 1, 1) == "@") %>% 19 | dplyr::mutate(type=ifelse(substr(X3, 1, 1) == "$","c","d"), start=as.numeric(gsub("@", "", X1)), X3=as.integer(chartr("$", " ", X3)), end=start+X3-1)})) 20 | if (!is.null(vars)) { 21 | if (any(!(vars %in% input$X2))) { 22 | missvar <- vars[!(vars %in% input$X2)] 23 | message(paste("Variables", paste(missvar, collapse=", "), "not present in microdata.\n")) 24 | } 25 | input %<>% subset(X2 %in% c("Ano", "Trimestre", "UF", "UPA", "ID_DOMICILIO", "Estrato", "V1008", "V1014", "V1027", "V1028", sprintf("V1028%03d", seq(1:200)), "V1029", "V1030", "V1031", "V1032", sprintf("V1032%03d", seq(1:200)), "V1033", "V1034", "V1035", "V1036", sprintf("V1036%03d", seq(1:200)), "V1037", "V1038", "V1039", "V1040", sprintf("V1040%03d", seq(1:200)), "V1041", "V1042", "posest", "posest_sxi", "V2003", "S090000", "S12001A", vars)) 26 | } 27 | columns <- input %$% readr::fwf_positions(start, end, X2) 28 | data_pnadc <- suppressWarnings(readr::read_fwf(microdata, columns, col_types=paste0(input$type, collapse=""))) 29 | data_pnadc <- dplyr::mutate(data_pnadc, ID_DOMICILIO=paste0(data_pnadc$UPA, data_pnadc$V1008, data_pnadc$V1014)) 30 | return(data_pnadc) 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PNADcIBGE 2 | ## Downloading, Reading and Analyzing PNADC Microdata 3 | 4 | This R package provides tools for download, read, and analyze the Continuous National Household Sample Survey - PNADC from Brazilian Institute of Geography and Statistics - IBGE. 5 | 6 | ## Baixe, Leia e Analise os Microdados da PNAD Contínua 7 | 8 | Pacote em R com ferramentas para download, leitura e análise da Pesquisa Nacional por Amostra de Domicílios Contínua (PNAD Contínua) do Instituto Brasileiro de Geografia e Estatística (IBGE). 9 | 10 | [Manual em Português Disponível](https://rpubs.com/gabriel-assuncao-ibge/pnadc) 11 | 12 | [Pacotes das Pesquisas do SIPD](https://cran.r-project.org/package=SIPDIBGE) 13 | 14 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/PNADcIBGE)](https://cran.r-project.org/package=PNADcIBGE) [![CRAN monthly downloads](https://cranlogs.r-pkg.org/badges/PNADcIBGE "CRAN monthly downloads")](https://cran.r-project.org/package=PNADcIBGE) 15 | -------------------------------------------------------------------------------- /inst/extdata/deflatorexample.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/PNADcIBGE/c29ef7b8e997f137e817571ffd5f444efcfa5b59/inst/extdata/deflatorexample.xls -------------------------------------------------------------------------------- /inst/extdata/dictionaryexample.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/PNADcIBGE/c29ef7b8e997f137e817571ffd5f444efcfa5b59/inst/extdata/dictionaryexample.xls -------------------------------------------------------------------------------- /inst/extdata/input_example.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/PNADcIBGE/c29ef7b8e997f137e817571ffd5f444efcfa5b59/inst/extdata/input_example.txt -------------------------------------------------------------------------------- /man/get_pnadc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_pnadc.R 3 | \name{get_pnadc} 4 | \alias{get_pnadc} 5 | \title{Download, label, deflate and create survey design object for PNADC microdata} 6 | \usage{ 7 | get_pnadc( 8 | year, 9 | quarter = NULL, 10 | interview = NULL, 11 | topic = NULL, 12 | selected = FALSE, 13 | vars = NULL, 14 | defyear = NULL, 15 | defperiod = NULL, 16 | labels = TRUE, 17 | deflator = TRUE, 18 | design = TRUE, 19 | reload = TRUE, 20 | curlopts = list(), 21 | savedir = tempdir() 22 | ) 23 | } 24 | \arguments{ 25 | \item{year}{The year of the data to be downloaded. Must be a number between 2012 and current year. Vector not accepted.} 26 | 27 | \item{quarter}{The quarter of the year of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. If \code{NULL}, \code{interview} or \code{topic} number must be provided.} 28 | 29 | \item{interview}{The interview number of the data to be downloaded. Must be number from 1 to 5. Vector not accepted. Using this option will get annual per interview data. If \code{NULL}, \code{quarter} or \code{topic} number must be provided.} 30 | 31 | \item{topic}{The quarter related to the topic of the data to be downloaded. Must be number from 1 to 4. Vector not accepted. Using this option will get annual per topic data. If \code{NULL}, \code{quarter} or \code{interview} number must be provided.} 32 | 33 | \item{selected}{Logical value. If \code{TRUE}, the specific questionnaire for selected resident will be used. If \code{FALSE}, the basic questionnaire for household and residents will be used. For more information about these supplemental topics, please check the survey official website.} 34 | 35 | \item{vars}{Vector of variable names to be kept for analysis. Default is to keep all variables.} 36 | 37 | \item{defyear}{The year of the deflator data to be downloaded for annual microdata. Must be a number between 2017 and the last available year. Vector not accepted. If \code{NULL}, the deflator year will be defined as the last year available for interview microdata, or as equal to \code{year} for topic microdata. When \code{quarter} is defined, this argument will be ignored. This argument will be used only if \code{deflator} was set as \code{TRUE}.} 38 | 39 | \item{defperiod}{The quarter period of the deflator data to be downloaded for annual per topic microdata. Must be number from 1 to 4. Vector not accepted. If \code{NULL}, the deflator period will be defined as equal to \code{topic}. When \code{quarter} or \code{interview} is defined, this argument will be ignored. This argument will be used only if \code{deflator} was set as \code{TRUE}.} 40 | 41 | \item{labels}{Logical value. If \code{TRUE}, categorical variables will presented as factors with labels corresponding to the survey's dictionary.} 42 | 43 | \item{deflator}{Logical value. If \code{TRUE}, deflator variables will be available for use in the microdata.} 44 | 45 | \item{design}{Logical value. If \code{TRUE}, will return an object of class \code{survey.design} or \code{svyrep.design}. It is strongly recommended to keep this parameter as \code{TRUE} for further analysis. If \code{FALSE}, only the microdata will be returned.} 46 | 47 | \item{reload}{Logical value. If \code{TRUE}, will re-download the files even if they already exist in the save directory. If \code{FALSE}, will be checked if the files already exist in the save directory and the download will not be performed repeatedly, be careful with coinciding names of microdata files.} 48 | 49 | \item{curlopts}{A named list object identifying the curl options for the handle when using functions from \code{RCurl} package.} 50 | 51 | \item{savedir}{Directory to save the downloaded data. Default is to use a temporary directory.} 52 | } 53 | \value{ 54 | An object of class \code{survey.design} or \code{svyrep.design} with the data from PNADC and its sample design, or a tibble with selected variables of the microdata, including the necessary survey design ones. 55 | } 56 | \description{ 57 | Core function of package. With this function only, the user can download a PNADC microdata from a year or quarter and get a sample design object ready to use with \code{survey} package functions. 58 | } 59 | \note{ 60 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 61 | } 62 | \examples{ 63 | \donttest{ 64 | pnadc.svy <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 65 | defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 66 | reload=TRUE, curlopts=list(), savedir=tempdir()) 67 | # Calculating proportion of employed and unemployed people 68 | if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE) 69 | pnadc.svy2 <- get_pnadc(year=2017, interview=5, selected=FALSE, vars=c("V4112","V4121B"), 70 | defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 71 | reload=TRUE, curlopts=list(), savedir=tempdir()) 72 | # Calculating average hours dedicated to the care of people or household chores 73 | if (!is.null(pnadc.svy2)) survey::svymean(x=~V4121B, design=pnadc.svy2, na.rm=TRUE) 74 | pnadc.svy3 <- get_pnadc(year=2017, topic=4, selected=FALSE, vars=c("S07006","S07007"), 75 | defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=TRUE, 76 | reload=TRUE, curlopts=list(), savedir=tempdir()) 77 | # Calculating proportion of cell phone for personal use with internet access 78 | if (!is.null(pnadc.svy3)) survey::svymean(x=~S07007, design=pnadc.svy3, na.rm=TRUE)} 79 | } 80 | \seealso{ 81 | \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 82 | } 83 | -------------------------------------------------------------------------------- /man/pnadc_deflator.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pnadc_deflator.R 3 | \name{pnadc_deflator} 4 | \alias{pnadc_deflator} 5 | \title{Add deflator variables to PNADC microdata} 6 | \usage{ 7 | pnadc_deflator(data_pnadc, deflator.file) 8 | } 9 | \arguments{ 10 | \item{data_pnadc}{A tibble of PNADC microdata read with \code{read_pnadc} function.} 11 | 12 | \item{deflator.file}{The deflator file for selected survey available on official website:\cr Quarter (select the deflator zip file) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/}.\cr Annual per Interview (select a deflator xls file, according to the appropriated year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/Documentacao_Geral/}.\cr Annual per Topic (select a deflator xls file, according to the appropriated period and, then, inside the documentation folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}.} 13 | } 14 | \value{ 15 | A tibble with the data provided from PNADC survey and the deflator variables added for use. 16 | } 17 | \description{ 18 | This function adds deflator variables to PNADC microdata. For deflation of income variables, the documentation provided through the following addresses must be used:\cr Quarter - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/PNADcIBGE_Deflator_Trimestral.pdf}.\cr Annual per Interview - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/Documentacao_Geral/PNADcIBGE_Deflator_Anual_Visita.pdf}.\cr Annual per Topic - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/Documentacao_Geral/PNADcIBGE_Deflator_Anual_Trimestre.pdf}. 19 | } 20 | \note{ 21 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 22 | } 23 | \examples{ 24 | # Using data read from disk 25 | input_path <- pnadc_example(path="input_example.txt") 26 | data_path <- pnadc_example(path="exampledata.txt") 27 | dictionary.path <- pnadc_example(path="dictionaryexample.xls") 28 | deflator.path <- pnadc_example(path="deflatorexample.xls") 29 | pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 30 | pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 31 | pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path) 32 | \donttest{ 33 | # Downloading data 34 | pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 35 | defyear=2017, defperiod=4, labels=TRUE, deflator=FALSE, design=FALSE, 36 | reload=TRUE, curlopts=list(), savedir=tempdir()) 37 | deflator.path2 <- pnadc_example(path="deflatorexample.xls") 38 | pnadc.df2 <- pnadc_deflator(data_pnadc=pnadc.df2, deflator.file=deflator.path2)} 39 | } 40 | \seealso{ 41 | \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 42 | } 43 | -------------------------------------------------------------------------------- /man/pnadc_design.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pnadc_design.R 3 | \name{pnadc_design} 4 | \alias{pnadc_design} 5 | \title{Create PNADC survey object with its sample design} 6 | \usage{ 7 | pnadc_design(data_pnadc) 8 | } 9 | \arguments{ 10 | \item{data_pnadc}{A tibble of PNADC microdata read with \code{read_pnadc} function.} 11 | } 12 | \value{ 13 | An object of class \code{survey.design} or \code{svyrep.design} with the data from PNADC and its sample design. 14 | } 15 | \description{ 16 | This function creates PNADC survey object with its sample design for analysis using \code{survey} package functions. 17 | } 18 | \note{ 19 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 20 | } 21 | \examples{ 22 | # Using data read from disk 23 | input_path <- pnadc_example(path="input_example.txt") 24 | data_path <- pnadc_example(path="exampledata.txt") 25 | dictionary.path <- pnadc_example(path="dictionaryexample.xls") 26 | deflator.path <- pnadc_example(path="deflatorexample.xls") 27 | pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 28 | pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 29 | pnadc.df <- pnadc_deflator(data_pnadc=pnadc.df, deflator.file=deflator.path) 30 | \donttest{ 31 | pnadc.svy <- pnadc_design(data_pnadc=pnadc.df) 32 | # Calculating proportion of employed and unemployed people 33 | if (!is.null(pnadc.svy)) survey::svymean(x=~VD4002, design=pnadc.svy, na.rm=TRUE)} 34 | \donttest{ 35 | # Downloading data 36 | pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 37 | defyear=2017, defperiod=4, labels=TRUE, deflator=TRUE, design=FALSE, 38 | reload=TRUE, curlopts=list(), savedir=tempdir()) 39 | pnadc.svy2 <- pnadc_design(data_pnadc=pnadc.df2) 40 | # Calculating proportion of employed and unemployed people 41 | if (!is.null(pnadc.svy2)) survey::svymean(x=~VD4002, design=pnadc.svy2, na.rm=TRUE)} 42 | } 43 | \seealso{ 44 | \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 45 | } 46 | -------------------------------------------------------------------------------- /man/pnadc_example.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/example.R 3 | \name{pnadc_example} 4 | \alias{pnadc_example} 5 | \title{Get the path of the quarter PNADC toy example files} 6 | \usage{ 7 | pnadc_example(path = NULL) 8 | } 9 | \arguments{ 10 | \item{path}{Name of file. If \code{NULL}, the quarter PNADC toy example files names will be listed.} 11 | } 12 | \value{ 13 | A vector with names of all the available quarter PNADC toy example files or the path for specific requested quarter PNADC toy example file. 14 | } 15 | \description{ 16 | This function provides the path of the microdata from quarter 4 of year 2017 of the PNADC toy example files, loaded with this package. 17 | } 18 | \note{ 19 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 20 | } 21 | \examples{ 22 | pnadc_example() 23 | pnadc_example(path="exampledata.txt") 24 | pnadc_example(path="input_example.txt") 25 | pnadc_example(path="dictionaryexample.xls") 26 | pnadc_example(path="deflatorexample.xls") 27 | } 28 | \seealso{ 29 | \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object. 30 | } 31 | -------------------------------------------------------------------------------- /man/pnadc_labeller.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pnadc_labeller.R 3 | \name{pnadc_labeller} 4 | \alias{pnadc_labeller} 5 | \title{Label categorical variables from PNADC microdata} 6 | \usage{ 7 | pnadc_labeller(data_pnadc, dictionary.file) 8 | } 9 | \arguments{ 10 | \item{data_pnadc}{A tibble of PNADC microdata read with \code{read_pnadc} function.} 11 | 12 | \item{dictionary.file}{The dictionary file for selected survey available on official website:\cr Quarter (select the dictionary and input zip file) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/}.\cr Annual per Interview (select a dictionary xls file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a dictionary xls file, according to the appropriated quarter related to the topic, inside the documentation folder) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}.} 13 | } 14 | \value{ 15 | A tibble with the data provided from PNADC survey and its categorical variables as factors with related labels. 16 | } 17 | \description{ 18 | This function labels categorical variables from PNADC microdata. 19 | } 20 | \note{ 21 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 22 | } 23 | \examples{ 24 | # Using data read from disk 25 | input_path <- pnadc_example(path="input_example.txt") 26 | data_path <- pnadc_example(path="exampledata.txt") 27 | dictionary.path <- pnadc_example(path="dictionaryexample.xls") 28 | pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 29 | pnadc.df <- pnadc_labeller(data_pnadc=pnadc.df, dictionary.file=dictionary.path) 30 | \donttest{ 31 | # Downloading data 32 | pnadc.df2 <- get_pnadc(year=2017, quarter=4, selected=FALSE, vars=c("VD4001","VD4002"), 33 | defyear=2017, defperiod=4, labels=FALSE, deflator=FALSE, design=FALSE, 34 | reload=TRUE, curlopts=list(), savedir=tempdir()) 35 | dictionary.path2 <- pnadc_example(path="dictionaryexample.xls") 36 | pnadc.df2 <- pnadc_labeller(data_pnadc=pnadc.df2, dictionary.file=dictionary.path2)} 37 | } 38 | \seealso{ 39 | \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{read_pnadc} for reading PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 40 | } 41 | -------------------------------------------------------------------------------- /man/read_pnadc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_pnadc.R 3 | \name{read_pnadc} 4 | \alias{read_pnadc} 5 | \title{Read PNADC microdata} 6 | \usage{ 7 | read_pnadc(microdata, input_txt, vars = NULL) 8 | } 9 | \arguments{ 10 | \item{microdata}{A text file containing microdata from PNADC survey, available on official website:\cr Quarter (select a microdata file, according to the appropriated year and, then, quarter) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/}.\cr Annual per Interview (select a microdata file, according to the appropriated interview and, then, inside the data folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a microdata file, according to the appropriated quarter related to the topic and, then, inside the data folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}.} 11 | 12 | \item{input_txt}{A text file, related to the microdata, containing the input script for SAS, available on official website:\cr Quarter (select the dictionary and input zip file) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Trimestral/Microdados/Documentacao/}.\cr Annual per Interview (select a input txt file, according to the appropriated interview and, then, inside the documentation folder, choose the desired year) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Visita/}.\cr Annual per Topic (select a input txt file, according to the appropriated quarter related to the topic, inside the documentation folder) - \url{https://ftp.ibge.gov.br/Trabalho_e_Rendimento/Pesquisa_Nacional_por_Amostra_de_Domicilios_continua/Anual/Microdados/Trimestre/}.} 13 | 14 | \item{vars}{Vector of variable names to be kept for analysis. Default is to keep all variables.} 15 | } 16 | \value{ 17 | A tibble with selected variables of the microdata, including the necessary survey design ones. 18 | } 19 | \description{ 20 | This function reads PNADC microdata. 21 | } 22 | \note{ 23 | For more information, visit the survey official website <\url{https://www.ibge.gov.br/estatisticas/sociais/trabalho/9171-pesquisa-nacional-por-amostra-de-domicilios-continua-mensal.html?=&t=o-que-e}> and consult the other functions of this package, described below. 24 | } 25 | \examples{ 26 | input_path <- pnadc_example(path="input_example.txt") 27 | data_path <- pnadc_example(path="exampledata.txt") 28 | pnadc.df <- read_pnadc(microdata=data_path, input_txt=input_path, vars=c("VD4001","VD4002")) 29 | } 30 | \seealso{ 31 | \link[PNADcIBGE]{get_pnadc} for downloading, labeling, deflating and creating survey design object for PNADC microdata.\cr \link[PNADcIBGE]{pnadc_labeller} for labeling categorical variables from PNADC microdata.\cr \link[PNADcIBGE]{pnadc_deflator} for adding deflator variables to PNADC microdata.\cr \link[PNADcIBGE]{pnadc_design} for creating PNADC survey design object.\cr \link[PNADcIBGE]{pnadc_example} for getting the path of the quarter PNADC toy example files. 32 | } 33 | --------------------------------------------------------------------------------