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

st: running do-files from vi

From   "Dimitriy V. Masterov" <>
Subject   st: running do-files from vi
Date   Wed, 23 Jun 2004 14:24:41 -0500 (CDT)

I've been trying to find a way to run a do-file that I am editing in vi
from vi. I think I came up with a way to do this that you might find
useful. The advantage of this method is that it does not open a new Stata
session (unless there is not one open). It essentially turns F8 into a
save-n-do button like the one in the Stata Do-Editor.

This works for Stata SE on XP and gvim. It may work elsewhere with the
appropriate modifications.

Step 1
I used a free and open source program called AutoIt to create a script
that I run from vi. You can download the software from

I created a file called do.au3 that contained the following code. You
might want to change the pathnames to suit your setup

; This program do.au3:
; (1) Opens a Stata session if one Is NOT yet open
; (2) Gets the do file path and then runs that file:
; Once you compiled the script to make do.exe:
; Syntax is "run c:/.../do.exe c:/.../"
; DVM 6/22/04

If WinExists("Stata/SE 8.2") Then
	;Put in the pathname from the vi loop
	WinWaitActive("Stata/SE 8.2")
	Send("do " & '"' & $CmdLine[1] & '"' & "{Enter}")
	;Run Stata
	Run("c:/program files/stata8/wsestata.exe")
	WinWaitActive("Stata/SE 8.2")
	Send("do " & '"' & $CmdLine[1] & '"' & "{Enter}")

Step 2
Compile the do.au3 script using AutoIt2 program. This will make the do.exe

Step 3
In your _gvimrc file, include the following lines. Make sure the pathnames
are correct.

" These 2 commands will map F8 to
" (1) save and run the current do-file in Stata
" (2) open a Stata session if one is not open and execute (1)

:map <F8> :<C-U>call RunIt() <Enter>
:imap <F8> <Esc>:<C-U>call RunIt() <Enter>
" <C-U> cancels the range in case you have a count pending in Normal mode
or if you use it from Visual mode.

fun! RunIt()
  !start "c:/program files/autoIt3/examples/english/my programs/do.exe"

Step 4
Hit F8 to test of this works.

*   For searches and help try:

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