Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: reading all files in a directory
From
Daniel Marcelino <[email protected]>
To
[email protected]
Subject
st: reading all files in a directory
Date
Fri, 15 Apr 2011 21:13:06 -0300
Dear all,
I've a problem to read thousands of CSV files. I used to do that using
R for what I wrote some loops. For teaching purpose I'm converting
these codes into Stata language, so I wondering if someone could drive
me to that.
setwd("/Users/DM/Data") [here I set the woking
directoryin Stata I do this cd "/Users/DM/Data"]
files = list.files(pattern = "csv$") [here package scan for
every CSV file]
AC = c() [here I create an
emptydata set to allocate all CSV files]
for ( x in files ) { [here I read each file
found in working directory]
u = read.csv(x, header=T) [here in "u" I put every
read file "x"]
u$dataset = x
AC = rbind(AC, u) [finally, here I append every
read file to the `AC']
AC$state = c("AC") [and generate a flag to which set
of file it came from].
}
I just start writing a similar to Stata.
cd "/Users/DM/Data"
foreach x in files {
insheet using "/Users/DM/Downloads/v_2002.csv", delimiter(";")
gen state = "AC"
}
Daniel
--
Daniel Marcelino
http://danielmarcelino.zip.net
Skype: dmsilva.br
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/