Skip to content

Commit

Permalink
scf draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdamico committed Mar 27, 2023
1 parent 3b8db02 commit 2d8c841
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions tests/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ scf_MIcombine( with( scf_design ,
scf_MIcombine( with( scf_design ,
svyquantile(
~ networth ,
0.5 , se = TRUE , method = 'constant' , interval.type = 'quantile'
0.5 , se = TRUE , interval.type = 'quantile'
) ) )

scf_MIcombine( with( scf_design ,
svyby(
~ networth , ~ hhsex , svyquantile ,
0.5 , se = TRUE , method = 'constant' , interval.type = 'quantile' ,
0.5 , se = TRUE , interval.type = 'quantile' ,
ci = TRUE
) ) )
scf_MIcombine( with( scf_design ,
Expand Down Expand Up @@ -274,26 +274,14 @@ stopifnot( round( coef( mean_net_worth ) / 1000 , 2 ) == 746.82 )
# https://www.federalreserve.gov/publications/files/scf20.pdf#page=11
stopifnot( abs( 15.6 - round( SE( mean_net_worth ) / 1000 , 1 ) ) < 0.1 )

# compute median net worth using the 2019 PUF
median_net_worth <-
scf_MIcombine( with( scf_design ,
svyquantile(
~ networth ,
0.5 , se = TRUE , method = 'constant' , interval.type = 'quantile' ,
ci = TRUE
) ) )

# for( this_qrule in c("math","school","shahvaish","hf1","hf2","hf3",
# "hf4","hf5","hf6","hf7","hf8","hf9") ){
# print( this_qrule )
# print( scf_MIcombine( with( scf_design , svyquantile( ~ networth , 0.5 , interval.type = 'quantile' , qrule = this_qrule ) ) ) )
# }

# confirm the estimate and standard error match FRB calculations within one dollar
# stopifnot( round( coef( median_net_worth ) ) == 97306 )
# stopifnot( round( SE( median_net_worth ) ) == 2699 )

# scf_MIcombine( with( scf_design , oldsvyquantile( ~networth , 0.5 , method = 'constant' , interval.type = 'quantile' ) ) )
# compute quantile with all five implicates stacked
# matches the public excel tables but not the recommended technique
fake_design <- svydesign( ~ 1 , data = p_df[ c( 'networth' , 'wgt' ) ] , weights = ~ wgt )
median_net_worth_incorrect_errors <- svyquantile( ~ networth , fake_design , 0.5 )

# exactly match "Table 4" tab cell V6 of
# https://www.federalreserve.gov/econres/files/scf2019_tables_public_nominal_historical.xlsx
stopifnot( round( coef( median_net_worth_incorrect_errors ) / 1000 , 2 ) == 121.76 )
library(convey)
scf_design$designs <- lapply( scf_design$designs , convey_prep )

Expand Down

0 comments on commit 2d8c841

Please sign in to comment.