Closed s3alfisc closed 1 year ago
Ok, I did a little bit of googling, and I am - after almost 10 years of running regressions in R - astonished to learn that formulaic
's C(, contr.treatment)
syntax goes back to base R!
df_het$state <- as.factor(df_het$state)
n = length(unique(df_het$state))
lm( dep_var ~ -1 + C(state, contr.treatment(n = n,base=1)), data=df_het ) |> coefficients()
# C(state, contr.treatment(n = n, base = 1))1
# 0.7395872
# C(state, contr.treatment(n = n, base = 1))2
# 1.1637809
# C(state, contr.treatment(n = n, base = 1))3
# 0.7334002
So I suppose everything is as it should be and I will close this issue. Though if you happen to know a good way to specify in the formula how to drop an Intercept "ex post" - please let me know! =)
Hi Matthew,
I am trying to implement some tricks for reference levels of categorical variables that I need for event study estimators. I've observed the following behavior, and I wonder if it is desired, or if it might be a bug =)
First I load some data:
I now create a model matrix via formulaic and drop state 1 / set it as the reference level:
As expected, the model matrix has an intercept & state 1 is "dropped".
If I now add a "+0" or "-1" to the formula, I'd expect from R's
fixest
that the Intercept is dropped on top of the reference state 1.But this does not seem to happen - only the intercept is dropped, and the
contr.treatment
argument appears to be overturned.In R's
fixest
- which I understand is not at allformulaic
's main role model - we get the same model matrix as above minus the column for the reference state 1.So, is this intended behavior? =)
Best, Alex