Combining svyimputationLists
I am working with the Survey of Consumer Finances dataset and am looking to do analysis across years. My initial thought is to combine them into the same svyimputationList, but my attempts don't seem to actually combine the data. they remain as different lists within a larger svyimputationList. There could be other ways to do analysis across years (I mainly looking to be able to run some regressions) so those answers are also welcome.
The class of the scf_design sets are "svyimuptationList".
Below is the code I have used in order to gather the datasets and my attempt to combine.
library(lodown)
library(survey)
library(mitools)
library(plyr)
scf_cat <-
get_catalog( "scf" ,
output_dir = file.path( path.expand( "~" ) , "SCF" ) )
# 2016 only
scf_cat_16 <- subset( scf_cat , year == 2016 )
#2013 only
scf_cat_13 <- subset( scf_cat , year == 2013 )
# download the microdata to your local computer
scf_cat_16 <- lodown( "scf" , scf_cat_16 )
scf_cat_13 <- lodown( "scf" , scf_cat_13 )
#setup the data to control for the survey style and MI
scf_imp_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016.rds" ) )
scf_rw_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016 rw.rds" ) )
scf_imp_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013.rds" ) )
scf_rw_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013 rw.rds" ) )
#APPLYING THE WEIGHTS TO THE DATA#####
scf_design_16 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_16[ , -1 ] ,
data = imputationList( scf_imp_16 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design_13 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_13[ , -1 ] ,
data = imputationList( scf_imp_13 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design <- rbind(scf_design_16,scf_design_13)
r survey imputation
add a comment |
I am working with the Survey of Consumer Finances dataset and am looking to do analysis across years. My initial thought is to combine them into the same svyimputationList, but my attempts don't seem to actually combine the data. they remain as different lists within a larger svyimputationList. There could be other ways to do analysis across years (I mainly looking to be able to run some regressions) so those answers are also welcome.
The class of the scf_design sets are "svyimuptationList".
Below is the code I have used in order to gather the datasets and my attempt to combine.
library(lodown)
library(survey)
library(mitools)
library(plyr)
scf_cat <-
get_catalog( "scf" ,
output_dir = file.path( path.expand( "~" ) , "SCF" ) )
# 2016 only
scf_cat_16 <- subset( scf_cat , year == 2016 )
#2013 only
scf_cat_13 <- subset( scf_cat , year == 2013 )
# download the microdata to your local computer
scf_cat_16 <- lodown( "scf" , scf_cat_16 )
scf_cat_13 <- lodown( "scf" , scf_cat_13 )
#setup the data to control for the survey style and MI
scf_imp_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016.rds" ) )
scf_rw_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016 rw.rds" ) )
scf_imp_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013.rds" ) )
scf_rw_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013 rw.rds" ) )
#APPLYING THE WEIGHTS TO THE DATA#####
scf_design_16 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_16[ , -1 ] ,
data = imputationList( scf_imp_16 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design_13 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_13[ , -1 ] ,
data = imputationList( scf_imp_13 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design <- rbind(scf_design_16,scf_design_13)
r survey imputation
Well if you are creating lists that you want to piece together this cannot be done withrbind
(row bind), appending a list would be done withlist.append(.data, ...)
. But I have no idea whatsvredesign()
does, so maybe show us the class and structure ofscf_design_13/16
– Chabo
Nov 15 at 22:32
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
1
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example issvydesign
where scf issvrepdesign
– Anthony Damico
Nov 16 at 16:49
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38
add a comment |
I am working with the Survey of Consumer Finances dataset and am looking to do analysis across years. My initial thought is to combine them into the same svyimputationList, but my attempts don't seem to actually combine the data. they remain as different lists within a larger svyimputationList. There could be other ways to do analysis across years (I mainly looking to be able to run some regressions) so those answers are also welcome.
The class of the scf_design sets are "svyimuptationList".
Below is the code I have used in order to gather the datasets and my attempt to combine.
library(lodown)
library(survey)
library(mitools)
library(plyr)
scf_cat <-
get_catalog( "scf" ,
output_dir = file.path( path.expand( "~" ) , "SCF" ) )
# 2016 only
scf_cat_16 <- subset( scf_cat , year == 2016 )
#2013 only
scf_cat_13 <- subset( scf_cat , year == 2013 )
# download the microdata to your local computer
scf_cat_16 <- lodown( "scf" , scf_cat_16 )
scf_cat_13 <- lodown( "scf" , scf_cat_13 )
#setup the data to control for the survey style and MI
scf_imp_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016.rds" ) )
scf_rw_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016 rw.rds" ) )
scf_imp_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013.rds" ) )
scf_rw_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013 rw.rds" ) )
#APPLYING THE WEIGHTS TO THE DATA#####
scf_design_16 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_16[ , -1 ] ,
data = imputationList( scf_imp_16 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design_13 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_13[ , -1 ] ,
data = imputationList( scf_imp_13 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design <- rbind(scf_design_16,scf_design_13)
r survey imputation
I am working with the Survey of Consumer Finances dataset and am looking to do analysis across years. My initial thought is to combine them into the same svyimputationList, but my attempts don't seem to actually combine the data. they remain as different lists within a larger svyimputationList. There could be other ways to do analysis across years (I mainly looking to be able to run some regressions) so those answers are also welcome.
The class of the scf_design sets are "svyimuptationList".
Below is the code I have used in order to gather the datasets and my attempt to combine.
library(lodown)
library(survey)
library(mitools)
library(plyr)
scf_cat <-
get_catalog( "scf" ,
output_dir = file.path( path.expand( "~" ) , "SCF" ) )
# 2016 only
scf_cat_16 <- subset( scf_cat , year == 2016 )
#2013 only
scf_cat_13 <- subset( scf_cat , year == 2013 )
# download the microdata to your local computer
scf_cat_16 <- lodown( "scf" , scf_cat_16 )
scf_cat_13 <- lodown( "scf" , scf_cat_13 )
#setup the data to control for the survey style and MI
scf_imp_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016.rds" ) )
scf_rw_16 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2016 rw.rds" ) )
scf_imp_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013.rds" ) )
scf_rw_13 <- readRDS( file.path( path.expand( "~" ) , "SCF" , "scf 2013 rw.rds" ) )
#APPLYING THE WEIGHTS TO THE DATA#####
scf_design_16 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_16[ , -1 ] ,
data = imputationList( scf_imp_16 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design_13 <-
svrepdesign(
weights = ~wgt ,
repweights = scf_rw_13[ , -1 ] ,
data = imputationList( scf_imp_13 ) ,
scale = 1 ,
rscales = rep( 1 / 998 , 999 ) ,
mse = FALSE ,
type = "other" ,
combined.weights = TRUE
)
scf_design <- rbind(scf_design_16,scf_design_13)
r survey imputation
r survey imputation
edited Nov 18 at 20:57
asked Nov 15 at 22:18
E. Nicholson
254
254
Well if you are creating lists that you want to piece together this cannot be done withrbind
(row bind), appending a list would be done withlist.append(.data, ...)
. But I have no idea whatsvredesign()
does, so maybe show us the class and structure ofscf_design_13/16
– Chabo
Nov 15 at 22:32
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
1
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example issvydesign
where scf issvrepdesign
– Anthony Damico
Nov 16 at 16:49
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38
add a comment |
Well if you are creating lists that you want to piece together this cannot be done withrbind
(row bind), appending a list would be done withlist.append(.data, ...)
. But I have no idea whatsvredesign()
does, so maybe show us the class and structure ofscf_design_13/16
– Chabo
Nov 15 at 22:32
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
1
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example issvydesign
where scf issvrepdesign
– Anthony Damico
Nov 16 at 16:49
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38
Well if you are creating lists that you want to piece together this cannot be done with
rbind
(row bind), appending a list would be done with list.append(.data, ...)
. But I have no idea what svredesign()
does, so maybe show us the class and structure of scf_design_13/16
– Chabo
Nov 15 at 22:32
Well if you are creating lists that you want to piece together this cannot be done with
rbind
(row bind), appending a list would be done with list.append(.data, ...)
. But I have no idea what svredesign()
does, so maybe show us the class and structure of scf_design_13/16
– Chabo
Nov 15 at 22:32
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
1
1
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example is
svydesign
where scf is svrepdesign
– Anthony Damico
Nov 16 at 16:49
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example is
svydesign
where scf is svrepdesign
– Anthony Damico
Nov 16 at 16:49
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38
add a comment |
1 Answer
1
active
oldest
votes
This is the answer that I have come up with after looking into what Anthony Damico commented:
It follows the form of stacking the data frames within the list of imputations and the replicate weight files to ultimately combine them to the 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
)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328683%2fcombining-svyimputationlists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is the answer that I have come up with after looking into what Anthony Damico commented:
It follows the form of stacking the data frames within the list of imputations and the replicate weight files to ultimately combine them to the 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
)
add a comment |
This is the answer that I have come up with after looking into what Anthony Damico commented:
It follows the form of stacking the data frames within the list of imputations and the replicate weight files to ultimately combine them to the 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
)
add a comment |
This is the answer that I have come up with after looking into what Anthony Damico commented:
It follows the form of stacking the data frames within the list of imputations and the replicate weight files to ultimately combine them to the 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
)
This is the answer that I have come up with after looking into what Anthony Damico commented:
It follows the form of stacking the data frames within the list of imputations and the replicate weight files to ultimately combine them to the 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
)
answered Dec 13 at 1:39
E. Nicholson
254
254
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328683%2fcombining-svyimputationlists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well if you are creating lists that you want to piece together this cannot be done with
rbind
(row bind), appending a list would be done withlist.append(.data, ...)
. But I have no idea whatsvredesign()
does, so maybe show us the class and structure ofscf_design_13/16
– Chabo
Nov 15 at 22:32
Also please include the libraries being used.
– Chabo
Nov 15 at 22:33
1
hi, the imp_13 and imp_16 lists each have data frames in them. you'll want to stack each of them, respectively. rw_13 and rw_16 are already data.frame objects, also stack those. ultimately you want to construct something like this asdfree.com/… but this example is
svydesign
where scf issvrepdesign
– Anthony Damico
Nov 16 at 16:49
hello, I have been dabbling around with this for a bit and believe that I am close doing some subsetting of the variables in order to stack the imputations. The one thing I am unsure of is how to work with the weight file in order to ensure that maintains its integrity with the svydesign. This comes from the fact that the dataframe is labeled weight1,weight2,...
– E. Nicholson
Nov 24 at 2:38