桌面存在一个stata的do文件dofile.do:
clear all
sysuse auto
regress price weight length
python代码为:
#note:需要用到subprocess模块
import os
# 改变路径到stata程序所在目录
os.chdir("C:\\Program Files (x86)\\Stata14")
import subprocess
# stata程序名称为"StataMP-64.exe"
cmd = ["StataMP-64", "do", "C:\\Users\\zk\\Desktop\\dofile.do"]
subprocess.call(cmd)
可参看:https://stackoverflow.com/questions/21263668/run-stata-do-file-from-python