Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: QUestion using -fs- package

From   "Nick Cox" <>
To   <>
Subject   st: RE: QUestion using -fs- package
Date   Tue, 8 Jun 2010 21:34:09 +0100

First off, -fs- is user-written from SSC. You are asked to make this
kind of detail clear in postings. 

As you say, your problem is not with -fs-. It is what you do with its

-fs- leaves in its wake a macro containing (in this case) one or more

For some reason you want each data file to contain a variable which
includes its own name. 
I don't know why, but set that aside. 

The key point is that each name is necessarily a string value. Thus you
need " " to act as delimiters. 

gen file = "`f'" 

Otherwise Stata will try to make sense of the RHS as some combination of
variables and operators, which won't work for this kind of data. 


Nuno Soares

I'm using the -fs- command to look into a directory for several files,
them, insert a new variable with the file name, and save them. The code
the following:

qui fs *.dta
foreach f in `r(files)' {
	use `f', clear
	cap drop file
	gen file=`f'		
	save, replace

However, when I run the code I get the following error code:
wscopear:  operator invalid

Basically the gen file=`f' command is returning the above error. Any way
doing what it is intended to do?

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index