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
classified after XT models - invalid subcommand classificationHello, I am using 4 binomial models. Logit, xtlogit re, xtlogit pa, and xtlogit fe. After logit I us…
how to do propensity score matchinghi everyone I m trying to do psm test but i do not what the wrong is this command correct or not? …
GDP on Gravity ModelI really need help on my panel regression. My dependent variable is bilateral trade flow. My Indepen…
Difference in difference with a single groupI may be misunderstanding something and need some help So I am looking at inheritances and want to …
Time taken by estimation?Hi everyone, I want to calculate the time gained by a maximum likelihood estimator in coming up wit…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop to import, edit, then export .csv files
Post a Comment