1. Is there a way to force model.matrix() to include
cases with NAs? I
want to
automatically create dummy variables for an entire data set with a lot
of
missing values (by default, model.matrix drops all those cases with
missing
values).
I don't think there is a way to force model.matrix() specifically. You an
easy hack is:
Data[is.na(Data)] <- -9999
Then do the your model matrix with that. And reconvert at the end:
Data[Data==-9999] <- NA
Another idea is to quickly write a dummy variable function that accommodates
NAs.
#now, add a missing value, and re-run analyses
d2<-d
d2[4,1]<-NA
zelig(y~x,model="logit",data=d2) #works
zelig(y~x,model="logit",weights=d2$wt,data=d2) #fails
This seems like a bug to me at first glance. Weights should be handled like
vars. I think trimming the dataset first hand, or running it on a subset of
non-missing items should do the trick. Like
d2 <- na.omit(d2)
zelig(y~x,model="logit",weights=d2$wt,data=d2) #fails
hth,
jens