I’m still trying to learn how to iterate the creation of my variables, so that I don’t have to write out sets of R code for each month’s calculation of minimum wage earners. I’ve been slowly but steadily learning regular expressions, pertinent functions in R like get()
, within()
, paste()
, apply()
, assign()
, and loops of course. But I’m unable to piece these concepts together to iterate the creation of variables that calculate my estimates for each month, through years 2010 to 2020. Would you be able to show me how to do that? My latest R code is below:
year2010analysis1_m1 <- year2010 %>%
filter(hourwage == 7.25, paidhour == 2, month == 1, statefip == 13) %>%
group_by(new_race = haven::as_factor(new_race),
sex = haven::as_factor(sex),
agerange = haven::as_factor(agerange)
) %>%
summarize(n = sum(earnwt))
I want to iterate the creation of variable names at the last character (…_m1, …_m2, …_m3, etc.) and also iterate the numbers in the “month” argument in my filter function to be month ==1, month==2 within the next iterated variable, and so on. Shamefully, I’m still doing this manually right now ☹
Grateful for any help with this,
Ray