[R] survey weights

Thomas Lumley tlumley at u.washington.edu
Sun Sep 4 18:52:31 CEST 2005


On Sat, 3 Sep 2005, A Das wrote:

> Hi all, I've been trying to get a large (12mb) Stata
> survey database into R. I managed that, but when I
> attach survey weights, something goes wrong. The error
> message is: object dchina not found. Here's the
> script:

If that is the *first* message then something extremly strange is 
happening

> library(car)
> library(foreign)
> library(survey)
>
> China <- read.dta("C:/final07c2.dta")
> attach(China)

This attach() isn't necessary or helpful

> data(China)
You should get a warning here

Warning message:
data set 'China' not found in: data(China)

since China isn't one of the built-in data sets. If you don't get this 
message it suggests that you do have a built-in dataset called China, 
which will have overwritten your file.

> dchina<-svydesign(id=~psu,strata=~strata,weights=~weight0x,
                          data=China,nest=TRUE)

If this line doesn't produce an error message then a variable called 
"dchina" must have been produced, in which case you shouldn't get an error 
message saying it wasn't found in the next line.

> summary(dchina)
>


Are you sure there wasn't an earlier error message from the call to 
svydesign()?

 	-thomas




More information about the R-help mailing list