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
Twang - psHi, I am working with Twang. I am running the specification suggested by RAND tutorials for binary t…
How to estimate panel vecm in stata?Hi everyone, could someone kindly enlighten me on how to perform panel vecm model and estimate the l…
How to visualize multiple mediation with moderatorI want to visualize following command sureg(m1 x)(m2 x)(y1 m1 m2 w m1w x) (y2 m1 m2 x) I can't ana…
Loop to extract multiple strings specified in a localHi there. I have string data in the format described below. I want to generate a new variable "Event…
Decomposition real oil prices to three shocks kilian 2009(SVAR)Dear all I have three variables : average of global crude oil, real activity index , real oil price.…
Subscribe to:
Post Comments (Atom)
0 Response to Using loop to import, edit, then export .csv files
Post a Comment