Statalist


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

st: addendum: parse last command from ado file?


From   <Stefan.Gawrich@hlpug.hessen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: addendum: parse last command from ado file?
Date   Wed, 11 Nov 2009 12:52:37 +0100

Hi Statalisters,

the question was: 
While working in the command window: How can I access the last command
from within an ado in order to alter it in a specified way (without
having to retype anything) and run it again.

My example was to interchange row and column vars in a bivariate tab
command.

There is one very simple (halfway) approach to this (still requires some
manual input)

**************
program define tt
di "choose command"
di _request(tabcmd)
...parsing....
...rearrangement...
...run
**************

- Start ado (e.g. set function key F4 to tt;)
- choose recent command from review window or use "page up"-key from the
command line
- (Enter)
- Now the global $tabcmd is altered and executed.

User input is for example: F4 ->  2* PgUp -> Return (quite comfortable)

*****************

Second, a one-click-solution that works for me (Stata 10.1 on Win XP)
but I'm not shure if it will work in all settings.
In my setting the "#review"-command can be executed from the internal
do-editor but not from my external editor. So I created an one-liner
do-file "review.do" containing "#review 2 1"
I also set function key F4 to tt1;

The basic idea is:

**********************
Start ado (over function key)
The ado file: 
- opens a log
- executes #review with "do review.do"
- closes the log
- opens log via "file open"
- reads lines (using "file read ... line" in a "while"-loop until a line
starts with "2 " (the #review number)
- copies last line to local
And then:
...parsing....
...rearrangement...
...run
**********************

User input is: F4 (very comfortable)

Stefan

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index