I am working on a data frame where I am trying to regress two columns(female dummy & scores) while grouping them by another column (country), and extracting the coefficient on female dummy.
I have tried using dplyr
, by first grouping my data frame by country, using group_by()
, then applying a regression, using group_map()
. First off, the coefficients that are shown in the result are all the same, for each group. Second I cannot seem to extract only the second coefficient, and when I try, the code says I cannot implement on a list
f1 %>% group_by(background) %>%
group_map(~ coef(lm(pv1math ~ female, data = f1))) %>%
group_map(~ coef[2])
I essentially want a series of the second coefficient.
I keep getting error for group_split
.
error in UseMethod("group_split") : no applicable method for 'group_split' applied to an object of class "list"