Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update a lfe formula containing 0 #6

Open
MatthieuStigler opened this issue Oct 9, 2018 · 1 comment
Open

update a lfe formula containing 0 #6

MatthieuStigler opened this issue Oct 9, 2018 · 1 comment

Comments

@MatthieuStigler
Copy link
Contributor

I have difficulties using update() on a formula containing any 0: trying multiple combinations, I end up always with 1-1`, which will throw an error. Any idea how to handle this?

library(Formula)
fo <-  y ~ x+x2| id + firm| 0 |firm

update(as.Formula(fo), . ~ .| firm| . |firm)
update(as.Formula(fo), . ~ .| firm| 0 |firm)
update(as.Formula(fo), . ~ .| firm| -1 + 0 |firm)
update(as.Formula(fo), . ~ .| firm| -1|firm)

This could be an issue with the underlying update() function:

update(~0, ~0)
~1 - 1

And actually from the terms.formula() function with simplify = TRUE.

terms.formula(~0, simplify = TRUE)
terms.formula(~0, simplify = FALSE)

But at that point... any workaround for that issue? Thanks!

@karldw
Copy link
Contributor

karldw commented Sep 12, 2019

@MatthieuStigler, it looks like felm has to do this internally (it's a tricky process)

lfe/R/felm.R

Lines 40 to 58 in 49bac46

# we can't just dot-update the iv-part, update will only keep the instruments
if(numrhs < 2) Form <- update(Form, . ~ . | 0 | 0 | 0 | 0, drop=FALSE)
else if(numrhs < 3) Form <- update(Form, . ~ . | . | 0 | 0 | 0 , drop=FALSE)
else if(numrhs < 4) {
# build from parts
Form <- as.Formula(do.call(substitute, list(L ~ R1 | R2 | R3 | 0 | 0,
list(L=formula(Form,lhs=NULL,rhs=0)[[2]],
R1=formula(Form,lhs=0,rhs=1)[[2]],
R2=formula(Form,lhs=0,rhs=2)[[2]],
R3=formula(Form,lhs=0,rhs=3)[[2]]))))
} else if(numrhs < 5) {
Form <- as.Formula(do.call(substitute, list(L ~ R1 | R2 | R3 | R4 | 0,
list(L=formula(Form,lhs=NULL,rhs=0)[[2]],
R1=formula(Form,lhs=0,rhs=1)[[2]],
R2=formula(Form,lhs=0,rhs=2)[[2]],
R3=formula(Form,lhs=0,rhs=3)[[2]],
R4=formula(Form,lhs=0,rhs=4)[[2]]))))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants