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

st: RE: forvalues question


From   "Huiber Gabi (nat1gxh)" <[email protected]>
To   [email protected]
Subject   st: RE: forvalues question
Date   Fri, 7 May 2004 16:42:36 -0400

One way to check if \` is where the problem's at would be:

cd c:/directory/

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 `x'filename
keep personid `x'variable
save filename`i', replace
}
}

Gabi

-----Original Message-----
From: Dasovic, Josip [mailto:[email protected]] 
Sent: Friday, May 07, 2004 4:31 PM
To: [email protected]
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