Pesquisa Nacional por Amostra de Domicilios - Continua (PNADC)

Build Status Build status

Contributed by Dr. Djalma Pessoa <pessoad@gmail.com>

Brazil’s principal household survey, the Pesquisa Nacional por Amostra de Domicilios Continua (PNADC) measures general education, labor, income, and housing characteristics of the population.

  • One table with one row per sampled household and a second table with one row per individual within each sampled household.

  • A complex sample survey designed to generalize to the civilian non-institutional population of Brazil.

  • Released quarterly since 2012.

  • Administered by the Instituto Brasileiro de Geografia e Estatistica.

Simplified Download and Importation

The R lodown package easily downloads and imports all available PNADC microdata by simply specifying "pnadc" with an output_dir = parameter in the lodown() function. Depending on your internet connection and computer processing speed, you might prefer to run this step overnight.

library(lodown)
lodown( "pnadc" , output_dir = file.path( path.expand( "~" ) , "PNADC" ) )

lodown also provides a catalog of available microdata extracts with the get_catalog() function. After requesting the PNADC catalog, you could pass a subsetted catalog through the lodown() function in order to download and import specific extracts (rather than all available extracts).

library(lodown)
# examine all available PNADC microdata files
pnadc_cat <-
    get_catalog( "pnadc" ,
        output_dir = file.path( path.expand( "~" ) , "PNADC" ) )

# 2015 3rd quarter only
pnadc_cat <- subset( pnadc_cat , year == 2015 & quarter == '03' )
# download the microdata to your local computer
lodown( "pnadc" , pnadc_cat )

Analysis Examples with the survey library  

Construct a complex sample survey design:

library(survey)

options( survey.lonely.psu = "adjust" )

pnadc_df <- readRDS( file.path( path.expand( "~" ) , "PNADC" , "pnadc 2015 03.rds" ) )

# add a column of all ones
pnadc_df$one <- 1

# construct a data.frame object with all state names.
uf <-
 structure(list(V1 = c(11L, 12L, 13L, 14L, 15L, 16L, 17L, 21L, 
 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 31L, 32L, 33L, 35L, 41L, 
 42L, 43L, 50L, 51L, 52L, 53L), V2 = structure(c(22L, 1L, 4L, 
 23L, 14L, 3L, 27L, 10L, 18L, 6L, 20L, 15L, 17L, 2L, 26L, 5L, 
 13L, 8L, 19L, 25L, 16L, 24L, 21L, 12L, 11L, 9L, 7L), .Label = c("Acre", 
 "Alagoas", "Amapa", "Amazonas", "Bahia", "Ceara", "Distrito Federal", 
 "Espirito Santo", "Goias", "Maranhao", "Mato Grosso", "Mato Grosso do Sul", 
 "Minas Gerais", "Para", "Paraiba", "Parana", "Pernambuco", "Piaui", 
 "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", 
 "Rondonia", "Roraima", "Santa Catarina", "Sao Paulo", "Sergipe", 
 "Tocantins"), class = "factor")), .Names = c("uf", "uf_name"), 
        class = "data.frame", row.names = c(NA, -27L))

# merge this data.frame onto the main `x` data.frame
# using `uf` as the merge field, keeping all non-matches.
pnadc_df <- merge( pnadc_df , uf , all.x = TRUE )

# confirm complete matches
stopifnot( all( !is.na( pnadc_df$uf_name ) ) )

# preliminary survey design
pre_stratified <-
    svydesign(
        ids = ~ upa , 
        strata = ~ estrato , 
        weights = ~ v1027 , 
        data = pnadc_df ,
        nest = TRUE
    )
# warning: do not use `pre_stratified` in your analyses!
# you must use the `pnadc_design` object created below.

# post-stratification targets
df_pos <- 
    data.frame( posest = unique( pnadc_df$posest ) , Freq = unique( pnadc_df$v1029 ) )

# final survey design object
pnadc_design <- postStratify( pre_stratified , ~ posest , df_pos )

# remove the `pnadc_df` data.frame object
# and the `pre_stratified` design before stratification
rm( pnadc_df , pre_stratified )

Variable Recoding

Add new columns to the data set:

pnadc_design <- 
    update( 
        pnadc_design , 
        age_categories = factor( 1 + findInterval( v2009 , seq( 5 , 60 , 5 ) ) ) ,
        male = as.numeric( v2007 == 1 ) ,
        pia = as.numeric( v2009 >= 14 ) ,
        region = substr( uf , 1 , 1 )
    )
    
pnadc_design <- 
    update( 
        pnadc_design , 
        ocup_c = ifelse( pia == 1 , as.numeric( vd4002 %in% 1 ) , NA ) ,
        desocup30 = ifelse( pia == 1 , as.numeric( vd4002 %in% 2 ) , NA ) ,
        # calculate usual income from main job
        # (rendimento habitual do trabalho principal)
        vd4016n = ifelse( pia %in% 1 & vd4015 %in% 1 , vd4016 , NA ) ,
        # calculate effective income from main job
        # (rendimento efetivo do trabalho principal) 
        vd4017n = ifelse( pia %in% 1 & vd4015 %in% 1 , vd4017 , NA ) ,
        # calculate usual income from all jobs
        # (variavel rendimento habitual de todos os trabalhos)
        vd4019n = ifelse( pia %in% 1 & vd4015 %in% 1 , vd4019 , NA ) ,
        # calculate effective income from all jobs
        # (rendimento efetivo do todos os trabalhos) 
        vd4020n = ifelse( pia %in% 1 & vd4015 %in% 1 , vd4020 , NA ) ,
        # determine individuals who are either working or not working
        # (that is, the potential labor force)
        pea_c = as.numeric( ocup_c == 1 | desocup30 == 1 )
    )

Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

sum( weights( pnadc_design , "sampling" ) != 0 )

svyby( ~ one , ~ uf_name , pnadc_design , unwtd.count )

Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

svytotal( ~ one , pnadc_design )

svyby( ~ one , ~ uf_name , pnadc_design , svytotal )

Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

svymean( ~ vd4020n , pnadc_design , na.rm = TRUE )

svyby( ~ vd4020n , ~ uf_name , pnadc_design , svymean , na.rm = TRUE )

Calculate the distribution of a categorical variable, overall and by groups:

svymean( ~ age_categories , pnadc_design )

svyby( ~ age_categories , ~ uf_name , pnadc_design , svymean )

Calculate the sum of a linear variable, overall and by groups:

svytotal( ~ vd4020n , pnadc_design , na.rm = TRUE )

svyby( ~ vd4020n , ~ uf_name , pnadc_design , svytotal , na.rm = TRUE )

Calculate the weighted sum of a categorical variable, overall and by groups:

svytotal( ~ age_categories , pnadc_design )

svyby( ~ age_categories , ~ uf_name , pnadc_design , svytotal )

Calculate the median (50th percentile) of a linear variable, overall and by groups:

svyquantile( ~ vd4020n , pnadc_design , 0.5 , na.rm = TRUE )

svyby( 
    ~ vd4020n , 
    ~ uf_name , 
    pnadc_design , 
    svyquantile , 
    0.5 ,
    ci = TRUE ,
    keep.var = TRUE ,
    na.rm = TRUE
)

Estimate a ratio:

svyratio( 
    numerator = ~ ocup_c , 
    denominator = ~ pea_c , 
    pnadc_design ,
    na.rm = TRUE
)

Subsetting

Restrict the survey design to unemployed persons in the labor force:

sub_pnadc_design <- subset( pnadc_design , desocup30 == 1 )

Calculate the mean (average) of this subset:

svymean( ~ vd4020n , sub_pnadc_design , na.rm = TRUE )

Measures of Uncertainty

Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:

this_result <- svymean( ~ vd4020n , pnadc_design , na.rm = TRUE )

coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )

grouped_result <-
    svyby( 
        ~ vd4020n , 
        ~ uf_name , 
        pnadc_design , 
        svymean ,
        na.rm = TRUE 
    )
    
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )

Calculate the degrees of freedom of any survey design object:

degf( pnadc_design )

Calculate the complex sample survey-adjusted variance of any statistic:

svyvar( ~ vd4020n , pnadc_design , na.rm = TRUE )

Include the complex sample design effect in the result for a specific statistic:

# SRS without replacement
svymean( ~ vd4020n , pnadc_design , na.rm = TRUE , deff = TRUE )

# SRS with replacement
svymean( ~ vd4020n , pnadc_design , na.rm = TRUE , deff = "replace" )

Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop for alternatives:

svyciprop( ~ male , pnadc_design ,
    method = "likelihood" )

Regression Models and Tests of Association

Perform a design-based t-test:

svyttest( vd4020n ~ male , pnadc_design )

Perform a chi-squared test of association for survey data:

svychisq( 
    ~ male + age_categories , 
    pnadc_design 
)

Perform a survey-weighted generalized linear model:

glm_result <- 
    svyglm( 
        vd4020n ~ male + age_categories , 
        pnadc_design 
    )

summary( glm_result )

Poverty and Inequality Estimation with convey  

The R convey library estimates measures of income concentration, poverty, inequality, and wellbeing. This textbook details the available features. As a starting point for PNADC users, this code calculates the gini coefficient on complex sample survey data:

library(convey)
pnadc_design <- convey_prep( pnadc_design )

sub_pnadc_design <- 
    subset( pnadc_design , pia == 1 )

svygini( ~ vd4020n , sub_pnadc_design , na.rm = TRUE )

Replication Example

nationwide_pop <- 
    svytotal( ~ pia , pnadc_design , na.rm = TRUE )
nationwide_forca <- 
    svytotal( ~ factor( vd4001 ) , pnadc_design , na.rm = TRUE )
nationwide_ocupacao <- 
    svytotal( ~ factor( vd4002 ) , pnadc_design , na.rm = TRUE )
regional_pop <- 
    svyby( ~ pia , ~ region , pnadc_design , svytotal , na.rm = TRUE )
regional_forca <- 
    svyby( ~ factor( vd4001 ) , ~ region , pnadc_design , svytotal , na.rm = TRUE )
regional_ocupacao <- 
    svyby( ~ factor( vd4002 ) , ~ region , pnadc_design , svytotal , na.rm = TRUE )