Support character formulas such as "y ~ x" (similar to lm, glm etc)
lm, glm and many other estimation function support character objects as formulas. More specifically, the documentation for lm states that the formula argument should be
an object of class "formula" (or one that can be coerced to that class)
Many other estimation functions similarly support character formulas (or other object types that can be coerced to an object of class "formula"). All of the estimation function in fixest only support objects of class "formula" for the fml argument.
Why does this matter:
- Consistency with
lm,glmand many other estimation functions - It is convenient for the user when formulas are constructed from strings such as
glue("{y} ~ x1 + x2", y = "depvar") - Should be very easy to implement.
fixest has its own way to include variables in formulas with the dot-square-bracket operator. This is much more compact and versatile than using strings with glue.
A few examples (the function xpd also applies the DSB operator to formulas in the same way as feols parses them):
y = "depvar"
xpd(.[y] ~ x)
#> depvar ~ x
glue("{y} ~ x")
#> depvar ~ x
xpd(y ~ x.[1:3])
#> y ~ x1 + x2 + x3
paste("y ~", paste0("x", 1:3, collapse = " + "))
#> [1] "y ~ x1 + x2 + x3"
vars = c("cyl", "mpg")
xpd(y ~ .[vars] + z)
#> y ~ cyl + mpg + z
paste("y ~", paste0(vars, collapse = " + "), "+ z")
#> [1] "y ~ cyl + mpg + z"
And actually many more things can be done. In general, the syntax is more compact and more explicit and clear than with the string versions.
I truly do not see the clear value added of the string syntax, but I may be missing something! Do you have a use case where it can be done only with strings and not the DSB syntax?
I did’t know about the existing syntax. Looks great. I will check it out.
I guess my main argument would be consistency with base R (and many other estimation commands). Consistency is really helpful for the language as a whole and for new package users who try out fixest or who are switching from other package such as lfe.
Love the package!