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: wishlist


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: wishlist
Date   Tue, 6 Aug 2013 21:39:10 -0400

Peter,  see if my -exi3- is more suitable for your request; the
description, screenshots and installation instructions are here:
http://www.radyakin.org/statalist/2013080602/exi3.htm


On Tue, Aug 6, 2013 at 6:02 PM, Nick Cox <[email protected]> wrote:
> Presumably this happens if you type
>
> exit, clear

Nick, if option clear is present, Stata will not ask what to do with
changed data files.
This happens when the Stata window is closed with the X-button (in
Windows), but not when a command -exit- is issued from a command line.
With unsaved changes Stata will abort with error (error code 4) or
exit silently if option clear is specified. With no unsaved changes
Stata exits without asking, but this is not an interesting case.
>
> but realise that you didn't mean it. Faced with your mild curses,
> Stata (if it could engage in repartee) would then merely quip that it
> did what you asked.
>
> I guess you want a command rather than a do-file. Is this something
> like the command?
>
> program sexit
>          version 8.2
>          save, replace
>          exit
> end

Nick, I guess this -exit- needs the -STATA- option (which used to be
documented, but disappeared from recent versions of the manual, but
continues to work at least with your version 8.2 statement), otherwise
i recon nothing will happen: Stata will exit from the sexit program,
right?

Unconditional saving is also questionable. Presumably you don't want
the changes to auto.dta to get saved after you try a new program
crunching it. Or another program (e.g. another instance of Stata) may
have modified the file in the meanwhile, and you don't want it to be
overwritten. Or the data might have never been saved before. And if
one could remember which command -exit- or -sexit- to type at any
moment, one wouldn't need it anyways.

So the user, as Peter requested must be given a choice of the three
actions, and only in the case when the data is modified. this is
possible. It is much more interesting and challenging to capture the
window closing event, and react to that, so that your custom
confirmation window appears regardless whether you call the special
command like sexit to exit, or just close Stata with the system's
method. However as we know, when Stata is closed with X-button it will
let the user save the data anyways, so we don't need to handle that
case here (we would need to had we wanted instead e.g. to save in the
old format using saveold).



Question to all the list is the following:

use mydata
gen x=1
preserve
drop x
gen y=1
NOW CLOSE STATA SESSION WITH X-BUTTON

It asks me if I want to save changes. It saves modified dataset with y
only. But it does not seem to -restore- the data later (that I
preserved) and which differs from original version (by variable x
only), and of which I indicated that I want to get back with
-preserve-. If -restore- had fired, Stata would again find unsaved
data in the memory and should have asked what to do with it. This
means that if my command was called from a deep stack of commands that
could modify data and call preserve before calling the next in chain,
the inner command has no way to exit with saving the changes to those
outer layers. :(

PS: those who visit the description page I suggest might notice that
my file name input dialog looks ugly. This is because although
standard Stata's dialog for file saving 'db save' is available, it
can't be called from a do file and followed by exit, actual save will
only be executed after the whole program terminates (which is
inconvenient).

clear all
generate x=1
save_dlg
window stopbox note "`=c(changed)'"

I will have to think more about how to call the save dialog in Stata 9
(!) and perform the save operation while generating the dialog on the
fly (if that is at all possible).

Best, Sergiy


>
> It's deliberate that this fails if there is no data in memory because
> then it fails to do what is intended, -save- data and -exit-.
>
>
> Nick
> [email protected]
>
>
> On 6 August 2013 22:39, Lachenbruch, Peter
> <[email protected]> wrote:
>> I have a small request (which never is?)
>> When I exit Stata I have often forgotten to save my changes - I have the chance to lose my changes or go back (click no).  I'd like a third option - save changes and exit.  It should be an easy do file...
>>
>>
>> Peter A. Lachenbruch,
>> Professor (retired)
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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