'Rewriting a loop in functional form maintaining object names
I am trying to rewrite the following loop in form of a generalizable funtion:
count = 1
for (i in alc) {
alc[[count]] <- fwildclusterboot::boottest(i, param = "treatment", clustid = "university", B = 9999)
count = count + 1
}
In this code, alc is a list of fixest regression objects. The point of the code is to replace each component of the list with the wild-cluster-bootstrap estimates of each model, while maintaining the names of the objects. It is imperative that the name of the original list remains exactly the same since broom::glance will not work otherwise (e.g., using purrr::map, or other functional programming methods).
I have tried the following code, although this code does not work properly which surprises me; using get("alc")[[1]] in the console seems to give a proper output.
boot_estimates <- function(x, count=1) {
## get the name of the input x
y <- deparse(substitute(x))
## replace elements of the name with bootstrapped versions
for (i in x) {
get("y")[[count]] <- boottest(i, param = "treatment", clustid = "university", B = 9999)
count = count + 1
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
