Code:
* Example generated by -dataex-. For more info, type help dataex clear input str215 V1 "C:/Users/nilim/Csv Files/file_04_06_on_2020_12_09/file_04_06_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_07_on_2020_12_09/file_04_07_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_08_on_2020_12_09/file_04_08_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_09_on_2020_12_09/file_04_09_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_10_on_2020_12_09/file_04_10_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_11_on_2020_12_09/file_04_11_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_12_on_2020_12_09/file_04_12_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_13_on_2020_12_09/file_04_13_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_14_on_2020_12_09/file_04_14_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_15_on_2020_12_09/file_04_15_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_16_on_2020_12_09/file_04_16_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_17_on_2020_12_09/file_04_17_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_18_on_2020_12_09/file_04_18_on_2020_05_31.csv" "C:/Users/nilim/Csv Files/file_04_19_on_2020_12_09/file_04_19_on_2020_05_31.csv" end
Code:
use filenames.dta, clear forval i = 1/`=_N' { use filenames.dta, clear local bla = cond(_n==`i', V1, .) import delimited `bla', clear (??????) save ??????? }
1. The first ???? - local bla = cond(_n==`i', V1, .) & import delimited `bla', clear commands do not seem to be working/
2. The second ???? - I want to save the files with the same name as they are saved in the csv. For example - the file "C:/Users/nilim/Csv Files/file_04_06_on_2020_12_09/file_04_06_on_2020_05_31.csv" should be saved as "C:/Users/nilim/Csv Files/file_04_06_on_2020_12_09/file_04_06_on_2020_05_31.dta"
Even if someone can help with only a portion of this problem I'll be happy to take it. I have been stuck at this problem for quite some time and I can't seem to find a workaround.
P.S. I tried doing this in R - which handles datapoints 'individually' within a set much simply but some columns in these csvs have too many characters and R can't open them. (Stata 17 / SE (the version I am on) can - I checked for a few csvs without using the loop)
Do help
0 Response to Using strings in a Stata dataset as filenames
Post a Comment