Project

General

Profile

Actions

Support #1477

open

clusters not nested in b_strata (using R and svydesign object)

Added by Marion Lieutaud almost 4 years ago. Updated almost 4 years ago.

Status:
Resolved
Priority:
High
Assignee:
-
Category:
-
Start date:
01/07/2021
% Done:

100%


Description

Dear Understanding Society team,

I have an issue with the combination of clusters and strata in the Wave 2 data. I have tested the exact same code for Wave 1 data, and it works - it is only when using b_strata that the issue arises. Here is the R code.

*b_indresp <- read.dta("b_indresp.dta")

library(survey)
options(survey.lonely.psu = "adjust")
options(na.action="na.pass")

b_w <- svydesign(id = ~b_psu,
strata = ~b_strata,
weights = ~b_indinub_xw,
data = b_indresp)*

this gives me the following error message:
"Error in svydesign.default(id = ~b_psu, strata = ~b_strata, weights = ~b_indinub_xw, : Clusters not nested in strata at top level; you may want nest=TRUE."

If I do add nest=TRUE:

b_w <- svydesign(id = ~b_psu,
strata = ~b_strata,
weights = ~b_indinub_xw,
data = b_indresp,
nest=TRUE)

I get no error message at this point, but an intractable list, not a svydesign object that would work for any {survey} function.
The problem persisted when I tried using other cross-sectional weights for Wave 2, i.e b_indinus_xw.

However, if instead of using Wave 2 data and variables, I use Wave 1 instead, it all works perfectly.

*a_indresp <- read.dta("a_indresp.dta")

a_w <- svydesign(id = ~a_psu,
strata = ~a_strata,
weights = ~a_indinus_xw,
data = a_indresp)*

Additionally, the code for Wave 2 works if I remove the strata element, i.e.:

b_w <- svydesign(id = ~b_psu,
weights = ~b_indinub_xw,
data = b_indresp,
nest=TRUE)

I wonder whether there is an issue with b_strata and the way I use it, and where I have gone wrong..?
I hope you can help!
Thank you very much in advance for your time and support!

Actions

Also available in: Atom PDF