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]

Re: st: Re: QUestion using -fs- package

From   "Michael N. Mitchell" <>
Subject   Re: st: Re: QUestion using -fs- package
Date   Tue, 08 Jun 2010 18:06:59 -0700

Dear Nuno

Thanks for letting us know that this helped and giving us more details about what you are doing. That makes perfect sense.

If you later should want to convert those country codes (stored as a character) into a numeric value, you can see

Best regards,

Michael N. Mitchell
Data Management Using Stata      -
A Visual Guide to Stata Graphics -
Stata tidbit of the week         -

On 2010-06-08 2.37 PM, Nuno Soares wrote:
Thank you everyone for the excellent tips! Statalist at its best!

Michael, I know the -save , replace- command is pretty scary, but I'm
using this bit of code on a given set of files and I'm aware of the
potential dangers. Thank you for the heads up!

Also, the reason for creating this variable is for using the name as
identifier in future analysis. The names of the files are countries

All the best,


On Tue, Jun 8, 2010 at 9:11 PM, Nuno Soares<>  wrote:
Hi everyone,

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

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

All the best,


*   For searches and help try:
*   For searches and help try:

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