我一直在使用Vim在Windows中編寫Stata腳本,現在在大學裏。我現在正在學習R,並且我想完全切換到Linux作爲我的操作系統(我最近在我的筆記本電腦上切換到了Ubuntu)。 R在Windows和Linux中都能很好地與Vim兼容,但是我仍然需要使用Stata。在Windows中,我一直使用由Stata用戶提供的簡單AutoIt腳本將行/整個文件發送給stata進行評估。這個腳本在Linux中不起作用。將代碼從vim發送到stata
這是劇本的樣子
; AutoIt v3 script to run a Stata do-file from an external text editor
; Version 3.1, Friedrich Huebler, [email protected], 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,因爲我可能會使用數據並進行更長時間的實證分析,而且我認爲它可能對某些任務有用,例如解決像這樣的問題或從網站解析數據。這是建議,還是應該看另一種語言(或完全忘記這個想法)?
您可能想在單獨的主題中提出Python問題。但是R也有一整套解析網站數據的工具。如果您打算將R用於後續分析,則最好將R用於數據生成,因爲您可以使用正確的格式更容易地使用R.儘管如此,Python是一種有趣的語言。 – 2010-11-19 15:02:54