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

st: Re: forvalues question


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: forvalues question
Date   Fri, 7 May 2004 16:41:13 -0400

use / instead of \ and Stata will know what you mean.  \ is Stata's symbol
for stopping macro expansion.

Michael Blasnik
[email protected]

----- 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/



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