RE: st: QUestion using -fs- package

<>
" di in r "`c(filename)'"
works directly."
I had said as much earlier
<http://www.stata.com/statalist/archive/2010-06/msg00453.html> but this
leaves you with the path as well, so I posted an additional thought how one
could get rid of the path and have the filename only...
No need for single/double quotes, btw, in any case: -di in r c(filename)-
HTH
Martin
-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Dienstag, 8. Juni 2010 22:50
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: QUestion using -fs- package
di in r "`c(filename)'"
works directly.
Nick
n.j.cox@durham.ac.uk
Martin Weiss
"2) You (or someone else) might be interested in putting a -note- in the
data file
(rather than a variable). If you wanted to do that, you could change the
-gen- command to be
note : This comes from the `f' data file"
The -note- is fine, but you could at any point in time replicate it via
***********
sysuse auto, clear
qui _getfilename "`c(filename)'"
di in r r(filename)
***********
Michael N. Mitchell
I think you are 99% of the way there. I think the problem is that the
variable -file-
needs to be a string variable, thus you might try this....
qui fs *.dta
foreach f in `r(files)' {
use `f', clear
cap drop file
gen str50 file="`f'"
save, replace
}
Two other thoughts...
1) the -save , replace- is a pretty scary command. If you make a bad
mistake you could
destroy the original file. So, when doing something experimental like
this,
it is prudent
to have a solid backup of all the data files.
2) You (or someone else) might be interested in putting a -note- in
the
data file
(rather than a variable). If you wanted to do that, you could change the
-gen- command to be
note : This comes from the `f' data file
On 2010-06-08 1.11 PM, Nuno Soares wrote:
> I'm using the -fs- command to look into a directory for several files,
open
> them, insert a new variable with the file name, and save them. The
code is
> 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
> r(198);
>
> Basically the gen file=`f' command is returning the above error. Any
way
of
> doing what it is intended to do?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/