I'm writing a function that, among other things, calls pgmm from the PLM package based on an updated formula. However when I use update.formula from stats the right-hand side (RHS) of the formula becomes inexplicably wrapped in parentheses. I wouldn't care except that the formula= argument in pgmm does not accept this syntax.
My baseline formula:
model.AR1.1X = y ~ lag(y,1) + lag(x,1)
I use this for some preliminary estimations and then update via:
gmm.form = update.formula(model.AR1.1X, . ~ . | lag(y, 2:6)
# calling this formula shows:
gmm.form
y ~ (lag(yi, 1) + lag(x, 1) | lag(y, 2:6))
Notice the bracket after the tilde ~, ( lag(y ... etc.. and the double-bracket at the end 2:6))
When I then call pgmm I get the error:
Error in terms.default(formula) : no terms component nor attribute
There is no problem when I write out the formula myself (without extra brackets), but this would complicate my code.
Is there a way to prevent this behaviour in update.formula? Alternatively, is there a gsub equivalent that can be used on a formula object to remove these brackets?
You can either modify the call or use paste as in the comments. Here's the modify method.
gmm.form[[3]] <- gmm.form[[3]][[2]]
#y ~ lag(y, 1) + lag(x, 1) | lag(y, 2:6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With