Rogerio and James,
The solution is a pretty nifty one. Creating (and then deleting) an object in the global
environment does, indeed, solve the problem. I hadn't been introduced to
"<<-", so I was looking for a solution that would make Zelig search the
local environment.
Now, while I the developers side of the issue, as a user I cannot see how this could
become a permanent feature of Zelig commands, especially given that other R functions do
not behave this same way. The way I dealt with the issue was simply to switch to glm(),
and either hand-code or use erer's maBina() for quantities of interest.
cz
On Jun 1, 2013, at 12:00 PM, zelig-request(a)lists.gking.harvard.edu wrote:
> Send Zelig mailing list submissions to
> zelig(a)lists.gking.harvard.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
>
https://lists.gking.harvard.edu/mailman/listinfo/zelig
> or, via email, send a message with subject or body 'help' to
> zelig-request(a)lists.gking.harvard.edu
>
> You can reach the person managing the list at
> zelig-owner(a)lists.gking.harvard.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Zelig digest..."
>
>
> Today's Topics:
>
> 1. Re: can't invoke data object inside a function (Rog?rio Barbosa)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 1 Jun 2013 03:23:53 -0300
> From: Rog?rio Barbosa <antrologos(a)gmail.com>
> To: "Honaker, James" <jhonaker(a)iq.harvard.edu>du>,
> "zelig(a)lists.gking.harvard.edu" <zelig(a)lists.gking.harvard.edu>
> Subject: Re: [zelig] can't invoke data object inside a function
> Message-ID:
> <CAM+NV=1Z6rcbnXvDD-zy1U4EMHVRF=WvRrZqWF_edSHUdC1WTA(a)mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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
>>>
>>
>>
>