fixest
fixest copied to clipboard
Bug with matrix of logical values on rhs of feols estimation
library(collapse)
library(fixest)
# This creates a lag-matrix of a logical variable
with(mtcars, L(as.logical(vs), 1:2))
#> L1 L2
#> [1,] NA NA
#> [2,] FALSE NA
#> [3,] FALSE FALSE
#> [4,] TRUE FALSE
#> [5,] TRUE TRUE
#> [6,] FALSE TRUE
#> [7,] TRUE FALSE
# This gives a bug
feols(mpg ~ L(as.logical(vs), 1:2) | cyl, mtcars)
#> NOTE: 2 observations removed because of NA values (RHS: 2).
#> Error in cpp_demean(y, X, weights, iterMax = fixef.iter, diffMax = fixef.tol, : The current SEXP type is not supported by the sMat class.
# Works with numeric data
feols(mpg ~ L(vs, 1:2) | cyl, mtcars)
#> NOTE: 2 observations removed because of NA values (RHS: 2).
#> OLS estimation, Dep. Var.: mpg
#> Observations: 30
#> Fixed-effects: cyl: 3
#> Standard-errors: Clustered (cyl)
#> Estimate Std. Error t value Pr(>|t|)
#> L(vs, 1:2)L1 0.829345 0.275969 3.00521 0.095181 .
#> L(vs, 1:2)L2 1.243851 0.747170 1.66475 0.237875
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> RMSE: 3.05353 Adj. R2: 0.711392
#> Within R2: 0.057662
feols(mpg ~ L(as.integer(vs), 1:2) | cyl, mtcars)
#> NOTE: 2 observations removed because of NA values (RHS: 2).
#> OLS estimation, Dep. Var.: mpg
#> Observations: 30
#> Fixed-effects: cyl: 3
#> Standard-errors: Clustered (cyl)
#> Estimate Std. Error t value Pr(>|t|)
#> L(as.integer(vs), 1:2)L1 0.829345 0.275969 3.00521 0.095181 .
#> L(as.integer(vs), 1:2)L2 1.243851 0.747170 1.66475 0.237875
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> RMSE: 3.05353 Adj. R2: 0.711392
#> Within R2: 0.057662
Created on 2022-05-18 by the reprex package (v2.0.1)