Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Windows: improving on interaction of external text editors and Stata


From   [email protected]
To   [email protected]
Subject   st: Windows: improving on interaction of external text editors and Stata
Date   Sun, 27 Jun 2004 14:23:56 +0200

Dear list readers,

I hope this is of interest to some Stata users under Windows operating system. It follows up on a post by D. Masterov on Stata and vi (http://www.stata.com/statalist/archive/2004-06/msg00699.html), but the method should be the same for any text editor under Windows.

D. Masterov sent a nice solution which allows to send a do-file to an existing instance of Stata, using the free software AutoIt. I adopted his AutoIt-code (thanks a lot!) and wrote a version which allows to send some lines of Stata code to an instance of Stata already running, without the text file necessarily being saved to disk, and without losing whatever is the content of the clipboard. Also, the code is prevented from being accidentally pasted to the viewer, if open.

It works nicely for me (WinXP, WinEdt as editor). If anyone wants to adopt: Just change the lines containing the name of the Stata window and the installation path of Stata to your needs, compile this using Aut2Exe which comes with AutoIt (http://www.autoitscript.com/autoit3/), and write up a macro or the like for your text editor. For WinEdt, my macro goes
Run('%b\Config\MyStata\doclip.exe',"%p", 0,1,"run selection",0,1);  
where doclip.exe is the name of the compiled script.

Regards,
Eva Poen

;;; doclip.au3
;;; sending selected lines of code to Stata
;save the content of the clipboard
$OldClip = ClipGet()
;copy the selected line(s) to clipboard
Send("^c")
;remove extra linefeeds
$string = ClipGet()
$string = StringReplace($string,@lf,"")
;check if Stata window already open
   If WinExists("Intercooled Stata 8.2") Then
       WinWait("Intercooled Stata 8.2")
       WinActivate("Intercooled Stata 8.2")
       ;make Command Window active
       Send("^4")
       ControlSend ( "Intercooled Stata 8.2", "Stata Command", "RICHEDIT1", $string & "{Enter}")
   Else
       ;Run Stata
       Run("C:/Programme/Stata8/wstata.exe")
       WinWait("Intercooled Stata 8.2")
       WinActivate("Intercooled Stata 8.2")
       ;make Command Window active
       Send("^4")
       ControlSend ( "Intercooled Stata 8.2", "Stata Command", "RICHEDIT1", $string & "{Enter}")
   EndIf
;restore clipboard
ClipPut($OldClip)




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