I have some codes as follows (as you may know this is the result after many previous helps from forum):
It seems only the first "if" code works. The second part "else" does not work, because when the loop bumps into the condition that "`firsrt'" == "DEF", it still runs as if it is "`firsrt'" == "ABC", then notified error.
Why does this code not work?
I am targeting transform data from many excel sheets at the same position in many excel files. They are in 2 forms: some have beginning variable as "ABC" and the remaining as "DEF", and the structures of theirs are different following these different forms too. That's why I must run 2 different do-file for them.
Many thanks for your help.
Code:
clear import excel "path_letter.xls", sheet("..") firstrow levelsof Letter, local(name_list) foreach name of local(name_list) { clear import excel "path_`name'.xls", sheet("..") cellrange(A5) firstrow foreach var of varlist _all { local vars "`vars' `var'" } local first: word 1 of `vars' if "`first'" == "ABC" { do "path.do" } else if "`first'" == "DEF" { do "path2.do" } save "path_`name'_2.xls" }
Why does this code not work?
I am targeting transform data from many excel sheets at the same position in many excel files. They are in 2 forms: some have beginning variable as "ABC" and the remaining as "DEF", and the structures of theirs are different following these different forms too. That's why I must run 2 different do-file for them.
Many thanks for your help.
Comment