Hi everyone! I'm trying to create a year variable for each .dta file that I have. Thankfully, the .dta files themselves indicate the year, but I'm failing to develop a foreach command which takes advantage of this.
My data is structured in the following manner:
"A 1986 B C D.dta"
"A 1988 B C D.dta"
"A 1993 B C D.dta"
"A 2001 B C D.dta"
"A 2006 B C D.dta"
"A 2015 B C D.dta"
Here's the command I tried:
After creating a year variable for each dta., I intend on appending these datasets.
I hope that was a clear description of my problem. Thank you very much.
My data is structured in the following manner:
"A 1986 B C D.dta"
"A 1988 B C D.dta"
"A 1993 B C D.dta"
"A 2001 B C D.dta"
"A 2006 B C D.dta"
"A 2015 B C D.dta"
Here's the command I tried:
Code:
local filelist: dir . files "A `x' B C D.dta" foreach file of local filelist { use "file", clear generate year = `x' save, replace }
I hope that was a clear description of my problem. Thank you very much.
Comment