I have following code which let two local macros expand in a file path.
But after running the looping, the files are saved under C: directly,
instead of the directory suggested by the code.
local path = "C:/EPI Projects/RRFSS Trends/"
local fname = "Smoking Vehicle\vehicle0"
cd "C:\EPI Projects\RRFSS Trends\data"
forval i = 1/4 {
insheet cat prop ucl lcl popsize using raw0`i'.txt, clear
generate year = 200`i'
save "`path'/`fname'`i'", replace
}
Messages from STATA after running the above code
forval i = 1/4 {
2. insheet cat prop ucl lcl popsize using raw0`i'.txt, clear
3. generate year = 200`i'
4. *save "C:\EPI Projects/RRFSS, replace
. save "`path'/`fname'`i'", replace
5. }