python - 从 vim 发送代码到 stata

标签 python linux bash vim stata

我在大学期间一直在使用 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,因为我可能会处理数据并进行更长时间的实证分析,我认为它可能对某些任务有用,例如解决这样的问题或从网站解析数据。这是推荐的,还是我应该看另一种语言(或者完全忘记这个想法)?

最佳答案

如果你打算(永远)切换到 Linux,你应该 1. 调用 stata 并将您的许可证切换为 linux 许可证(他们将免费提供)并本地安装,然后从 vim 启动 stata 只需要一个 bash 脚本(我不是 vim 专家) 2. 或者,您可以购买 stata 11,它对所有支持的平台都有一个许可证 3. 你可以用 wine 安装 stata(在 linux 上玩对我来说更容易)但是我无法让 wine 给 stata 超过半个内存,所以我安装了原生的 stata10

我将 gedit 用于 python、stata、R、latex 等,它可以处理任何事情,而 gtksourceview 非常容易添加语法高亮和样式等。

Python非常适合数据分析,请看

http://www.scipy.org/ http://openopt.org/欢迎 http://www.macworld.com/appguide/app.html?id=63924&expand=false

抓取网站有

http://scrapy.org/ http://wwwsearch.sourceforge.net/mechanize/

为了从文本中解析数据,通常我们有, http://pyparsing.wikispaces.com/

我有一堆你可能会觉得有用的文件(stata 和其他的 gtksoureview 语言定义,一些书的 pdf 副本(一些 copyleft))但是我不知道如何在这个网站上附加文件

关于python - 从 vim 发送代码到 stata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226145/

相关文章:

java - OpenJDK 9 IntelliJ IDEA (Ubuntu) "Can' t 解析符号”

python - celery 、Django 和@shared_task

Python unittest 仅跳过一个子类的测试

python - 向可变 tensorflow 添加随机噪声

C 编译器无法在 OpenSUSE 上创建可执行文件

linux - awk:根据给定列的前 3 个不同值选择行

linux - 运行 Bash 脚本,后跟关键字或变量

两个时间点之间的 Bash 历史记录

c - bash、sh、ps 在 Linux 中如何工作?

python 2、3、os.environ 和 unicode