【发布时间】:2020-06-21 12:51:07
【问题描述】:
我是 Python 新手,正在尝试从 Python 执行 Stata do-file,使用 MacOS。
以下问题的建议:Run Stata do file from Python
我尝试了以下代码:
dofile = folder_path + "stata_dofile.do"
cmd = ["C:/Program Files (x86)/Stata14/StataSE-64", "do", dofile, variable1, variable2]
subprocess.call(cmd)
其中“dofile”是我想要执行的 Stata do 文件,“variable1”和“variable2”是我想要提供给 Stata 的一些字符串变量。
此代码在 Windows 上运行良好。但是当我尝试按如下方式使其适应 Mac 时:
dofile = folder_path + "stata_dofile.do"
cmd = ["/Applications/Stata/StataMP.app", "do", dofile, variable1, variable2]
subprocess.call(cmd)
我收到一条错误消息“权限被拒绝”。
根据这个论坛上的一些其他建议,我确实设法使用以下代码在我的 Mac 上从 Python 打开了 Stata 应用程序:
cmd = ["/usr/bin/open", "/Applications/Stata/StataMP.app"]
subprocess.call(cmd)
但这只是打开Stata,我不知道如何修改代码使其执行上面的do-file。
基本上我不知道自己在做什么。非常感谢任何提示!
【问题讨论】: