Skip to content
Prev 260419 / 398502 Next

svytable and na's

hi thomas

thanks for your reply.
in the documentation of svytable, the argument na.rm=T is mentioned.

however, last night i figured out what went wrong in my tabulation: i had a dataset which i attached and then defined the missing values - of course they were not stored in the data set. 

attach(data)
vote[vote=="Don't know"|vote=="Refusal"]<-NA
detach(data)

so they disappeared when i created a svydesign-object with weighted data and my table looked like this:
vote
gndr             Yes       No Not eligible to vote  Refusal Don't know
  Male      453.8726 226.7600             154.1651   0.0000    10.8572
  Female    507.6368 302.3634             145.4426   0.0000    17.9157
  No answer   0.0000   0.0000               0.0000   0.0000     0.0000
           vote
gndr        No answer
  Male         0.0000
  Female       0.0000
  No answer    0.0000

thus the solution is to define the missings in the original data set by using data$variable before creating the svydesign-object. 

data$vote[data$vote=="Don't know"|data$vote=="Refusal"]<-NA

then the svytable looks correctly:
vote[drop = T]
gndr[drop = T]      Yes       No Not eligible to vote
        Male   453.8726 226.7600             154.1651
        Female 507.6368 302.3634             145.4426

or is there a way to define factor levels as na directly in an svydesign-object?

best and thanks
katharina

dr. katharina manderscheid

soziologisches seminar
universit?t luzern

kasernenplatz 3
6000 luzern 7

tel. ++41 41 228 4657