Thanks, it works well !
But it seems to have a mistake. I have to had the object produce by zelig() in the call()
function. So the code is this :
call1 <- call2 <- call("setx", z.out.1, fn = NULL)
Merci,
François Maurice, B. Sc., A. Stat.
Candidat à la maîtrise
Département de sociologie
Université de Montréal
De : "Owen, Matt" <mowen(a)iq.harvard.edu>
À : Francois Maurice <maurice.francois(a)ymail.com>om>; Zelig mailing list
<zelig(a)lists.gking.harvard.edu>
Envoyé le : Mardi 6 Septembre 2011 22h46
Objet : RE: [zelig] Problem in specifying a proxy variable in setx()
The operation that you are attempting to do is:
x.out.0.1 <- setx(z.out.1, fn=NULL, TREAT=0)
x.out.1.1 <- setx(z.out.1, fn=NULL, TREAT=1)
The reason why your statement does not work is more of an issue with programming in
general. That is, when the function setx is evaluated, the statement:
tx.var = 0
is being understood that you are setting a parameter (tx.var) to whatever is on the
right-hand-side of the equal sign.
To do what you are trying to do (in the same manner as you are trying to do it) requires
something like:
call1 <- call2 <- call("setx", fn = NULL)
call1[[tx.var]] <- 0
call2[[tx.var]] <- 1
x.out.0.1 <- eval(call1)
x.out.1.1 <- eval(call2)
Why this is the case has to do with how R interprets what you are writing in your script.
That is, imagine the scenario where the formula (causal.model) was:
causal.model <- QASBAT ~ TREAT + T + T2 + T3 + tag(T | ID.factor) + tx.var
Note that tx.var now is specified as an explanatory variable.
In general, writing out:
x.out.0.1 <- setx(z.out.1, fn=NULL, TREAT=0)
x.out.1.1 <- setx(z.out.1, fn=NULL, TREAT=1)
is typically the better option because of its readability.
________________________________________
From: owner-zelig_at_lists_gking_harvard_edu(a)mail.hmdc.harvard.edu
[owner-zelig_at_lists_gking_harvard_edu(a)mail.hmdc.harvard.edu] On Behalf Of Francois
Maurice [maurice.francois(a)ymail.com]
Sent: Tuesday, September 06, 2011 10:19 PM
To: Zelig mailing list
Subject: [zelig] Problem in specifying a proxy variable in setx()
Hi,
I'm trying to do elegant coding, but I have trouble with setx(). I defined two
objects, tx.var, wich contains the name of the treatment variable, and causal.model, which
contains the model used in zelig() (see the code below). Everything works fine except in
setx(). When I specify tx.var instead of TREAT, which is the name of the treatment
variable, sim() produce zero effect. But when I specify TREAT, sim() produces a quantity.
Is there something I can do to correct this ?
tx.var <- c("TREAT")
causal.model <- QASBAT ~ TREAT + T + T2 + T3 + tag(T | ID.factor)
(some other codes here)
z.out.1 <- zelig(formula= as.formula(causal.model), data=matched.1.mtch.long,
model="ls.mixed")
x.out.0.1 <- setx(z.out.1, fn=NULL, tx.var=0)
x.out.1.1 <- setx(z.out.1, fn=NULL, tx.var=1)
s.out.1 <- sim(z.out.1, x=x.out.0.1, x1=x.out.1.1)
Merci,
François Maurice, B. Sc., A. Stat.
Candidat à la maîtrise
Département de sociologie
Université de Montréal
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/