Hello,
I am importing a large number of .csv files into Stata. Before I can import the files, I need to remove several of the columns in the csv. (If I keep them in, it makes the later analysis very difficult). The number and name of the columns is constant across all the files.
I've used the code below with the intention of importing each of the csv files in the folder, dropping the unwanted columns, and saving each modified csv into a new file with a "_new" suffix. The code below works - however, it stops after the first file and does not continue through the rest of the files.
local filenames: dir . files "*.csv"
foreach file of local filenames {
import delimited "`file'" , delimiter(",") clear
drop v2 v3 v4 //dropping the unwanted columns
local new : subinstr local file ".csv" "_new.csv", all
export delimited using "`new'", replace
}
Does anyone have advice on what is missing here? Any advice or pointers would be appreciated.
Related Posts with Using loop to import, edit, then export .csv files
droping multiple observationsMy data looks like the one below. and I want to delete the observations that dont have hhid (the thr…
How can you make a by() bar graph plot side-by-side bars on one plot rather than two subfigures?I want to change the attached graph so that instead of appearing as two sub-figures, there is just o…
ytitle "unrecognized"Hi all, I've been trying to replicate a figure from code I got from the authors of a paper. When I …
How can I change the order of the bars in this bar graph?I am a beginner Stata user. For a research project, whose information I must unfortunately keep conf…
xtsccDears, I have question regarding XTSCC. As I read this can be used to deal with cross-section depen…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop to import, edit, then export .csv files
Post a Comment