By the way, I tried my old do.call solution and in fact it didn't worked. I
think the problem is that "zelig" always points to the global environment
(and there is no way to specify a customized env). Using do.call arguments
wouldn't change the fact that "lcl.data" just exists inside the function.
It seems "setx" doesn't have this issue.
but I'm just guessing...
Em 01/06/2013 03:13, "Rogério Barbosa" <antrologos(a)gmail.com> escreveu:
Hi Cesar and James,
I've came up with a simple idea that worked this problem out, at least for
Cesar's purpose -- I think...
As Zelig cannot have access to objects created inside a function, one way
to deal with it is (1) to use the function for creating the desired data
frame in the global environment and then use; (2) then you call this object
from Zelig; (3) finally you can delete it, if you want -- and in the end it
is like it never existed in the globalenv.
Here it is an example:
###
rm(list=ls())
#require(Zelig)
data(mexico)
my.function <- function(the.data){
lcl.data <<- subset(the.data,select=c(1,2)) #creating a temporary
object in the global environment
zelig.reg <- zelig(lcl.data[,1]~
lcl.data[,2],data=lcl.data,model="ls") #running zelig using that object
rm(lcl.data, envir=.GlobalEnv) #removing it...
return(zelig.reg)
}
my.function(mexico)
It worked fine for me. Is it what you wanted?
Best,
Rogerio J. Barbosa
On Sat, Jun 1, 2013 at 12:25 AM, Honaker, James <jhonaker(a)iq.harvard.edu>wrote;wrote:
Cesar,
This is the same issue with environment dependence as in this thread
earlier this month:
https://lists.gking.harvard.edu/pipermail/zelig/2013-May/001189.html
In the slightly long run, the solution is that we will move from S4 to
Reference Classes (R5) over the summer. In the meantime, two solutions
were suggested in that thread. I can not get Rogério's do.call() solution
to work with the main zelig() function as I'm probably not creating the
argument list quite right, (the thread was about the setx() function, but
same underlying issue), but finding the dataset by scope does work, even if
unsatisfying.
Let me know if you work out a better solution for the present.
Best,
James
--
James Honaker, Senior Research Scientist
//// Institute for Quantitative Social Science, Harvard University
------------------------------
*From:* zelig-bounces(a)lists.gking.harvard.edu [
zelig-bounces(a)lists.gking.harvard.edu] on behalf of Cesar Zucco [
cesar.zucco(a)gmail.com]
*Sent:* Wednesday, May 15, 2013 3:28 PM
*To:* zelig(a)lists.gking.harvard.edu
*Subject:* [zelig] can't invoke data object inside a function
Hello list,
Is there any known issue using Zelig (4.1-3) commands inside a
function and invoking data.frame that is only defined inside that
function? This worked in the previous versions of Zelig, and works with
non-zelig commands. Here's a barebones example:
my.function <- function(the.data){
lcl.data <- subset(the.data,select=c(dv,iv))
reg <- lm(dv~ iv,data=lcl.data) #this works fine
zelig.reg <- zelig(dv~ iv,data=lcl.data,model="ls") #this gives error
}
The lm regression works, but no zelig model seems to be able to use the
lcl.data. I get the same error message triggered by invoking a data.frame
that does not exist:
Error in multi.dataset(lcl.data) : object 'lcl.data' not found
cz
Cesar Zucco Jr.
Assistant Professor
Political Science Department
Rutgers, The State University of New Jersey
http://fas-polisci.rutgers.edu/zucco/
-
--
Zelig Mailing List, served by HUIT
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/mailman/listinfo/zelig
Zelig program information:
http://gking.harvard.edu/zelig/
Zelig mailing list
Zelig(a)lists.gking.harvard.edu
To unsubscribe from this list or get other information:
https://lists.gking.harvard.edu/mailman/listinfo/zelig