Reputation: 1435
I have two fixed effect variables and I'm interested in estimating coefficients of one fixed effect, but feols
automatically drops the first one always.
For example, in my toy data like below:
library(data.table)
library(fixest)
set.seed(1)
test_dt = data.table(
y = rnorm(12, 15,20),
x = rnorm(12, 25, 5),
TIMESLOT = rep(c('BEG','MID','END'),4),
FIRM = rep(c('A','B','C','D'), 3)
)
print(test_dt)
y x TIMESLOT FIRM
1: 2.470924 21.89380 BEG A
2: 18.672866 13.92650 MID B
3: -1.712572 30.62465 END C
4: 46.905616 24.77533 BEG D
5: 21.590155 24.91905 MID A
6: -1.409368 29.71918 END B
I'm trying to estimate coefficients of TIMESLOT fixed effect (removing intercept), and I'm not interested in coef of FIRM.
So my first approach was to run
feols(y ~ 0 + i(TIMESLOT) + i(TIMESLOT, x) + FIRM, test_dt) # WORKS, and drops one of firm
Which yields what I need - all of TIMESLOT coefficients.
The variable 'FIRMD' has been removed because of collinearity (see $collin.var).
OLS estimation, Dep. Var.: y
Observations: 12
Standard-errors: IID
Estimate Std. Error t value Pr(>|t|)
TIMESLOT::BEG -31.539770 107.34824 -0.293808 0.78806
TIMESLOT::END 16.660959 45.20014 0.368604 0.73690
TIMESLOT::MID 72.309104 64.56608 1.119924 0.34432
TIMESLOT::BEG:x 2.672511 4.23945 0.630391 0.57319
TIMESLOT::END:x 0.477604 1.97274 0.242102 0.82431
TIMESLOT::MID:x -1.121334 2.42085 -0.463199 0.67476
FIRMA -17.185688 19.01731 -0.903687 0.43277
FIRMB -35.705475 25.40943 -1.405206 0.25461
FIRMC -17.706701 21.30094 -0.831264 0.46680
... 1 variable was removed because of collinearity (FIRMD)
My real data has lots of unique values of FIRM so I'd like to put it as fixed effect variable. Unfortunately, feols
removes one of my dummy variable of interest.
For example,
feols(y ~ 0 + i(TIMESLOT) + i(TIMESLOT, x)| FIRM, test_dt)
yields
OLS estimation, Dep. Var.: y
Observations: 12
Fixed-effects: FIRM: 4
Standard-errors: Clustered (FIRM)
Estimate Std. Error t value Pr(>|t|)
TIMESLOT::END 48.200729 63.44549 0.759719 0.50267
TIMESLOT::MID 103.848874 123.20970 0.842863 0.46120
TIMESLOT::BEG:x 2.672511 3.39202 0.787882 0.48828
TIMESLOT::END:x 0.477604 1.75570 0.272030 0.80325
TIMESLOT::MID:x -1.121334 2.21219 -0.506888 0.64714
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RMSE: 9.82348 Adj. R2: -0.468187
Within R2: 0.403153
So now TIMESLOT::BEG is dropped. I would rather want one of firm dummies to be dropped, but I had no success.
Finally,
I saw y
and X
, and fixef_df
arguments in feols
function and was trying to use this path as my last resort.
However, I'm getting some error messages that I can't interpret. My trial is like below.
feols(y= test_dt$y, X = test_dt[,.(i(TIMESLOT), i(TIMESLOT,x))], fixef_df = test_dt[,.(i(FIRM, ref ='A'))])
#Error in get("isFixef", env) : argument "env" is missing, with no default
What could be the way to manually drop one of dummy variable here? I'd appreciate your answers.
(fixest package is not tagged in SO currenlty)
Upvotes: 0
Views: 1365