Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Saving datasets temporarily - switching back and forth between two datasets


From   Phil Clayton <[email protected]>
To   [email protected]
Subject   Re: st: Saving datasets temporarily - switching back and forth between two datasets
Date   Sat, 19 Nov 2011 09:11:25 +1100

Have you looked at -tempfile-? It allows you to save datasets to a temporary file from within a do-file. You don't need to specify the file name and they automatically get deleted.

So you could, for example, do something like this:
use masterdataset
(refine)
tempfile master
save `master'
use usingdataset1
(refine)
tempfile using1
save `using1'
use usingdataset2
(refine)
tempfile using2
save `using2'
use `master'
merge ...

You may also want to check out -mmerge- which is an extension to -merge- (available from SSC). It allows you to do things such as:
- merge on a variable that has a different name in each dataset
- rename variables from the "using" dataset on the fly
- specify that you only want to merge in a subset of observations from the "using" dataset

I often find that with -mmerge- I can accomplish what I need in one command, or occasionally two if I need to remove some duplicates after merging.

Phil

On 19/11/2011, at 8:54 AM, Ben Hoen wrote:

> I am executing a merge between one main dataset and a few others.  Some of
> the other datasets need some additional refining before they can be merged
> easily (e.g., changing variable names, culling out duplicates), but I have
> no need to save off these temporary versions.
> 
> Is it possible to hold the main dataset in "memory" while I quickly refine a
> using dataset, then save IT into memory, from where I perform the merge?
> 
> Tangentially, if I was to save off a temporary file to merge to, can I erase
> that file from a do-file?  
> 
> Did that make sense?
> 
> Ben
> 
> Ben Hoen
> Principal Research Associate
> Lawrence Berkeley National Laboratory
> Office: 845-758-1896
> Cell: 718-812-7589
> [email protected]
> http://eetd.lbl.gov/ea/emp/staff/hoen.html
> 
> 
> 
> 
> *
> *   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/


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