python 读写stata

import pandas as pd
from pandas.io.stata import StataReader, StataWriter
file="cfps2020famconf_202301.dta"
stata_data = StataReader(file, convert_categoricals=False)
data=stata_data.read()
varlist = stata_data.varlist#变量名列表
 
value_labels = stata_data.value_labels() 
 
fmtlist = stata_data.fmtlist
 
variable_labels = stata_data.variable_labels()
##data = pd.read_stata('cfps2020famconf_202301.dta')
##data.to_stata('output_file.dta')
##data.to_stata('output_file.dta', version=12)
###12版本号  默认为13
###也可以使用statsmodels和rpy2来读取

 

posted @ 2023-03-04 11:34  myrj  阅读(75)  评论(0编辑  收藏  举报