-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Labels
bugSomething isn't workingSomething isn't working
Description
pyfixest does not appear to omit the reference category when using the i() syntax. This is not consistent with fixest.
In the example below, using i(cyl, hp, ref='4') still includes C(cyl, contr.treatment(base='4'))[4]:hp which should be omitted.
pyfixest
import pandas as pd
import pyfixest as pf
import statsmodels.api as sm
import rpy2.robjects as ro
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr
pandas2ri.activate()
fixest = importr("fixest")
broom = importr("broom")
#%% data
data = sm.datasets.get_rdataset("mtcars", "datasets").data
data["cyl"] = data["cyl"].astype("string").astype("category")
data["gear"] = data["gear"].astype('string').astype("category")
#%% i-syntax factor and float
formula: str = "mpg ~ i(cyl, hp, ref='4')"
pf.feols(fml=formula, data=data).summary()
###
Estimation: OLS
Dep. var.: mpg, Fixed effects: 0
Inference: iid
Observations: 32
| Coefficient | Estimate | Std. Error | t value | Pr(>|t|) | 2.5% | 97.5% |
|:----------------------------------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| Intercept | 25.389 | 2.828 | 8.979 | 0.000 | 19.597 | 31.182 |
| C(cyl, contr.treatment(base='4'))[4]:hp | 0.008 | 0.035 | 0.241 | 0.811 | -0.063 | 0.079 |
| C(cyl, contr.treatment(base='4'))[6]:hp | -0.045 | 0.025 | -1.810 | 0.081 | -0.096 | 0.006 |
| C(cyl, contr.treatment(base='4'))[8]:hp | -0.047 | 0.014 | -3.496 | 0.002 | -0.075 | -0.020 |
---
RMSE: 3.31 R2: 0.689
fixest
r = fixest.feols(ro.Formula(formula), data=data)
r_summary = pd.DataFrame(broom.tidy_fixest(r, conf_int=ro.BoolVector([True]))).T
print(r_summary.set_index(0)[1])
0
(Intercept) 26.024247
cyl::6:hp -0.049939
cyl::8:hp -0.050232
Name: 1, dtype: object
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working