Hi, let's say I want to create a series of dummy variables as follows:

Code:
order work_deg_sector*,sequential
egen dummy1_1970 = anymatch(work_deg_sector_1998_01-work_deg_sector_2005_04) if byear==1970,v(1)
egen dummy1_1971 = anymatch(work_deg_sector_1998_01-work_deg_sector_2006_05) if byear==1971,v(1)
egen dummy1_1972 = anymatch(work_deg_sector_1998_01-work_deg_sector_2007_05) if byear==1972,v(1)
egen dummy1_1973 = anymatch(work_deg_sector_1998_01-work_deg_sector_2008_08) if byear==1973,v(1)
egen dummy1_1974 = anymatch(work_deg_sector_1998_01-work_deg_sector_2009_03) if byear==1974,v(1)

gen dummy1 = .
replace dummy1 = dummy1_1970 if byear==1970
replace dummy1 = dummy1_1971 if byear==1971
replace dummy1 = dummy1_1972 if byear==1972
replace dummy1 = dummy1_1973 if byear==1973
replace dummy1 = dummy1_1974 if byear==1974


egen dummy2_1970 = anymatch(work_deg_sector_1998_01-work_deg_sector_2005_04) if byear==1970,v(2)
egen dummy2_1971 = anymatch(work_deg_sector_1998_01-work_deg_sector_2006_05) if byear==1971,v(2)
egen dummy2_1972 = anymatch(work_deg_sector_1998_01-work_deg_sector_2007_05) if byear==1972,v(2)
egen dummy2_1973 = anymatch(work_deg_sector_1998_01-work_deg_sector_2008_08) if byear==1973,v(2)
egen dummy2_1974 = anymatch(work_deg_sector_1998_01-work_deg_sector_2009_03) if byear==1974,v(2)

gen dummy2 = .
replace dummy2 = dummy2_1970 if byear==1970
replace dummy2 = dummy2_1971 if byear==1971
replace dummy2 = dummy2_1972 if byear==1972
replace dummy2 = dummy2_1973 if byear==1973
replace dummy2 = dummy2_1974 if byear==1974
I want to create multiple dummy variables. Accordingly, I would like a loop that changes the "dummy1" name to "dummy2" when the loop also changes "v(1)" to "v(2)". However, I am not fully sure how to do this. For example, if I run the loop below, then it'll try to create dummy1 and dummy2 twice, using each values that goes into v()

Code:
local dvars dummy1 dummy2 
foreach d of local dvars {
foreach i of numlist 1 2 {

egen `d'_1970 = anymatch(work_deg_sector_1998_01-work_deg_sector_2005_04) if byear==1970,v(`i')
egen `d'_1971 = anymatch(work_deg_sector_1998_01-work_deg_sector_2006_05) if byear==1971,v(`i')
egen `d'_1972 = anymatch(work_deg_sector_1998_01-work_deg_sector_2007_05) if byear==1972,v(`i')
egen `d'_1973 = anymatch(work_deg_sector_1998_01-work_deg_sector_2008_08) if byear==1973,v(`i')
egen `d'_1974 = anymatch(work_deg_sector_1998_01-work_deg_sector_2009_03) if byear==1974,v(`i')

gen `d' = .
replace `d' = `d'_1970 if byear==1970
replace `d' = `d'_1971 if byear==1971
replace `d' = `d'_1972 if byear==1972
replace `d' = `d'_1973 if byear==1973
replace `d' = `d'_1974 if byear==1974


}
}
What would be the most efficient way of creating these multiple dummies? Note that the dummies will have entirely different names (e.g., south, north).

Please let me know if I should clarify anything