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
Related Posts with Can we copy the contents of one data frame to another without destroying hidden frames attached to the second?
Import and reshape data while capturing variable label from ExcelHello, I have 115 worksheets (each of them has about 100 variables) from excel to work with and the…
How to rename around 200 rows of a matrix simultaneously or in iterationHi, I'm very new to Stata and I've searched and tried answers for this question for three hours. I'm…
Generating date variables based on ID and yearDear Statalist community, I am working with a panel data set on armed conflict (UCDP/PRIO Armed Con…
Importing problem BRFSS SAS file post 2014I'm working with BRFSS data 2010-2015. Before 2014, I could open it by clicking the import option an…
Model Specification - Generalized DiD or TWFE Model (Need Suggesstions)Hello everyone, I am estimating the effect of a law change on certain policies for the US states. T…
Subscribe to:
Post Comments (Atom)
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