R Under development (unstable) (2024-02-21 r85967 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(lfe) Loading required package: Matrix > options(lfe.threads=1,digits=3,warn=1) > set.seed(42) > N <- 10000 > x <- rnorm(N) > y <- rnorm(N) > time_id <- factor(sample(5,N,repl=TRUE)) > group <- factor(sample(c('A','B','C','M','P','Q'),N,repl=TRUE)) > data <- data.frame(x=x, y=y, time_id=time_id, group=group) > > model_1<-felm(y~x|group:time_id,data=data) > model_2<-felm(y~x|time_id+group:time_id,data=data) > model_3<-felm(y~x|group:time_id+ time_id+group,data=data) > model_4<-felm(y~x|group*time_id,data=data) > > lm_1 <- lm(y ~ x + group:time_id, data=data) > lm_2 <- lm(y ~ x + time_id + group:time_id, data=data) > lm_3 <- lm(y ~ x + group:time_id + time_id + group,data=data) > lm_4 <- lm(y ~ x + group*time_id,data=data) > > all.equal(coef(lm_1)["x"], coef(model_1)) [1] TRUE > all.equal(coef(lm_2)["x"], coef(model_2)) [1] TRUE > all.equal(coef(lm_3)["x"], coef(model_3)) [1] TRUE > all.equal(coef(lm_4)["x"], coef(model_4)) [1] TRUE > > all.equal(coef(model_1), coef(model_2)) [1] TRUE > all.equal(coef(model_3), coef(model_4)) [1] TRUE > > message('felm 1'); print(model_1) felm 1 x -0.00632 > message('lm 1'); print(lm_1) lm 1 Call: lm(formula = y ~ x + group:time_id, data = data) Coefficients: (Intercept) x groupA:time_id1 groupB:time_id1 -0.11916 -0.00632 0.09161 0.09356 groupC:time_id1 groupM:time_id1 groupP:time_id1 groupQ:time_id1 0.16257 0.18258 0.11876 0.05666 groupA:time_id2 groupB:time_id2 groupC:time_id2 groupM:time_id2 0.16614 0.14561 0.06515 0.12547 groupP:time_id2 groupQ:time_id2 groupA:time_id3 groupB:time_id3 0.18507 0.14228 0.08883 0.14574 groupC:time_id3 groupM:time_id3 groupP:time_id3 groupQ:time_id3 0.18161 0.10092 0.10974 0.13172 groupA:time_id4 groupB:time_id4 groupC:time_id4 groupM:time_id4 0.10959 0.08194 0.07567 0.18149 groupP:time_id4 groupQ:time_id4 groupA:time_id5 groupB:time_id5 0.12796 0.18306 0.08885 0.16327 groupC:time_id5 groupM:time_id5 groupP:time_id5 groupQ:time_id5 0.03526 0.07357 0.17912 NA > message('felm 2'); print(model_2) felm 2 x -0.00632 > message('lm 2'); print(lm_2) lm 2 Call: lm(formula = y ~ x + time_id + group:time_id, data = data) Coefficients: (Intercept) x time_id2 time_id3 -0.02755 -0.00632 0.07453 -0.00277 time_id4 time_id5 time_id1:groupB time_id2:groupB 0.01798 -0.00276 0.00195 -0.02053 time_id3:groupB time_id4:groupB time_id5:groupB time_id1:groupC 0.05690 -0.02765 0.07442 0.07097 time_id2:groupC time_id3:groupC time_id4:groupC time_id5:groupC -0.10099 0.09278 -0.03392 -0.05359 time_id1:groupM time_id2:groupM time_id3:groupM time_id4:groupM 0.09098 -0.04067 0.01208 0.07190 time_id5:groupM time_id1:groupP time_id2:groupP time_id3:groupP -0.01528 0.02716 0.01893 0.02091 time_id4:groupP time_id5:groupP time_id1:groupQ time_id2:groupQ 0.01837 0.09027 -0.03495 -0.02386 time_id3:groupQ time_id4:groupQ time_id5:groupQ 0.04288 0.07347 -0.08885 > message('felm 3'); print(model_3) felm 3 x -0.00632 > message('lm 3'); print(lm_3) lm 3 Call: lm(formula = y ~ x + group:time_id + time_id + group, data = data) Coefficients: (Intercept) x time_id2 time_id3 -0.02755 -0.00632 0.07453 -0.00277 time_id4 time_id5 groupB groupC 0.01798 -0.00276 0.00195 0.07097 groupM groupP groupQ groupB:time_id2 0.09098 0.02716 -0.03495 -0.02248 groupC:time_id2 groupM:time_id2 groupP:time_id2 groupQ:time_id2 -0.17196 -0.13165 -0.00823 0.01109 groupB:time_id3 groupC:time_id3 groupM:time_id3 groupP:time_id3 0.05495 0.02181 -0.07889 -0.00625 groupQ:time_id3 groupB:time_id4 groupC:time_id4 groupM:time_id4 0.07783 -0.02960 -0.10488 -0.01907 groupP:time_id4 groupQ:time_id4 groupB:time_id5 groupC:time_id5 -0.00878 0.10842 0.07246 -0.12456 groupM:time_id5 groupP:time_id5 groupQ:time_id5 -0.10625 0.06312 -0.05390 > > data[,'time+id'] <- data[,'time_id'] > m <- felm(y~x|`time+id`+group + group:`time+id`,data=data) > print(getfe(model_3)) Warning in is.estimable(ef, obj$fe) : non-estimable function, largest error 0.7 in coordinate 39 ("time_id:group.3.Q") Warning in getfe.kaczmarz(obj, se, ef = ef, bN = bN, robust = robust, cluster = cluster, : Supplied function seems non-estimable effect obs comp fe idx time_id.1 0.02367 1992 1 time_id 1 time_id.2 0.04138 2019 1 time_id 2 time_id.3 0.03121 1989 1 time_id 3 time_id.4 0.03138 1951 1 time_id 4 time_id.5 0.00000 2049 1 time_id 5 group.A -0.03031 1723 1 group A group.B -0.01613 1656 1 group B group.C -0.03444 1682 1 group C group.M -0.01048 1637 1 group M group.P -0.00104 1653 1 group P group.Q -0.03553 1649 1 group Q time_id:group.1.A -0.02091 337 2 time_id:group 1.A time_id:group.2.A 0.03591 348 2 time_id:group 2.A time_id:group.3.A -0.03123 344 2 time_id:group 3.A time_id:group.4.A -0.01064 323 2 time_id:group 4.A time_id:group.5.A 0.00000 371 2 time_id:group 5.A time_id:group.1.B -0.03314 339 2 time_id:group 1.B time_id:group.2.B 0.00120 345 2 time_id:group 2.B time_id:group.3.B 0.01149 312 2 time_id:group 3.B time_id:group.4.B -0.05247 302 2 time_id:group 4.B time_id:group.5.B 0.06023 358 2 time_id:group 5.B time_id:group.1.C 0.05418 316 2 time_id:group 1.C time_id:group.2.C -0.06095 326 2 time_id:group 2.C time_id:group.3.C 0.06567 341 2 time_id:group 3.C time_id:group.4.C -0.04043 330 2 time_id:group 4.C time_id:group.5.C -0.04946 369 2 time_id:group 5.C time_id:group.1.M 0.05023 331 2 time_id:group 1.M time_id:group.2.M -0.02460 325 2 time_id:group 2.M time_id:group.3.M -0.03898 318 2 time_id:group 3.M time_id:group.4.M 0.04143 336 2 time_id:group 4.M time_id:group.5.M -0.03511 327 2 time_id:group 5.M time_id:group.1.P -0.02303 330 2 time_id:group 1.P time_id:group.2.P 0.02557 366 2 time_id:group 2.P time_id:group.3.P -0.03959 328 2 time_id:group 3.P time_id:group.4.P -0.02154 321 2 time_id:group 4.P time_id:group.5.P 0.06100 308 2 time_id:group 5.P time_id:group.1.Q -0.05064 339 2 time_id:group 1.Q time_id:group.2.Q 0.01727 309 2 time_id:group 2.Q time_id:group.3.Q 0.01687 346 2 time_id:group 3.Q time_id:group.4.Q 0.06805 339 2 time_id:group 4.Q time_id:group.5.Q -0.08363 316 2 time_id:group 5.Q > print(getfe(m)) Warning in is.estimable(ef, obj$fe) : non-estimable function, largest error 0.4 in coordinate 30 ("`time+id`:group.4.M") Warning in getfe.kaczmarz(obj, se, ef = ef, bN = bN, robust = robust, cluster = cluster, : Supplied function seems non-estimable effect obs comp fe idx `time+id`.1 0.02367 1992 1 `time+id` 1 `time+id`.2 0.04138 2019 1 `time+id` 2 `time+id`.3 0.03121 1989 1 `time+id` 3 `time+id`.4 0.03138 1951 1 `time+id` 4 `time+id`.5 0.00000 2049 1 `time+id` 5 group.A -0.03031 1723 1 group A group.B -0.01613 1656 1 group B group.C -0.03444 1682 1 group C group.M -0.01048 1637 1 group M group.P -0.00104 1653 1 group P group.Q -0.03553 1649 1 group Q `time+id`:group.1.A -0.02091 337 2 `time+id`:group 1.A `time+id`:group.2.A 0.03591 348 2 `time+id`:group 2.A `time+id`:group.3.A -0.03123 344 2 `time+id`:group 3.A `time+id`:group.4.A -0.01064 323 2 `time+id`:group 4.A `time+id`:group.5.A 0.00000 371 2 `time+id`:group 5.A `time+id`:group.1.B -0.03314 339 2 `time+id`:group 1.B `time+id`:group.2.B 0.00120 345 2 `time+id`:group 2.B `time+id`:group.3.B 0.01149 312 2 `time+id`:group 3.B `time+id`:group.4.B -0.05247 302 2 `time+id`:group 4.B `time+id`:group.5.B 0.06023 358 2 `time+id`:group 5.B `time+id`:group.1.C 0.05418 316 2 `time+id`:group 1.C `time+id`:group.2.C -0.06095 326 2 `time+id`:group 2.C `time+id`:group.3.C 0.06567 341 2 `time+id`:group 3.C `time+id`:group.4.C -0.04043 330 2 `time+id`:group 4.C `time+id`:group.5.C -0.04946 369 2 `time+id`:group 5.C `time+id`:group.1.M 0.05023 331 2 `time+id`:group 1.M `time+id`:group.2.M -0.02460 325 2 `time+id`:group 2.M `time+id`:group.3.M -0.03898 318 2 `time+id`:group 3.M `time+id`:group.4.M 0.04143 336 2 `time+id`:group 4.M `time+id`:group.5.M -0.03511 327 2 `time+id`:group 5.M `time+id`:group.1.P -0.02303 330 2 `time+id`:group 1.P `time+id`:group.2.P 0.02557 366 2 `time+id`:group 2.P `time+id`:group.3.P -0.03959 328 2 `time+id`:group 3.P `time+id`:group.4.P -0.02154 321 2 `time+id`:group 4.P `time+id`:group.5.P 0.06100 308 2 `time+id`:group 5.P `time+id`:group.1.Q -0.05064 339 2 `time+id`:group 1.Q `time+id`:group.2.Q 0.01727 309 2 `time+id`:group 2.Q `time+id`:group.3.Q 0.01687 346 2 `time+id`:group 3.Q `time+id`:group.4.Q 0.06805 339 2 `time+id`:group 4.Q `time+id`:group.5.Q -0.08363 316 2 `time+id`:group 5.Q > > proc.time() user system elapsed 1.00 0.15 1.14