- 输出示例如下: ``` Python Settings set python_exec /usr/bin/python3 set python_userpath Python system information initialized no version 3.8.9 architecture 64-bit
启动 Python 会话:
在 Stata 中输入 python 来启动 Python,会话中可以直接运行 Python 代码。输入 end 返回 Stata 环境:
clear all use http://www.stata-press.com/data/r16/iris python: from sfi import Data import numpy as np from sklearn.svm import SVC # Use the sfi Data class to pull data from Stata variables into Python X = np.array(Data.get("seplen sepwid petlen petwid")) y = np.array(Data.get("iris")) # Use the data to train C-Support Vector Classifier svc_clf = SVC(gamma='auto') svc_clf.fit(X, y) end
测试 pystacked:
运行以下代码,测试 pystacked 是否正常运行:
clear all use https://statalasso.github.io/dta/cal_housing.dta, clear set seed 42 gen train=runiform() replace train=train<.75> set seed 42 pystacked medh longi-medi if train