Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: dangerous preserve


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: dangerous preserve
Date   Tue, 22 Apr 2008 11:58:29 +0100

Sergiy is right to call my bluff. 

I had in mind ending a wrapper with -restore, not- but this cancels,
rather than postpones, the eventual -restore-. That does not rule out a
customised analogue of -preserve- and -restore- that made use of -save-
and then -use- but that would seem to create quite as many problems as
it solved. However, I was not recommending any such wrapper even in
principle. 

So, apart from suggestions of new features, the advice to Martin remains
to use -preserve- very cautiously and indeed, from several users, never
to make changes to data that cannot be repeated exactly by do files and
reversed by going back to the original data files, which you should not
overwrite. 

Nick
n.j.cox@durham.ac.uk 

Sergiy Radyakin

I agree to Nick's earlier comment about sharp knives. I do not agree
to Nick on the point that it is easy to write a wrapper around
"preserve" that would properly issue warnings, that Martin wishes. If
I write a safepreserve.ado which issues a warning, then preserves,
then whatever it preserved will be restored after it terminates. The
behaviour of preserve is necessarily built-in, since a corresponding
-restore- statement must be issued automatically after the end of the
current block of the program, even if it crashes. AFAIK this behaviour
can not be replicated with legitimate Stata syntax. Something can be
done with tempfile->save->capture{do something}->use,clear But it
restrictively disables all output. (How wonderful programming in Stata
could have been, if -capture- didn't do two things at once:
1. suppress the output
2. get the error code
These tasks should be performed by two different commands)

2Martin: the situation is directly opposite to the Windows Clipboard
(where the contents is lost when you copy the new content there
without any warnings). -Preserve- protects the data which is currently
in the memory, but not the source of the data that has been preserved.
Once you "preserve" any subsequent calls to -preserve- would be
denied, unless you directly specify "restore, not". "Preserve" should
also not be confused with "protect" as Excel understands it
("protected cells"). However, I would really like to see "protected
variables" in Stata, as working with plugins I have been bitten a
couple of times already, when the values were sent to the wrong
variables.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index