PYTHON 读STATA

# 导入stata_setup模块
from pandas import json_normalize
import pandas as pd
import stata_setup,json
# 通过stata_setup.config关联 Stata17  
stata_setup.config(r"D:\Stata17", "mp")
# 填入 Stata17 的本地路径及版本类型
from pystata import stata
#stata.run(r'use d:/statashu/2/CGSS2015, clear')
stata.run(r'sysuse auto, clear')
stata.run(r'des')
myret = stata.get_return()
myeret = stata.get_ereturn()
mysret = stata.get_sreturn()
(1978 automobile data)

Contains data from D:\Stata17/ado\base/a/auto.dta
 Observations:            74                  1978 automobile data
    Variables:            12                  13 Apr 2020 17:45
                                              (_dta has notes)
-------------------------------------------------------------------------------
Variable      Storage   Display    Value
    name         type    format    label      Variable label
-------------------------------------------------------------------------------
make            str18   %-18s                 Make and model
price           int     %8.0gc                Price
mpg             int     %8.0g                 Mileage (mpg)
rep78           int     %8.0g                 Repair record 1978
headroom        float   %6.1f                 Headroom (in.)
trunk           int     %8.0g                 Trunk space (cu. ft.)
weight          int     %8.0gc                Weight (lbs.)
length          int     %8.0g                 Length (in.)
turn            int     %8.0g                 Turn circle (ft.)
displacement    int     %8.0g                 Displacement (cu. in.)
gear_ratio      float   %6.2f                 Gear ratio
foreign         byte    %8.0g      origin     Car origin
-------------------------------------------------------------------------------
Sorted by: foreign
>>> myret
{'r(changed)': 0.0, 'r(widthmax)': 1048576.0, 'r(k_max)': 5000.0, 'r(N_max)': 1099511627774.0, 'r(width)': 43.0, 'r(k)': 12.0, 'r(N)': 74.0, 'r(datalabel)': '1978 automobile data'}
>>> 

 

posted @ 2023-04-16 16:31  myrj  阅读(43)  评论(0编辑  收藏  举报