[R] "survey" package -- doesn't appear to match svy

Stephen Amrock stephen.amrock at gmail.com
Mon Oct 27 16:11:18 CET 2014


Hi,

I'm new to R and have encountered two issues in coding using the "survey"
package:

(1) Code from *svytable* using "survey" package does not correspond to
Stata estimates from *svy: tab*. I call

    svyd.nation <- svydesign(ids = ~1, probs = ~wt_national, strata =
~stratum, data=nats.sub)
    svytable(formula = ~wpev, design = svyd.nation, Ntotal = 100)

where the equivalent Stata would be:

    svyset [pw=wt_national], strata(stratum)
    svy: tab wpev

These are inverse probability weights but Stata and R give different %s for
the tabulations. I know from published results that the Stata code is
correct.  Any ideas as to what I've done incorrectly in R?

(2) Alternative weights---which I've verified in R have the same
distribution as in Stata---produce a strange "inf" output.

    svyd.st <- svydesign(ids = ~1, probs = ~wt_state, strata = ~stratum,
data=nats.sub)
    svytable(~wpev, design = svyd.st, Ntotal=100)

This produces the following output:

    wpev
    0 1

The code
    svytable(~wpev, svyd.st)

produces the output:

    wpev
    0   1
    Inf Inf

Why are these alternative weights -- which work in Stata when resetting
svyset -- not working in R?

Any insights would be much appreciated!! Many thanks!
- S

	[[alternative HTML version deleted]]



More information about the R-help mailing list