Hello all,
I want to combine many .csv files. Each file has the name NYSEyyyymmdd.csv, where yyyymmdd is the date. For example yyyy= 1996, mm is month, e.g 01 for january, and dd is day, e.g. 01 for the first day of the month. The data are stock prices each day when the exchange is open, so even though the file names increases, there will be gaps for weekends, holidays, etc.
The following code does not work due to the gaps in file names:
local j = 1
forval i = 1/50 {
clear
insheet using "D:\NYSE\NYSE_1996010`i'.csv"
gen id = "`i'"
save file`j++', replace
}
local J = `j' - 2
forval j = `J'(-1)1 {
append using fole`j'
}
For example, this code then tries to import the file NYSE_19960106.csv, but because that was a Saturday, the file does not exist and Stata stops reading the code when a file is not found.
How can I make Stata continue reading even if one file is not in the folder?
Suggestions are appreciated!
Thomas Leirvik
I want to combine many .csv files. Each file has the name NYSEyyyymmdd.csv, where yyyymmdd is the date. For example yyyy= 1996, mm is month, e.g 01 for january, and dd is day, e.g. 01 for the first day of the month. The data are stock prices each day when the exchange is open, so even though the file names increases, there will be gaps for weekends, holidays, etc.
The following code does not work due to the gaps in file names:
local j = 1
forval i = 1/50 {
clear
insheet using "D:\NYSE\NYSE_1996010`i'.csv"
gen id = "`i'"
save file`j++', replace
}
local J = `j' - 2
forval j = `J'(-1)1 {
append using fole`j'
}
For example, this code then tries to import the file NYSE_19960106.csv, but because that was a Saturday, the file does not exist and Stata stops reading the code when a file is not found.
How can I make Stata continue reading even if one file is not in the folder?
Suggestions are appreciated!
Thomas Leirvik
Comment