Here is the code I have:
local dateList "01" "02" "03" "04" "05" "06" "07"
foreach date of local dateList {
use `"`date'"'
clear
import excel "V:\Report07" + `"`date'"' + "13.xls", sheet("MySheet") firstrow
sort PersonID Place
bysort PersonID (Place): gen mix = Place[1] != Place[_n]
sort PersonID
by PersonID: egen anymix=max(mix)
count if anymix==1
drop mix
drop anymix
}
I am trying to loop through multiple Excel files that differ by date, as you can see in the code where I put the variable date. For example, the name of this spreadsheet would be Report070113, representing the date July 1, 2013. The next time through the loop should import the report titled Report070213. I thought that the best way to do this would be to make an array of strings that are the various dates of the month so I can run the code month by month and get the count of each person who has visited different places. I know what is inside the loop works fine, but I am having trouble with the for loop itself. When I have:
use `"`date'"'
in the code (line 3) it gives me the following error:
file 01".dta not found
But when I don't include that line, it gives me this error:
using required
Any help would be appreciated; please let me know if my question is unclear.