Statalist


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

Re: st: How to restore dataset after preserve, but keep some specific variables?


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: How to restore dataset after preserve, but keep some specific variables?
Date   Thu, 25 Jun 2009 15:04:49 +0100

On Thu, Jun 25, 2009 at 2:59 PM, Stata Chris<[email protected]> wrote:
> Good morning,

Good afternoon ;-)

> I need to do similar calculations, generating a new variable, on
> different subsamples of my dataset,
> and was therefore planning to use the preserve command each time
> before cutting the dataset,
> and then, after having generated the respective variable, restore to
> return to the full dataset.
>
> The problem with this is that once I restore the data, my new variable
> is gone as well.
> I first thought I could store this in a local macro,
> but when I wanted to summarize all macros at the end of the dofile, it
> turned out Stata wanted to use the lost variable, having apparently
> remembered only that the macro consisted of said variable, but not the
> distribution of the variable itself.

You don't provide any examples of the code you are using so its
difficult to advise, but I suspect you may well get some mileage out
of -bysort-

> So my question is: How can I after each of these rounds generally
> return to the full dataset,
> but keep the one new variable?

If you're problem isn't conducive to -bysort- then -save-ing each
subset of data with the new variable, -append-ing them to each other
and then -merge-ing them with the original would likely get you there.

Neil


-- 
"The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data." ~ John Tukey (1986), "Sunset salvo". The American
Statistician 40(1).

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index