Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
tashi lama <ltashi32@hotmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: creating 2 datasets in memory without saving and merge |

Date |
Fri, 27 Apr 2012 19:08:31 +0000 |

This works great...This not only resolves my problem but also educates me the tempfile command. I knew tempfile, read about it in the past but didn't really know its application. Now I do. Thanx > Subject: Re: st: RE: creating 2 datasets in memory without saving and merge > From: sandersn@stanford.edu > Date: Fri, 27 Apr 2012 11:33:08 -0700 > To: statalist@hsphsun2.harvard.edu > > Tashi, > > Yes, my sloppiness has come to light - one should add a "clear" command, either after "save file1" or as a option to loading the second data file. > > > > On Apr 27, 2012, at 11:19 AM, tashi lama <ltashi32@hotmail.com> wrote: > > > Hello, > > That is exactly correct Nick Sanders. I followed your instructions and did the following and got an error... > > > > > > > > > > clear > > set more off > > odbc query indigo > > odbc load, exec("select distinct source_id, count(*) as hits from readership where date(read_date) between '2011-01-01' and '2011-01-05' group by source_id order by count(*) desc") > > list > > tempfile file1 > > save `file1' > > odbc load, exec("select distinct firm_id as source_id, name from brokers") > > list > > merge 1:1 source_id using `file1' > > list > > > > > > And go the error > > > > > > > > odbc load, exec("select distinct source_id, count(*) as hits from readership where date(read_date) between '2011-01-01' and '2011-01-05' group by source_id order by count(*) > >> desc") > > > > . > > . tempfile file1 > > > > . save `file1' > > file C:\Users\Tashi\AppData\Local\Temp\ST_0e000001.tmp saved > > > > . odbc load, exec("select distinct firm_id as source_id, name from brokers") > > you must start with an empty dataset > > r(18); > > > > Any idea. > > > > > > > > Tashi > > > > > > > > > >> Subject: Re: st: RE: creating 2 datasets in memory without saving and merge > >> From: sandersn@stanford.edu > >> Date: Fri, 27 Apr 2012 10:29:16 -0700 > >> To: statalist@hsphsun2.harvard.edu > >> > >> Hello Tashi, > >> > >> I'm assuming you don't want to save one of the data sets because you have no interest in those data by themselves, only the final merged data, and have no desire to have a bunch of .dta files lying around. If that's the case, one potential solution is the use of a temporary file (via -tempfile-) which will be deleted after closing out Stata (if you close out properly). > >> > >> e.g.: > >> > >> insheet using somefile.csv > >> sort var1 > >> tempfile file1 > >> save 'file1' > >> > >> insheet using anotherfile.csv > >> sort var1 > >> merge var1 using 'file1' > >> > >> > >> -Nick > >> > >> On Apr 27, 2012, at 10:15 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > >> > >>> 1. You can hold precisely one (1) dataset in memory in Stata at once. This is circular in so far as what you hold in memory is always regarded as one (1) dataset, regardless of whether that dataset was originally two or more datasets in some sense, Stata or not Stata. Nevertheless the circularity is not vicious. > >>> > >>> 2. There are various ways of combining two or more datasets, including the use of -merge- or -append- and just typing or pasting in new data into the Editor. > >>> > >>> 3. Whether a dataset has been -save-d is a different question. No rule says that you must -save- data. It would be a waste of effort to combine datasets and not -save- the results if you intend to -use- that dataset later, but that's a practicality, not a rule. > >>> > >>> 4. Why you say that whatever you have in mind is "not good" is completely unclear to me. > >>> > >>> Nick > >>> n.j.cox@durham.ac.uk > >>> > >>> tashi lama > >>> > >>> I will be using 2 diff databases to get my data in stata. And I need to merge those two data to use for my analysis. One obvious way is to get the data from database 1 and save it with .dta file. Then use another database to pull data in stata memory(this is doable since my memory is clear) and use merge command. Unfortunately, this method is not good since i will have to save one dataset. Is there anyway I could pull two datasets in the memory without saving anyof the datasets? Or, what are my choices to get my intended result. Please let me know if my question is not clear. > >>> > >>> * > >>> * 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/ > > * > > * 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/ * * 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/

**References**:**st: creating 2 datasets in memory without saving and merge***From:*tashi lama <ltashi32@hotmail.com>

**st: RE: creating 2 datasets in memory without saving and merge***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: creating 2 datasets in memory without saving and merge***From:*Nick Sanders <sandersn@stanford.edu>

**RE: st: RE: creating 2 datasets in memory without saving and merge***From:*tashi lama <ltashi32@hotmail.com>

**Re: st: RE: creating 2 datasets in memory without saving and merge***From:*Nick Sanders <sandersn@stanford.edu>

- Prev by Date:
**Re: st: odbc load** - Next by Date:
**st: Mata efficiency: st_views and st_selects** - Previous by thread:
**Re: st: RE: creating 2 datasets in memory without saving and merge** - Next by thread:
**st: RE: RE: creating 2 datasets in memory without saving and merge** - Index(es):