Apologies, I am not very good at coding.
I have +12,000 files in which I need to add the file name (the file names include information about the names of investment funds and the quarters of the fund holdings) as a variable in each file and then append these files into one large file. I have a problem with the first part, saving the file names as names.
The following is an example of one of the file names: Adrigo Hedge portfolio 2006-12-31.dta
I split the files into two folders as they exceed 10,000 which I understand is the maximum when using 'foreach' to loop over files. I then tried the following code to to save the file names as a substrings (dropping '.dta')
local allfiles : dir . files "*.dta"
foreach file of local allfiles {
I do not receive any error message so I do not know what is wrong with the code. Can anybody please help me with this?
Mari Paananen
I have +12,000 files in which I need to add the file name (the file names include information about the names of investment funds and the quarters of the fund holdings) as a variable in each file and then append these files into one large file. I have a problem with the first part, saving the file names as names.
The following is an example of one of the file names: Adrigo Hedge portfolio 2006-12-31.dta
I split the files into two folders as they exceed 10,000 which I understand is the maximum when using 'foreach' to loop over files. I then tried the following code to to save the file names as a substrings (dropping '.dta')
local allfiles : dir . files "*.dta"
foreach file of local allfiles {
preserve
use `file'.dta, clear}
gen str fund_date = substr(`file', 1, strlen(file') - 4)
save temp, replace
restore
append using temp, force
I do not receive any error message so I do not know what is wrong with the code. Can anybody please help me with this?
Mari Paananen
Comment