Hello,
I've recently run across a series of problems when I try to estimate models that
include factors via 2SLS. The problems arise in versions 3.5.5 and 4.1.3. (I'm also
using I'm using systemfit 1.1.14.) In all cases, zelig() works fine, but problems
arise with setx() or sim(). Here is a minimal example:
data(klein)
klein$fac <- factor(rep(letters[1:3], times = 7))
z.out <- zelig(
formula = list(
"mu1" = Wtot ~ fac + P1,
"mu2" = fac ~ X + X1 + P1,
"inst" = ~ X + X1 + P1),
model = "twosls",
data = klein)
x.out <- setx(z.out, fac = 'b')
s.out <- sim(z.out, x = x.out)
In Zelig 4.1.3, the setx() command above yields an "Error in form[[3]] : subscript
out of bounds" message. In Zelig 3.5.5, there is no problem with setx(), but the
sim() command yields: "Error: subscript out of bounds."
If I make numeric dummies out of the factor, the problem vanishes in both versions of
Zelig:
klein$b <- as.numeric(klein$fac == 'b')
klein$c <- as.numeric(klein$fac == 'c')
z.out <- zelig(
formula = list(
"mu1" = Wtot ~ b + c + P1,
"mu2" = b ~ X + X1 + P1,
"mu3" = c ~ X + X1 + P1,
"inst" = ~ X + X1 + P1),
model = "twosls",
data = klein)
x.out <- setx(z.out, b = 0)
s.out <- sim(z.out, x = x.out)
But when a factor has many levels, it can be laborious to convert it into a set of dummies
that will work with setx() and sim(). (Using model.matrix() doesn't help here: it
creates matrices of dummies, and sim() doesn't seem to like matrices in formulas.)
Short of dummying out my factors, is there anything that I can do to use setx() and sim()
when my model has factors and I want to use 2SLS?
Thank you,
John
Show replies by date