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

Re: st: Filenames of datasets

From   Henrik Stovring <>
Subject   Re: st: Filenames of datasets
Date   Thu, 27 Oct 2005 11:53:37 +0200

Not to discuss with myself, but I have received an answer to my query
below (briefly: why doesn't Stata by default keep track of the precise
location of the file the current dataset was opened from/saved in) from
Stata's Technical Support, which I would like to share with you:

You should be able to use the -creturn list- values -c(pwd)- and
-c(filename)- to create the path to a filename even if you have used the
-cd- command.

I think this is correct and corresponds with my understanding, but to me
this answer does not address the real issue: Careless (or just ordinary)
use of cd commands does not impact the filename reported in -describe-
nor the filename used in -save, replace-.

To me the sensible interpretation of a command like -save, replace-
would be that the data was saved in the actual dataset last
opened/stored, but this is not true if a change of directory has
occurred inbetween. Similarly, the -describe- command may point to a
dataset not to be found in the current directory without indication of
its true location.

So, summing up, I certainly agree that the values -c(pwd)- and
-c(filename)- can be used to keep track of the location of the
originating file of dataset - I just fail to understand why this
bookkeeping is not integrated into the default behavior of -save- and



Henrik Stovring wrote:
> Dear Stata and Statalist,
> Having recently worked on updating the -gzsave- package, I have become
> aware of some of the internal details in the way Stata handles the
> filename of a dataset. When a dataset is opened or saved, the global
> macro S_FN is set to contain the name of the file containing the
> dataset. A subsequent -describe- will then report this filename, while a
> -save- command without an explicit filename will save the dataset in
> memory to this filename.
> What puzzles me is that this system takes no account of any intermediate
> -cd- command. This means that if you open a dataset in your current
> directory, say dir1, change to another directory, say dir2, and do a
> -save, replace- then the dataset is saved in the dir2 directory with the
> same filename as the dataset from dir1. I think this might create some
> confusion, and to me the obvious remedy would be to let S_FN contain the
> complete path with the filename of the dataset opened/saved. This would
> also make the information presented with -describe- absolutely accurate,
> so that there can be no doubt as to which filename the data originated
> from. Alternatively (but to me less attractive), a flag could be set
> indicating whether or not the working directory has been changed since
> the dataset was last opened/saved, and perhaps even record the relative
> changes in directory location in another macro, so that this could be
> used by -save- and -describe- to point to the actual filename of the
> dataset.
> Best,
> Henrik

Henrik St°vring, PhD

Research Unit of General Practice
University of Southern Denmark
J.B. Winsl°ws Vej 9
DK-5000 Odense C
Phone: (+45) 6550 3692
Fax: (+45) 6591 8296
*   For searches and help try:

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