I have the following code in Stata 17 that aims to run a command when the suffixes match. In other words, use days_a with freq_a, days_b with freq_b, and so on. However, it still gives me all combinations from valist 1 and varlist 2. Do you know what is wrong with my code? Thank you!
foreach var1 of varlist days_a days_b days_c days_d days_e days_f days_g days_h days_i days_j {
local var1suffix substr("`var1'", strpos("`var1'", "_")+1, length("`var1'"))
foreach var2 of varlist freq_a freq_b freq_c freq_d freq_e freq_f freq_g freq_h freq_i freq_j {
local var2suffix substr("`var2'", strpos("`var2'", "_")+1, length("`var2'"))
if "`var1suffix'" == "`var2suffix'" & "`var1suffix'" != "" {
total(`var1'), over(`var2')
}
}
}
0 Response to Creating a loop to run a command when the suffixes match
Post a Comment