简体   繁体   中英

Using stargazer with Zelig

I am trying to use stargazer (Version 5.2) to output the standard summary() results of a regression estimated with Zelig (Version 5.0.13). However, I obtain the error

Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
‘result’ is not a valid field or method name for reference class “Zelig-ls”

when trying to feed the estimated model into stargazer.

A minimal working example reproducing the error would be

library(Zelig)
library(stargazer)
data("swiss")
z <- zls$new()
z$zelig(Fertility~Education, data=swiss)
stargazer(z)

I assume I need to somehow access the place where the estimated model is stored in the zelig object, but I am having trouble finding it.

As of Zelig 5.0-13 and stargazer 5.2, stargazer doesn't seem to be able to handle Zelig's internal model. As a workaround, you can simply cast it to a "normal" lm to make it work:

stargazer(lm(z$zelig.out$z.out[[1]]), type='text')

Result:

===============================================
                        Dependent variable:    
                    ---------------------------
                             Fertility         
-----------------------------------------------
Education                    -0.862***         
                              (0.145)          

Constant                     79.610***         
                              (2.104)          

-----------------------------------------------
Observations                    47             
R2                             0.441           
Adjusted R2                    0.428           
Residual Std. Error       9.446 (df = 45)      
F Statistic           35.446*** (df = 1; 45)   
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM