I am using dplyr
+ the broom
package to run separate regression for each subgroup in my
my_data %>% group_by(my_groups) %>%
do(tidy(lm( attended_school ~ treated + I_post_treatmet, data=.)
))
(the actuall data is of restricted access, can't share here)
I get the following error:
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
If I understood correctly this means the regression could not be run for some subgroup, possibly due to all NAs in some variable.
How can I catch those errors so that in the end I receive a dataset containing the regression outputs for the subgroups in which the regressions ran sucessfully?
EDIT: tryed a syntax similar to the link suggested in the comments and got the same problem:
my_data %>% group_by(my_groups) %>%
do(aa=tryCatch(lm( attended_school ~ treated + I_post_treatmet, data=.)
))
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases