sgaure / lfe

Source code repository for the R package lfe on CRAN.
53 stars 18 forks source link

How to use arg `keepModel` in `felm()`? Seems to return model whether TRUE or FALSE #9

Open MatthieuStigler opened 6 years ago

MatthieuStigler commented 6 years ago

Hi

For sake of space (I am running super heavy regressions), I would like to return a felm object without the model component. Is this what keepModel is intended for? I don't see a difference if I am using with TRUE or FALSE... it seems to return in both cases the same output? Am I doing something wrong?

Thanks!

library(lfe)
#> Loading required package: Matrix

example(felm, echo = FALSE)
est <- felm(y ~ x+x2| id + firm)
est_noM <- felm(y ~ x+x2| id + firm, keepModel = FALSE)

est$model
#> evalq(model.frame(formula = y ~ x + x2 + id + firm - 1, drop.unused.levels = TRUE), 
#>     <environment>)
est_noM$model
#> evalq(model.frame(formula = y ~ x + x2 + id + firm - 1, drop.unused.levels = TRUE), 
#>     <environment>)
all.equal(est$model, est_noM$model)
#> [1] TRUE
object.size(est$model)
#> 4088 bytes
object.size(est_noM$model)
#> 4088 bytes

Created on 2018-10-23 by the reprex package (v0.2.1)

karldw commented 5 years ago

@MatthieuStigler, it looks like the default for keepModel is FALSE, so both of your versions end up not keeping the model frame.

library(lfe)
#> Loading required package: Matrix

example(felm, echo = FALSE)
est     <- felm(y ~ x + x2 | id + firm, keepModel=TRUE)
est_noM <- felm(y ~ x + x2 | id + firm, keepModel=FALSE)

head(est$model, 1)
#>            y         x         x2 id firm
#> 1 -0.7610686 0.5097289 0.06221951 10    3
est_noM$model
#> evalq(model.frame(formula = y ~ x + x2 + id + firm - 1, drop.unused.levels = TRUE), 
#>     <environment>)
all.equal(est$model, est_noM$model)
#> [1] "Modes: list, call"                                   
#> [2] "Lengths: 5, 3"                                       
#> [3] "names for target but not for current"                
#> [4] "Attributes: < Modes: list, NULL >"                   
#> [5] "Attributes: < Lengths: 3, 0 >"                       
#> [6] "Attributes: < names for target but not for current >"
#> [7] "Attributes: < current is not list-like >"            
#> [8] "current is not list-like"