Created
May 17, 2018 09:38
-
-
Save ajdamico/0044da842846c240a391cad7e879f10b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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