asdfree icon indicating copy to clipboard operation
asdfree copied to clipboard

add `income concentration examples.R` script to SCF

Open ajdamico opened this issue 8 years ago • 4 comments

showing simple usage of main convey functions

https://github.com/ajdamico/asdfree/tree/master/Survey%20of%20Consumer%20Finances

ajdamico avatar Mar 12 '16 14:03 ajdamico

convey_prep on a multiply-imputed design is easy

# # # # # # # # # # # # # # #
# convey_prep application on a multiply-imputed survey design object!
scf.design$designs <- lapply( scf.design$designs , convey_prep )
# # # # # # # # # # # # # # #

ajdamico avatar Mar 12 '16 16:03 ajdamico

here's my first draft of this script.. https://github.com/ajdamico/asdfree/commit/41eec71966eb584f3bce64487e70735f639dac38

djalma, are we able to use convey to replicate the percentile ratios here? http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4200506/table/T5/

or any other numbers in this paper? http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4200506/

i'm not sure what other measures of income concentration we should consider adding to these example scripts, but it's nice to replicate published articles!

ajdamico avatar Mar 14 '16 22:03 ajdamico

This is an example of estimating the ratio o quantiles and the se:

library(convey) library(vardpoor) data(eusilc) library(survey) # linearized design des_eusilc <- svydesign( ids = ~rb030 , strata = ~db040 , weights = ~rb050 , data = eusilc )

  q50 <- svyiqalpha( ~eqIncome , design = des_eusilc, .50 )
  q25 <- svyiqalpha( ~eqIncome , design = des_eusilc, .25 )

  # ratio of quantiles

  q25_list <- list(value = coef(q25), lin = attr(q25, "lin"))
  q50_list <- list(value = coef(q50), lin = attr(q50, "lin"))
  list_all <- list(Q25 = q25_list, Q50 = q50_list )
  Rquant<- contrastinf(quote(Q50/Q25), list_all)




  # estimate
  Rquant$value

  # se estimate

  variance <- svyrecvar(Rquant$lin/des_eusilc $prob, des_eusilc $cluster, des_eusilc $strata, 
  des_eusilc $fpc, postStrata = des_eusilc $postStrata)

  sqrt(variance)

DjalmaPessoa avatar Mar 15 '16 14:03 DjalmaPessoa

you probably can use the code in this commit to replicate those other numbers..

https://github.com/ajdamico/asdfree/commit/ace287311b27b5240a2f3ed72e88e70747cf800c

ajdamico avatar Mar 15 '16 19:03 ajdamico