Skip to content

Commit

Permalink
Add error message when i() is used in the FE part => related to #77
Browse files Browse the repository at this point in the history
  • Loading branch information
lrberge committed Jan 5, 2021
1 parent 5a369fe commit 2cf7040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# Other

- More coherence regarding the use of `summary` applied to models for which the SEs were computed at estimation time. Now there is a memory of how the SEs were computed, so that, for example, if only the argument `dof` is passed to `summary`, then the SEs will be clustered in the same way as estimation time but and only `dof` will change.

- Now an error is raised when `i()` is used in the fixed-effects part of the formula. The appropriate way is indicated (related to [#77](https://github.com/lrberge/fixest/issues/77)).

# fixest 0.8.0 (2020-12-14)

Expand Down
15 changes: 15 additions & 0 deletions R/MiscFuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,22 @@ fixef_terms = function(fml, stepwise = FALSE, origin_type = "feols"){
return(msg)
}
}
}

# And yet again some error checking => i() should NOT be used
if(any(grepl("^i(nteract)?\\(", my_vars))){
# We create an error instead of simply correcting the syntax => this is because the function i is
# very different and should not be confused

var_pblm = my_vars[grepl("^i(nteract)?\\(", my_vars)][1]

get_new_var = function(var, f, f2, ...) match.call()

what = eval(str2lang(gsub("^i(nteract)?", "get_new_var", var_pblm)))
n_var = sum(c("var", "f", "f2") %in% names(what))
msg = if(n_var == 1) "Using i() to create fixed-effects is not possible, use directly the variable." else paste0("To interact fixed-effects, use the syntax fe1^fe2 (in your case ", deparse(what[[2]]), "^", deparse(what[[3]]), ").")

stop("The function i() should not be used in the fixed-effects part of the formula. ", msg)
}

# Internal function
Expand Down

0 comments on commit 2cf7040

Please sign in to comment.