My code to summarise data looks like this:
sec_02 <- employment_mf_02 %>%
  select(sex, industry, hhwt) %>% 
  group_by(industry) %>% 
  count(industry, sex, wt = hhwt) %>% 
  pivot_wider(names_from = "sex", values_from = "n") %>% 
  mutate(Industry_sum = Male + Female,
         Msec = Male / Industry_sum,
         Fsec = Female / Industry_sum)
sec_04 <- employment_mf_04 %>%
  select(sex, industry, hhwt) %>% 
  group_by(industry) %>% 
  count(industry, sex, wt = hhwt) %>% 
  pivot_wider(names_from = "sex", values_from = "n") %>% 
  mutate(Industry_sum = Male + Female,
         Msec = Male / Industry_sum,
         Fsec = Female / Industry_sum)
sec_06 <- employment_mf_06 %>%
  select(sex, industry, hhwt) %>% 
  group_by(industry) %>% 
  count(industry, sex, wt = hhwt) %>% 
  pivot_wider(names_from = "sex", values_from = "n") %>% 
  mutate(Industry_sum = Male + Female,
         Msec = Male / Industry_sum,
         Fsec = Female / Industry_sum)
I understand that I can put employment_mf_xx in a list and use a for-loop to do this. However, this would change the underlying data, but I want to create new dataframes sec_02 sec_04 and sec_06. Is there a way I can do this?
Thank you.
 
    