Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: reading the first X letters of a filename


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: reading the first X letters of a filename
Date   Tue, 19 Jul 2005 02:12:15 +0100

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 19 July 2005 01:59
> To: [email protected]
> Subject: st: RE: RE: reading the first X letters of a filename
> 
> 
> A different approach would appear more direct: 
> use -fs-, as publicised by Kit Baum yesterday. 
> 
> ssc inst fs 
> fs *bilateral.csv 
> foreach f in `r(files)' { 
> 	insheet using `"`f'"' 
> 	local country : substr local f "bilateral.csv" 
> 	gen country = "`country'" 
> 	...
> } 
> 
> Nick 
> [email protected] 
> 
> Dev Vencappa
> 
> > I am running the insheet command as follows:
> > 
> > insheet using "C:\World Bank TPD data\ARGbilateral.csv", clear
> > gen str5 country=="ARG"
> > ....
> > 
> > I have about 100 other csv files similar to the above. e.g. 
> > ARMbilateral, BRGbilateral, CRDbilateral, etc. I have to 
> > repeat the same command on each of these csv files. Instead 
> > of writing a macro that would store all these three letter 
> > names and calling them in a loop, I was wondering if there is 
> > a simpler way of asking Stata to read the first three letters 
> > of the file, check if it is followed by the name bilateral, 
> > read in the data and execute the commands that follow. 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index