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
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 } }
Please let me know if I should clarify anything
0 Response to Looping with paired values but not for every variable
Post a Comment