2

I would like to set up the survey design for Cote d'Ivoire DHS using R (2011-2012). I am focused on domestic violence.

I used this code:

wt <- ipv_studyf$d005/1000000 # creating the variable weight

ipvdesign <- svydesign(ids = ipv_studyf$v021,      # clustering- psu
                        strata = ipv_studyf$v023,   # strata variable
                        weights = wt,               # the weighting variable
                        data = ipv_studyf,          # the dataset
                        variance="HT" )             # Horvitz-Thompson estimator

However, I keep getting this error message:

**Error in na.weight(data.frame(weights)) : missing values in `weights'**

If anyone has any insights on how to set up the dataset in R and help me fix this error message, I would appreciate the help!

holzben
  • 1,459
  • 16
  • 24
bakani1
  • 21
  • 1
  • Try by `i1 <- !is.na(wt)`, then do `svydesign(ids = ipv_studyf$v021[i1], strata = ipv_studyf$v023[i1], weights = wt[i1], data = ipv_studyf, variance = "HT")` – akrun Oct 30 '20 at 17:29

1 Answers1

0

We can create a logical vector for NA, subset the data and apply the function

 i1 <- !is.na(wt)
 svydesign(ids = ipv_studyf$v021[i1], 
           strata = ipv_studyf$v023[i1], 
           weights = wt[i1], 
           data = ipv_studyf, variance = "HT") 
akrun
  • 874,273
  • 37
  • 540
  • 662