Home > Net >  Trouble converting a Stata command for survey design declaration to R - svydesign
Trouble converting a Stata command for survey design declaration to R - svydesign

Time:09-02

I am working on the INCA3 nutrition dataset. To be analyzed, a survey declaration must be performed. It is explained in this file: https://static.data.gouv.fr/resources/donnees-de-consommations-et-habitudes-alimentaires-de-letude-inca-3/20210128-192916/notice-utilisateurs-donnees-inca3-data.gouv-english.pdf

In particular, for the dataset I am interested in, the following Stata command is provided (p. 69):

svyset zae [pweight=pond_indiv_adu_pop3], ///
    strata(strate) fpc(fpc1) vce(linearized) singleunit(scaled) ///
    || NOMEN, fpc(fpc2) || NOIND, fpc(fpc3)

Unfortunately, I do not use Stata and have not worked with this type of survey before. I am working with R and found the survey package, with the corresponding svydesign command. Here is my attempt at reproducing the code in R:

svydesign(id=~zae NOMEN NOIND,
          strata=~strate,
          weights=~pond_indiv_adu_pop3,
          fpc=~fpc1 fpc2 fpc3,
          data=conso_alim)

Unfortunately, it is not working, as I obtain the following error:

Error in (function (object, ...) : missing values in `weights'

Is there anything wrong with my implementation?

CodePudding user response:

As the error message suggested, you have missing values in weights variable: pond_indiv_adu_pop3. You could try to use a subset of data:

svydesign(id = ~zae   NOMEN   NOIND,
          strata = ~strate,
          weights = ~pond_indiv_adu_pop3,
          fpc = ~fpc1   fpc2   fpc3,
          data=subset(conso_alim, !is.na(pond_indiv_adu_pop3))

I am not sure if this will fix your problem without a reproducible example.

  • Related