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
Time of day labels in tempogramHi there, I am trying to plot a tempogram, where on the X-axis I have the time of the day (24hr) and…
Using if statement with gsemHi, I am using gsem and I want to use "if statement" so that I include some observations for my anal…
Creating a histogram with categorical dataHi everyone, I am trying to create a histogram with a string variable. In the example dataset below…
overcome serial correlation error terms in fixed effectsHi there, I was wondering if someone could clear up a problem I have. I have to review the assumpti…
margins without standard erros & outreg2 (cmclogit)Hello! While it's possible to store the results of the margins command (after cmclogit) with outreg…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop to import, edit, then export .csv files
Post a Comment