Statalist


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

st: AW: parse last command from ado file?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: parse last command from ado file?
Date   Tue, 3 Nov 2009 17:56:43 +0100

<> 

BTW, there is also -#review- which displays the last executed commands quite
bravely. I do not think that it leaves anything behind, though, for your ado
to pick up. Also, some commands do leave the command as typed in
-e(cmdline)-...




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Dienstag, 3. November 2009 17:31
An: [email protected]
Betreff: st: parse last command from ado file?

Hi Statalisters,

working in the review window is it possible to access the last command
from an ado file? 

My example:
I create a lot of bivariate tables from the review window and e.g. later
copy them to a spreadsheet. 
Often tables are too wide but fit with rows and columns interchanged.

sysuse auto
tab rep78 trunk // too wide
tab trunk rep78 // fits

I thought about sparing some typing by writing a small ado that swaps
rows and columns of the last shown table. 

For this I need to parse the last command inside the ado. If for
instance I could have it in a global (without typing the next line, of
course)
global tabcmd "tab rep78 trunk, row col"


...I could write a program like this:
program define tt
local commapos = strpos("$tabcmd",",")
local options = substr("$tabcmd",`commapos',.)
local commapos1 = `commapos' - 1
local tabc = substr("$tabcmd'",1, `commapos1')
di "`tabc'"
local tab : word 1 of `tabc'
local var1 : word 3 of `tabc'
local var2 : word 2 of `tabc'
`tab' `var1' `var2' `options'
end

and exchange rows and columns of the last table by simply typing "tt".
(A more sophisticated program could also swap row and column options and
so on)


Regards 

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/


*
*   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