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

re: st: forvalues question


From   "Owens, Douglas Hamilton" <[email protected]>
To   <[email protected]>
Subject   re: st: forvalues question
Date   Fri, 7 May 2004 21:00:25 -0000

Two solutions:
use the unix style forward slash for directories rather than the MS windows
backslash.  Stata likes forward slashes (a.k.a. virgule or solidus).

Option 2: continue using backslashes, but recognize that backslashes can
operate to "escape" the usual function of special characters, like a left
single quote.  So whenever you have a backslash followed by a left single
quote insert another backslash to form a consecutive pair. 



"Dasovic, Josip" <[email protected]> wrote:

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/



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