Это ответ, который я придумал после изучения того, что прокомментировал Энтони Дамико:
Это следует за формой размещения кадров данных в списке вменений и копируемых файлов весов, чтобы в конечном итоге объединить их в svyimputationList.
scf_cat <-
get_catalog( "scf" ,
output_dir = file.path( path.expand( "~" ) , "SCF" ) )
yearslist <- list(10,13,16)
y1<- NULL
y2<- NULL
y3<- NULL
y4<- NULL
y5<- NULL
imp <- NULL
rw <- NULL
#loop to load in the desired years and assign the weights
for (i in 1:length(yearslist)){
year <- yearslist[i]
fullyear <- as.numeric(paste0("20",year))
df1 = scf_cat[FALSE,]
df1 <- subset( scf_cat , year == fullyear )
df2 <- lodown( "scf" , df1)
scf_imp <- readRDS( file.path( path.expand( "~" ) , "SCF" , paste0("scf ",fullyear,".rds" ) ))
for( i in 1:length(scf_imp)){
scf_imp[[i]][["year"]] <- fullyear
scf_imp[[i]] <- select(scf_imp[[i]],c("yy1","one","year","wgt","edcl","hhsex","age","married","kids","lf","lifecl",
"networth","racecl4","racecl","occat1","income","norminc","wsaved",
"spendmor","spendless","late","late60","hpayday","bshopnone",
"bshopgrdl","bshopmodr","checking","hcheck",
"saving","hsaving","mmda","cds","irakh","anypen","vehic","hvehic",
"own","nown","newcar2","newcar1","veh_inst","hveh_inst","x7543","x7540",
"x2206","x2209","x2210","x2211","x2212","x2213","x2219"))
}
scf_rw <- readRDS( file.path( path.expand( "~" ) , "SCF" , paste0("scf ",fullyear," rw.rds" ) ))
#piecing together the dataframes
#figure out a loop for this
y1<- rbind(scf_imp[[1]],y1)
y2<- rbind(scf_imp[[2]],y2)
y3<- rbind(scf_imp[[3]],y3)
y4<- rbind(scf_imp[[4]],y4)
y5<- rbind(scf_imp[[5]],y5)
rw <- rbind(scf_rw,rw)
#include or exclude incrimental saving
assign(paste0("scf_imp_",year),scf_imp)
assign(paste0("scf_rw_",year),scf_rw)
assign(paste0("scf_design_",year),
svrepdesign(
weights = ~wgt ,
repweights = scf_rw[ , -1 ] ,
data = imputationList( scf_imp ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
))
rm(df1)
rm(df2)
rm(scf_imp)
rm(scf_rw)
}
#piecing together the imputations
imp <- list(y1,y2,y3,y4,y5)
#creating the design using the set of 3 years
design_full <- svrepdesign(
weights = ~wgt ,
repweights = rw[ , -1 ] ,
data = imputationList( imp ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)