Dear All,
- I have a lot of files (such as t201304016.ftm, t201304026.ftm, and so on) in the same directory to be imported into Stata. The file `t201304016.ftm' contains intra-daily data on April 1 (0401), 2013, and `t201304026.ftm' on April 2 (0402), 2013. The last `6' in each file name does not have any meaning, though.
- I tried the following (I do not post the data set because it is big, and is not in Stata format):
Code:
fs *.ftm foreach v in `r(files)' { infix x1 1-6 /// x2 7-14 /// str code 15-20 /// th 21-22 /// tm 23-24 /// ts 25-26 /// tt 27-33 /// p 34-39 /// v 40-47 /// b1 48-53 /// b1v 54-61 /// b2 62-67 /// b2v 68-75 /// b3 76-81 /// b3v 82-89 /// b4 90-95 /// b4v 96-103 /// b5 104-109 /// b5v 110-117 /// s1 118-123 /// s1v 124-131 /// s2 132-137 /// s2v 138-145 /// s3 146-151 /// s3v 152-159 /// s4 160-165 /// s4v 166-173 /// s5 174-179 /// s5v 180-187 /// using `v', clear keep if code == "0050" gen d = `v' egen t = group(x2) order d t, first save `v'.dta, replace clear }
Code:. fs *.ftm t201304016.ftm t201304026.ftm . foreach v in `r(files)' { 2. infix x1 1-6 /// > x2 7-14 /// > str code 15-20 /// > th 21-22 /// > tm 23-24 /// > ts 25-26 /// > tt 27-33 /// > p 34-39 /// > v 40-47 /// > b1 48-53 /// > b1v 54-61 /// > b2 62-67 /// > b2v 68-75 /// > b3 76-81 /// > b3v 82-89 /// > b4 90-95 /// > b4v 96-103 /// > b5 104-109 /// > b5v 110-117 /// > s1 118-123 /// > s1v 124-131 /// > s2 132-137 /// > s2v 138-145 /// > s3 146-151 /// > s3v 152-159 /// > s4 160-165 /// > s4v 166-173 /// > s5 174-179 /// > s5v 180-187 /// > using `v', clear 3. keep if code == "0050" 4. gen d = `v' 5. egen t = group(x2) 6. order d t, first 7. save `v'.dta, replace 8. clear 9. } (3,142,057 observations read) (3,141,307 observations deleted) t201304016: operator invalid r(198); end of do-file r(198);
- In fact, I want to extract only one stock (code=0050), and save all the files for each day with name `v' (later to be appended altogether). Any suggestions is highly appreciated.
Comment