stata绘制桑基图需要调用Python,所以第一步是安装Python然后再在stata安装sankey命令包运行命令即可
一、安装Python
去官方网站https://www.python.org/downloads/windows/下载相应的Python安装包,安装
参考帖子:Python安装教程https://bbs.pinggu.org/forum.php ... 00&from^^uid=11374248
二、下载stata的sankey和python安装包
-
- net install sankey, from([url]https://www.mjcrowther.co.uk/code/sankey[/url])
- ssc install python,replace
参考网站:
https://www.mjcrowther.co.uk/software/sankey/
如果出现如下问题
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
参考网站:
https://www.statalist.org/forums/forum/general-stata-discussion/general/1622989-sankey-visual-analysis
https://blog.stata.com/2020/09/01/stata-python-integration-part-3-how-to-install-python-packages/
如果在窗口出现错误ValueError: check_hostname requires server_hostname
参考网站:
https://www.jianshu.com/p/d4af07d5af27
三、注意
1.startvar stopvar不能是字符串,需要用encode(刚开始用了字符串,结果出不来)
2.安装命令
- net install sankey, from([url]https://www.mjcrowther.co.uk/code/sankey[/url])
- help sankey
- ssc install python,replace
- python query
- python which numpy
- shell
然后在打开的窗口里输入(网址是清华镜像,下载速度会快一些):
pip -V
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple plotly
再回到stata打开数据输入sankey的命令
- use [url]https://www.mjcrowther.co.uk/data/sankey_eg1[/url]
- sankey start stop freq, colors(3 "green" 6 "red") linkcolor(lightgreen)
3.图形导出是网页版的,有时候加载很久也出不来,不确定是什么原因
4.节点不能太多,要不显示不出来5.startvar 和stopvar 为不同的值
参考:https://www.statalist.org/forums ... 1629010#post1629010


雷达卡




京公网安备 11010802022788号







