I got the same problem bofore, and Statalist returns as following, which, I
believe, will be useful for you as well:
I past the feedback from statalist:
(1) from Nick Cox:
The problem is that the backslash has different
interpretations. To you, and to Windows, it is
a separator which helps to indicate where a file
is. To Stata, it also has a different interpretation
as explained at [U] 21.3.10.
The best advice is to think Unix and use forward
slashes. Stata understands what you mean and will
translate to Windows.
(2) from Michael Blasnik:
Stata uses the \ character to indicate not to expand a macro when
interpreting a line. Rather than try to deal with \\ or other work arounds,
it seems fastest to just always use the / character in specifying paths (it
works on all platforms).
jt
----- Original Message -----
From: "Dasovic, Josip" <[email protected]>
To: <[email protected]>
Sent: Friday, May 07, 2004 4:31 PM
Subject: st: forvalues question
> I am working with the GSOEP (German Socioeconomic) panel survey. I have a
series of files for each of seventeen waves of the data, which are labeled
such that the file denoting the first year (wave) of data begins with the
letter a, the file denoting the second year (wave) of data begins with the
letter b, etc.. What I would like to do is to open each of the seventeen
files, keep the person id variable, and another variable, then save these
new files using the same filename as the original, with one small
exception--renaming the files with the year name (1984,1985, etc.) at the
end of the filename, dropping the wave-denoting letters (a,b, etc.) from the
filename altogether. To make this easier, I have created a short forvalues
loop:
>
> local wave "a b c d e f g h i j k l m n o p q r"
> local i=1985
>
> while `i'<=2001 {
> foreach x of local wave {
> use "C:\Directory\`x'filename.dta", clear
> keep personid `x'variable
> save "C:\Directory\filename`i'.dta", replace
> }
> }
>
> Once again, the successive year files begin with a letter matched to a
particular year; afilename, bfilename, cfilename, etc., where a=1985,
b=1986...r=2001.
>
> The short program above should open the file afilename.dta, keep the
required variables, and save the new file as filename1985.dta, and so on.
>
> The problem is that Windows doesn't seem to recognize the `x' after the \
symbol (in the third line of the program above). Is there a way to get
around this? I assume that Windows is disturbed by the placement of the
symbols \` beside each other.
>
> Stata gives me the following error message:
>
> file C:`x'filename.dta not found
>
> Thanks in advance,
>
> Josip
>
>
> *
> * 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/