I am trying to append several excel files (about 80 files) with different names located in the same folder using Stata 17. I want to save all of them in one dataset with dta format. I have looked at previous posts about appending files and tried to test them for my issue. However, I can’t reach the desired result. Could you please help debug the issue?
The following is my code:
// step 1:
cd "C:\Users\pc1\Desktop\trd"
local files : dir "C:\Users\pc1\Desktop\trd" files "*.xlsx"
foreach file in `files' {
clear
import excel `file'
***newfolder is the folder where I want the dta files save here.
save newfolder\\`file'.dta, replace
}
// step 2:
local files : dir "C:\Users\pc1\Desktop\trd" files "*.dta"
foreach file in `files' {
append using newfolder\\`file'
}
The following is my code:
// step 1:
cd "C:\Users\pc1\Desktop\trd"
local files : dir "C:\Users\pc1\Desktop\trd" files "*.xlsx"
foreach file in `files' {
clear
import excel `file'
***newfolder is the folder where I want the dta files save here.
save newfolder\\`file'.dta, replace
}
// step 2:
local files : dir "C:\Users\pc1\Desktop\trd" files "*.dta"
foreach file in `files' {
append using newfolder\\`file'
}
Comment