Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(survey)
library(lodown)
cpsasec_cat <- get_catalog( "cpsasec" , output_dir = tempdir() )
lodown( "cpsasec" , subset( cpsasec_cat , year == 2017 ) )
plot(
c( 15 , 75 ) ,
c( 0 , .03 ) ,
type = 'n' ,
axes = F ,
xlab = '' ,
ylab = '' ,
main = 'share of total nationwide earned income\nreceived by individuals of different ages' ,
sub = '2016 earnings from the 2017 cps-asec'
)
axis( 1 )
axis( 2 , at = c( 0 , 0.01 , 0.02 , 0.03 ) , labels = c( '0%' , '1%' , '2%' , '3%' ) )
cpsasec_df <-
readRDS( paste0( tempdir() , "/2017 cps asec.rds" ) )
cpsasec_design <-
svrepdesign(
weights = ~ marsupwt ,
repweights = "pwwgt[1-9]" ,
type = "Fay" ,
rho = ( 1 - 1 / sqrt( 4 ) ) ,
data = cpsasec_df ,
combined.weights = TRUE ,
mse = TRUE
)
overall <- data.frame( svytotal( ~ pearnval , cpsasec_design ) )
by_age <-
data.frame(
svyby( ~ pearnval , ~ a_age , cpsasec_design , svytotal )
)
share_by_age <- by_age[ by_age$a_age %in% 15:75 , 2 ] / overall$total
lines( 15:75 , share_by_age )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.