我在大学里使用 Vim 在 Windows 中编写 Stata 脚本已有一段时间了。我现在正在学习 R,我想完全切换到 Linux 作为我的操作系统(我最近在笔记本电脑上切换到了 Ubuntu)。R 在 Windows 和 Linux 中都能很好地与 Vim 配合使用,但有时我仍然需要使用 Stata。在 Windows 中,我一直在使用 Stata 用户提供的简单 AutoIt 脚本将行/整个文件发送到 stata 进行评估。此脚本在 Linux 中不起作用。
这是脚本的样子
; AutoIt v3 script to run a Stata do-file from an external text editor
; Version 3.1, Friedrich Huebler, fhuebler@gmail.com, www.huebler.info, 30 March 2009
; Declare variables
Global $ini, $statapath, $statawin, $dofile, $winpause, $keypause, $clippause
; File locations
; Path to INI file
$ini = @ScriptDir & "\rundo.ini"
; Path to Stata executable
$statapath = IniRead($ini, "Stata", "statapath", "C:\Program Files\Stata10\wsestata.exe")
; Title of Stata window
$statawin = IniRead($ini, "Stata", "statawin", "Stata/SE 10.1")
; Path to do-file that is passed to AutoIt
; Edit line to match editor used, if necessary
$dofile = $CmdLine[1]
; Delays
; Pause after copying of Stata commands to clipboard
$clippause = IniRead($ini, "Delays", "clippause", "100")
; Pause between window-related operations
$winpause = IniRead($ini, "Delays", "winpause", "200")
; Pause between keystrokes sent to Stata
$keypause = IniRead($ini, "Delays", "keypause", "1")
; Set SendKeyDelay and WinWaitDelay to speed up or slow down script
Opt("WinWaitDelay", $winpause)
Opt("SendKeyDelay", $keypause)
; If more than one Stata window is open, the window
; that was most recently active will be matched
Opt("WinTitleMatchMode", 2)
; Check if Stata is already open, start Stata if not
If WinExists($statawin) Then
WinActivate($statawin)
WinWaitActive($statawin)
; Activate Stata Command Window and select text (if any)
Send("^4")
Send("^a")
; Run saved do-file
; Double quotes around $dofile needed in case path contains blanks
ClipPut("do " & '"' & $dofile & '"')
; Pause avoids problem with clipboard, may be AutoIt or Windows bug
Sleep($clippause)
Send("^v" & "{Enter}")
Else
Run($statapath)
WinWaitActive($statawin)
; Activate Stata Command Window
Send("^4")
; Run saved do-file
; Double quotes around $dofile needed in case path contains blanks
ClipPut("do " & '"' & $dofile & '"')
; Pause avoids problem with clipboard, may be AutoIt or Windows bug
Sleep($clippause)
Send("^v" & "{Enter}")
EndIf
; End of script
在我的 vimrc 中有以下内容
" STATA DO-FILE SCRIPTS
fun! RunIt()
w
!start "C:\Programme\Stata10\integvim\rundo3\rundo.exe" "%:p"
endfun
map <F8> :<C-U>call RunIt()<CR><CR>
imap <F8> <Esc>:<C-U>call RunIt()<CR><CR>
fun! RunDoLines()
let selectedLines = getbufline('%', line("'<"), line("'>"))
if col("'>") < strlen(getline(line("'>")))
let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
endif
if col("'<") != 1
let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)
endif
let temp = tempname() . ".do"
call writefile(selectedLines, temp)
exec "!start C:\\Programme\\Stata10\\integvim\\rundo3\\rundo.exe " . temp
au VimLeave * exe "!del -y" temp
endfun
map <F9> :<C-U>call RunDoLines()<CR><CR>
imap <F9> <Esc>:<C-U>call RunDoLines()<CR><CR>
这真的很实用,几乎是我仍然坚持使用 Windows 的唯一原因。我将如何为 Ubuntu 获得类似的东西?我是 linux 新手,除了统计之外,对编程知之甚少。任何帮助是极大的赞赏。(请不要推荐 emacs,emacs 对 stata 的支持是错误的,虽然它与 R 的集成要好得多,但我现在想继续使用 Vim。)
关于一个可能相关的话题:我正在考虑学习 Python,因为我可能会在更长的时间内处理数据并进行经验分析,我认为它可能对某些任务有用,例如解决此类问题或解析来自网站的数据。这是推荐的,还是我应该看另一种语言(或完全忘记这个想法)?