1 Star 1 Fork 11

连享会/Stata-Event_Study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wrds2.py 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
# https://wrds-web.wharton.upenn.edu/wrds/support/Accessing%20and%20Manipulating%20the%20Data/_004Python%20Programming/_001Using%20Python%20with%20WRDS.cfmimport wrds
# https://github.com/wharton/wrds
import pandas
import sys
import time
import wrds
# parse arguments
query = sys.argv[1]
froot = sys.argv[2]
csv = sys.argv[3]
# execute query
print "Query: %s" % query
print "Output file root: %s" % froot
print "Querying..."
t0 = time.time()
result = wrds.sql(call=query, connection=wrds.CONN)
t1 = time.time()
print "Time to execute query: %s" % format(t1-t0, '.1f')
print "\n"
# preview output
print "Output preview:"
print(result.head())
print "\n"
# write to file
if (csv != ""):
print "Saving as %s.csv" % froot
result.to_csv(froot+".csv", index=False)
print "Saved as %s.csv" % froot
else:
print "Trying to save as %s.dta" % froot
try:
result.to_stata(froot+".dta", write_index=False)
print "Saved as %s.dta" % froot
except:
print "Error saving as %s.dta, falling back to %s.csv" % (froot, froot)
result.to_csv(froot+".csv", index=False)
print "Saved as %s.csv" % froot
# pause before closing window
print "\n"
raw_input("Press enter to return to Stata")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/arlionn/Stata-Event_Study.git
git@gitee.com:arlionn/Stata-Event_Study.git
arlionn
Stata-Event_Study
Stata-Event_Study
master

搜索帮助