Fellow Statalisters (especially StataCorp)
I have a Stata 16 query about data frames. Is it possible to copy a dataset from one data frame to another without destroying the hidden data frames attached to the second?
For instance, I can run the following code:
sysuse auto, clear;
desc, fu;
preserve;
frame create myframe;
frame change myframe;
use http://www.stata-press.com/data/r11/lbw.dta, clear;
desc, fu;
frame copy myframe default, replace;
frame change default;
restore;
desc, fu;
When I do this, the execution proceeds to the restore command, and Stata gives me the reply:
nothing to restore
r(622);
presumably because my earlier frame copy command destroyed the old default frame and also the attached hidden frame created by preserve.
Is there a way of copying a dataset from one frame to another without destroying any attached hidden frames? My reason for wanting to do this is that I am trying to update my resultsset-creating programs to Stata Version 16, and enabling them to create resultsframes as well as resultssets, using a frame() option. (See Newson (2004) for more about resultssets.) I thought that, in most cases, the best way might be to start by creating the resultsset in a temporary data frame, and then to copy it to the pre-existing current frame if the user specifies the norestore option. However, when I try do do this, I find that I can no longer use my resultsset-generating program between a preserve statement and a restore statement.
I am wondering whether I should be less radical, and create the resultsset between a preserve statement and a restore statement as before, and create any resultsframes using frame create and frame copy. However, this seemed to be a little bit inefficient, because this would entail creating a whole new copy of the original current data frame in a hidden frame in memory, however enormous the original current data frame was. And this would be less inefficient than storing the original dataset on disk (as preserve used to do in Stata Version 15), but it still seems resource-intensive to me. It seemed to make so much more sense to create the resultsset in a temporary frame, and to list it if a list() option is specified, save it to a disk dataset if a saving() option is specified, copy the dataset to the original current frame if norestore is specified, and rename the temporary frame if a frame() option is specified. However, when I try to implement this method, using frame copy if norestore is specified, I find that I cannot copy the resultsset to the original current data frame without destroying any hidden data frames (created using preserve) attached to the pre-existing current frame. (Except maybe saving the dataset in the temporary frame to a tempfile and use-ing the temporary file in the pre-existing current frame, which seems very inefficient as file i/o is involved.)
Is there a fix to this problem? (This might be something to discuss at the UK Stata Conference at the end of this week.)
Best wishes
Roger
References
Newson RB. From datasets to resultssets in Stata. Presented at the 10th UK Stata User Meeting, 28-29 June, 2004. Download from https://ideas.repec.org/p/boc/usug04/16.html
0 Response to Can we copy the contents of one data frame to another without destroying hidden frames attached to the second?
Post a Comment