-- for Economists and Statisticians
Feng Li
School of Statistics and Mathematics
Central University of Finance and Economics
Economists have relied on Stata for over 30 years because of its breadth, accuracy, extensibility, and reproducibility.
Whether you are researching school selection, minimum wage, GDP, or stock trends, Stata provides all the statistics, graphics, and data-management tools needed to pursue a broad range of economic questions.
Python is a widely used general-purpose, high-level programming language.
Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.
The language provides constructs intended to enable clear programs on both a small and large scale.
The core philosophy of the language is summarized by the document "PEP 20 (The Zen of Python)" as
Python is compact and readable. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs.
Python is extensible: if you know how to program in C, it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed.
Open source!
Easy to learn and use with no programing experiences.
Rich ecosystem for modeling and data analysis
The language is named after the BBC show Monty Python’s Flying Circus
(1969-1974) and has nothing to do with reptiles.
Python has a large standard library, commonly cited as one of Python's greatest strengths, providing tools suited to many tasks.
The standard library is not essential to run Python or embed Python within an application.
As of March 2018, the Python package Index (PyPI), the official repository for third-party Python software, contains over 130,000 packages with a wide range of functionality.
Notable applications: web scraping, scientific computing, text processing, image processing
Python is free software.
On Windows and Mac, Anaconda (https://www.anaconda.com/) is the easiest way to perform Python data science and machine learning on a single machine.
To install Python on other systems, check out the Python Setup and Usage section in Python help documentation.
To start a Python interpreter, type the command in your terminal: python3
.
To terminate the Python interpreter, type an end-of-file character (Control-D
on Unix, Control-Z
on Windows) at the primary prompt. If that doesn’t work, you can exit the interpreter by typing the following command: quit()
.
fli@carbon:~$ python3
Python 3.9.7 (default, Sep 24 2021, 09:43:00)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
hello.py
with .py
extension#!/usr/bin/env python3
print('Hello World')
python3 hello.py
chmod +x hello.py
./hello.py
IPython is a command shell for interactive computing in multiple programming languages
To start IPython interactive environment, type ipython
in your terminal.
Help for Python module help('module')
Help for Python function help(function)
.
Use q
to quit the help session.
With IPython, use the command ?function
or function?
. ??function
or function??
can also be used to type the entire function including both the docstring
and the code.
This is the official documentation is available at https://docs.python.org/3.9/
To edit Python code, you just need a handy text editor. There are many available, check out the following pages
Use 4-space indentation, and no tabs.
Wrap lines so that they don't exceed 79 characters.
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
When possible, put comments on a line of their own.
Use docstrings
.
Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(x=3, y=4)
.
use CamelCase for classes and lower_case_with_underscores for functions and methods.
Always use self
as the name for the first method argument.
Do not use fancy encodings even if Python 3 has full UTF support. Plain ASCII works best in any case.