Hi all,
I have a forval loop that is trying to take advantage of local macros for naming certain files. (Please note that there is code above this that allows for the .dta file to enter into this loop properly; I am showing only this portion to hone in on the problem I'm having--see my example output in the second code box below):
So, when I use a file called andersaa_VT_1909_1_trained.txt, my end goal is to have a file named fp_1_1901_1_trained.txt, where the number after fp will be different for each time through the loop.
What I get for my output upon running the above:
All of the displaying of my local variables works as expected, but then when the final file is saved, it uses "st" "yr" and "bch" instead of the actual values for those things ("VT", "1909", and "1", respectively). Since I'm running this and everything above it every time, I can't figure out why my local macros wouldn't be working in this case. Any help is greatly appreciated!
Best,
Sarah
I have a forval loop that is trying to take advantage of local macros for naming certain files. (Please note that there is code above this that allows for the .dta file to enter into this loop properly; I am showing only this portion to hone in on the problem I'm having--see my example output in the second code box below):
Code:
forval i = 1/`numvars' { import delimited "$dofile/output_data/`fp_`i''", delim("|") clear gen file = "`fp_`i''" dis file capture drop st yr bch gen st = substr(file, -21, 2) gen yr = substr(file, -18, 4) gen bch = substr(file, -13, 1) local state st dis `state' local year yr dis `year' local batch bch dis `batch' save "$temp/fp_`i'_`state'_`year'_`batch'", replace
What I get for my output upon running the above:
Code:
andersaa_VT_1909_1_trained.txt VT 1909 1 file C:/Users/andersaa/Documents/datatemp/fp_1_st_yr_bch.dta saved
Best,
Sarah
Comment