jkcshea / ivmte

An R package for implementing the method in Mogstad, Santos, and Torgovitsky (2018, Econometrica).
GNU General Public License v3.0
18 stars 2 forks source link

Allowing redundant 'as-is' operator for MTR specifications #211

Closed johnnybonney closed 2 years ago

johnnybonney commented 2 years ago

I've noticed that the package does not allow me to specify an MTR formula that contains the term I(u). ivmte throws a (very informative) error:

Error : The following terms are not declared properly.
  m0: I(u) 
  m1: I(u) 
The unobserved variable 'u' must be declared as a monomial, e.g. u, I(u^3). The monomial can be interacted with other variables, e.g. x:u, x:I(u^3). Expressions where the unobservable term is not a monomial are either not permissible or will not be parsed correctly, e.g. exp(u), I((x * u)^2). Try to rewrite the expression so that 'u' is only included in monomials.

Using the as-is operator this way is clearly redundant (that is, I could just use u instead of I(u)), but other standard R functions (lm, glm ivreg, etc.) allow for such redundant usage.

This is simply a user-friendliness thing and may not be something you want to update. If you don't think it is worth the effort, feel free to disregard!

jkcshea commented 2 years ago

Ah sorry, yes, I can do this!