1.5 Pesquisa Nacional por Amostra de Domicílios Contínua (PNAD Contínua)

Administered by the Instituto Brasileiro de Geografia e Estatística (IBGE), the PNAD Contínua is the primary source of labor force statistics for the population of Brazil.

This section downloads, imports, and prepares the most current microdata for analysis, then reproduces some statistics and margins of error from IBGE.1 See this link for IBGE Gini coefficient estimates reproduced below.

Download and import the 2022 5th interview file:

library(PNADcIBGE)

pnadc_df <-
  get_pnadc(2022 ,
            interview = 5 ,
            design = FALSE ,
            labels = FALSE ,
            defyear = 2022)

names(pnadc_df) <- tolower(names(pnadc_df))

Recode a number of variables:

pnadc_df <-
  transform(
    pnadc_df ,
    
    household_id = paste0(upa , v1008 , v1014) ,
    
    deflated_labor_income = vd4019 * co2 ,
    
    deflated_other_source_income = vd4048 * co2e
  )

labor_income_sum_df <-
  aggregate(
    cbind(household_deflated_labor_income = deflated_labor_income) ~ household_id ,
    data = pnadc_df[!(pnadc_df[, 'vd2002'] %in% 17:19) ,] ,
    sum ,
    na.rm = TRUE
  )

other_income_sum_df <-
  aggregate(
    cbind(household_deflated_other_source_income = deflated_other_source_income) ~ household_id ,
    data = pnadc_df[!(pnadc_df[, 'vd2002'] %in% 17:19) ,] ,
    sum ,
    na.rm = TRUE
  )

before_nrow <- nrow(pnadc_df)
pnadc_df <- merge(pnadc_df , labor_income_sum_df , all.x = TRUE)
pnadc_df <- merge(pnadc_df , other_income_sum_df , all.x = TRUE)
stopifnot(nrow(pnadc_df) == before_nrow)

pnadc_df[is.na(pnadc_df[, 'household_deflated_labor_income']) , 'household_deflated_labor_income'] <-
  0
pnadc_df[is.na(pnadc_df[, 'household_deflated_other_source_income']) , 'household_deflated_other_source_income'] <-
  0



pnadc_df <-
  transform(
    pnadc_df ,
    
    deflated_per_capita_income =
      (
        household_deflated_labor_income + household_deflated_other_source_income
      ) / vd2003 ,
    
    sex = factor(
      v2007 ,
      levels = 1:2 ,
      labels = c('male' , 'female')
    )
    
  )

Construct a complex sample survey design:

library(survey)

pnadc_design <-
  svrepdesign(
    data = pnadc_df ,
    weight = ~ v1032,
    type = "bootstrap" ,
    repweights = "v1032[0-9]{3}" ,
    mse = TRUE
  )

Run the convey_prep() function on the full design:

pnadc_design <- convey_prep(pnadc_design)

Analysis Examples with the survey library  

Add new columns to the data set:

pnadc_design <-
  update(pnadc_design ,
         
         pia = as.numeric(v2009 >= 14))

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)
  )

pnadc_design <-
  
  update(
    pnadc_design ,
    
    one = 1 ,
    
    uf_name =
      
      factor(
        as.numeric(uf) ,
        
        levels =
          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
          ) ,
        
        labels =
          c(
            "Rondonia",
            "Acre",
            "Amazonas",
            "Roraima",
            "Para",
            "Amapa",
            "Tocantins",
            "Maranhao",
            "Piaui",
            "Ceara",
            "Rio Grande do Norte",
            "Paraiba",
            "Pernambuco",
            "Alagoas",
            "Sergipe",
            "Bahia",
            "Minas Gerais",
            "Espirito Santo",
            "Rio de Janeiro",
            "Sao Paulo",
            "Parana",
            "Santa Catarina",
            "Rio Grande do Sul",
            "Mato Grosso do Sul",
            "Mato Grosso",
            "Goias",
            "Distrito Federal"
          )
        
      ) ,
    
    age_categories = factor(1 + findInterval(v2009 , seq(5 , 60 , 5))) ,
    
    male = as.numeric(v2007 == 1) ,
    
    region = substr(uf , 1 , 1) ,
    
    # 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 the potential labor force
    pea_c = as.numeric(ocup_c == 1 | desocup30 == 1)
    
  )

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 )

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

svytotal( ~ one , pnadc_design )

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

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 , na.rm = TRUE
)

Estimate a ratio:

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

Restrict the survey design to employed persons:

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

Calculate the mean (average) of this subset:

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

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 (nominal) design 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" )

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 )

1.5.1 Per Capita Income

Calculate the Gini coefficient with per capita income:

# https://sidra.ibge.gov.br/tabela/7435#/n1/all/v/all/p/last%202/d/v10681%203,v10682%201/l/v,p,t/resultado

(
  pnadc_per_capita_gini <-
    svygini( ~ deflated_per_capita_income , pnadc_design , na.rm = TRUE)
)
##                               gini     SE
## deflated_per_capita_income 0.51845 0.0032
# match 2022 per_capita gini coefficient
stopifnot(round(coef(pnadc_per_capita_gini) , 3) == 0.518)

# match 2022 per_capita gini coefficient of variation
stopifnot(round(cv(pnadc_per_capita_gini), 3) == 0.006) 

1.5.2 Worker Earnings

Estimate the Gini coefficient with total earnings:

# https://sidra.ibge.gov.br/tabela/7453#/n1/all/v/all/p/last%202/d/v10806%203,v10807%201/l/v,p,t/resultado

(pnadc_earnings_gini <-
   svygini( ~ deflated_labor_income , pnadc_design , na.rm = TRUE))
##                          gini     SE
## deflated_labor_income 0.48606 0.0036
# match 2022 earnings gini coefficient
stopifnot(round(coef(pnadc_earnings_gini) , 3) == 0.486)

# match 2022 earnings gini coefficient of variation
stopifnot(round(cv(pnadc_earnings_gini), 3) == 0.007)