企业信息

    北京天演融智软件有限公司

  • 2
  • 公司认证: 营业执照已认证
  • 企业性质:
    成立时间:
  • 公司地址: 北京市 海淀区 海淀街道 上地东路35号院1号楼3层1-312318、1-312-319
  • 姓名: 张经理
  • 认证: 手机未认证 身份证未认证 微信已绑定

Stata/Python integration part 1: Setting up Stata

时间:2020-08-31点击次数:157


Python integration is one of the most exciting features in Stata 16. There are thousands of free Python packages that you can use to access and process data from the Internet, visualize data, explore data using machine-learning algorithms, and much more. You can use these Python packages interactively within Stata or incorporate Python code into your do-files. And there are a growing number of community-contributed commands that have familiar, Stata-style syntax that use Python packages as the computational engine. But there are a few things that we must do before we can use Python in Stata. This blog post will show you how to set up Stata to use Python.


Download and install Python

You may already have Python installed on your computer. You can check by typing python search in Stata.

The result tells us that no Python installations were found, so I will need to install Python. You may need to consult your system administrator if you are not the owner or administrator of the computer you are using.


You can download an installation file for Python at the Python download website. Python is available for Linux, Mac, and Windows, so you should select the installation file that corresponds to your operating system. You should select a 64-bit installation file because Stata/Python integration works only with 64-bit processors. Python 3.8.5 is the current version as I am writing this post, and I recommend using the latest version. Older versions of Python are available for download if you need them for backward compatibility, but versions older than Python 3.0 have now reached “end of life” status.


After you download the installation file, simply run it and follow the setup instructions. I have recorded a video that shows how to download and install Python for Windows 10 on a 64-bit computer.


Download and install Anaconda/Python

Python is also included in an open-source development environment called Anaconda. Many people prefer Anaconda because it automatically installs and manages many Python packages during installation. You can download the appropriate Anaconda installation file at the Anaconda download website. Anaconda is also available for Linux, Mac, and Windows, and you should select the 64-bit installation file that corresponds to your operating system. After you download the installation file, simply run it and follow the setup instructions. I have recorded a video that shows how to download and install Anaconda for Windows 10 on a 64-bit computer. 

Setting up Stata to use Python

After you install Python or Anaconda, or both, on your computer, you can return to Stata and again type python search in the Command window.

I have installed both Python 3.8 and Anaconda 3.0 on my computer. I can tell Stata which Python installation I wish to use with the set python_exec command. The example below tells Stata that I wish to use Python 3.8.

You can type python query to see which Python installation you are currently using.

You can use set python_userpath to set additional paths for Python to look up packages and modules that you create or download. The example below uses set python_userpath to add the folder where I save my personal Python modules.

You can type python query to see which Python installation you are currently using.

Now we’re ready to use Python within Stata! You can begin using Python interactively by typing python in the Command window. Stata will remind you that you can type end to exit Python and return to Stata. The example below uses Python to print() the sentence “Hello Stata, I am Python” to the screen.

It worked! This blog post is the first in a series that I am writing to show you how to use Python within Stata. My goal is to provide a basic foundation so that you will have the skills to explore Python packages that are useful to you. This post demonstrated how to install Python and set up Stata to use Python. In my next post, I will demonstrate several ways to use Python from within Stata.

近期,武汉大学经济与管理学院联合Stata软件中国授权经销商北京天演融智软件有限公司(科学软件网)在七-八月份举办Stata系列专题讲座以及Stata软件研讨会,得到了大家的一致**。在此,科学软件网为大家提供三场讲座的回放以及“Stata洞察数据科学研讨会” 中李春涛老师主讲的主题为 “中文地图与Stata” 和 肖光恩老师主讲的主题为 “新冠疫情数据的可视化与建模方法” 的演讲回放视频,全部免费,可直接扫码(页面下方直接点 试听 )免费观看

北京天演融智软件有限公司(科学软件网)是Stata软件在中国的授权经销商,为中国的Stata用户提供优质的软件销售和培训服务。



http://turntech88.b2b168.com