'Multiple estimations with different databases and export using package fixest (loop?)

I am trying to reproduce this STATA estimation using R. But I have problems when estimating with different databases, I tried with sw, split and lapply, but it doesn't work.

STATA code

foreach var in "y1"  "y2"  "y3"   {
   foreach sample in db1 db2 db3 db4 {
   foreach FE in  "i" "j" "k"  {
    foreach control in  "c1 c2 c3" {
     foreach indvar in "x1" "x1"  "x3"    {
     reghdfe `var' `indvar' `control' if `sample'==1, a(`FE') vce(cl i)
     outreg2 using `var'2.xls, append cti(Dep Var: `var', FE: `FE', ) 
    }
   }
  }
 }
}

R code

tt=iris %>% filter(Sepal.Length>5.5)
tt2=iris

list_models <- lapply(split(tt, tt2), function(x) feols(c(Sepal.Length,Petal.Width) ~ csw(Sepal.Width,Petal.Length), data = x))

res4 = feols(c(Sepal.Length,Petal.Width) ~ csw(Sepal.Width,Petal.Length) | Species, sw(tt,tt2))
etable(res4)
#Error in feols(c(Sepal.Length, Petal.Width) ~ csw(Sepal.Width, Petal.Length) |  : 
#  Argument 'data' could not be evaluated. Problem: could not find function "sw".


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source