>>
Nick, Scott
thanks for your suggestions. I do not seem to be able to replicate your codes for what I want to do. My longer alternative was to do the following (this is only a subset, I have more files like these)
local z "ARG ARM AUS AUT BGD BOL CAN CHL CHN CMR COL CRI CYP DNK ECU EGY ESP ETH FIN FRA GBR GER GRC GTM HKG HND HUN IDN IND IRL IRN ITA JOR JPN KEN KOR KWT LKA LVA MAC MAR MDA MEX MWI MYS NLD NOR NPL NZL PAK PAN PER PHL POL PRT ROM SGP SWE THA TTO TUR TWN URY USA VEN ZAF"
foreach x of local z{
insheet using "C:\World Bank TPD data\\`x'bilateral.csv", clear
gen country="`x'"
keep if ccode=="MUS"
sort year
save "C:\World Bank TPD data\\`x'bilateral.dta", replace
}
I tried to replicate the above into Nick's codes as follows:
ssc inst fs
fs *bilateral.csv
foreach f in `r(files)' {
insheet using "C:\World Bank TPD data\\`"`f'"'",clear
local country : substr local f "bilateral.csv"
gen country = "`country'"
save "C:\World Bank TPD data\\`"`country'"'bilateral.dta", replace
}
But it does not seem to produce the saved stata file I want in the last cmmand line. I guess somewhere I must have called the macros in a wrong way. Any suggestions?
Many thanks
Dev
>>> [email protected] 07/19/05 2:19 am >>>
Try again:
Nick
[email protected]
> -----Original Message-----
> From: Nick Cox
> Sent: 19 July 2005 02:12
> To: '[email protected]'
> Subject: RE: RE: RE: reading the first X letters of a filename
>
>
> 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]
>
*
* 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/
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
*
* 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/