Python

In this part, we provide a brief introduction to Python for econometric analysis. This part consists of ten chapters:

In Chapter 1  Introduction to Python, we discuss how to install Python using Anaconda and introduce its basic syntax. We discuss commonly used IDEs such as Spyder and Jupyter Notebook. We then briefly describe important modules- NumPy, SciPy, Pandas, Matplotlib, Seaborn, and Statsmodels- that are useful for econometrics. Finally, we cover built-in data types (e.g., integers, floats, strings, booleans) and essential data structures like lists, tuples, and dictionaries.

In Chapter 2  Introduction to NumPy, we introduce the NumPy module. We start with arrays and matrices and discuss how they can be initialized. We cover basic operations on arrays and matrices, as well as fundamental linear algebra operations for matrices. Finally, we explore functions for rounding, sorting, and handling NaN values.

In Chapter 3  Control Structures, we cover control structures in Python, including conditionals, loops, and comprehensions for efficient iteration tasks. We also discuss statements for terminating or skipping certain iterations, as well as basic error and exception handling.

In Chapter 4  Custom Functions, we introduce how to write efficient custom functions. We cover the syntax for parameters, return values and help documentation. Finally, we discuss the anonymous lambda function that can be defined in a single line of code.

In Chapter 5  Statistical Functions, we introduce statistical functions from NumPy and SciPy for generating random draws from well-known distributions. We show how to evaluate density and cumulative distribution functions, and compute quantiles and other key statistics.

In Chapter 6  Graphics, we introduce Matplotlib and Seaborn for data visualization. We show how to generate line plots, scatter plots, histograms, bar charts, and density plots. We explore customization options such as adding titles, labels, and legends. Finally, we discuss methods for saving and exporting graphics in different formats.

In Chapter 7  Introduction to Pandas, we introduce the Pandas library for data management. We show how to import data from CSV files, Stata dta files, Excel spreadsheets, and from some other formats. We introduce Series and DataFrames and show how these objects can be initialized. We cover methods for filtering, sorting, grouping, and merging data. Finally, we show how to handle missing values.

In Chapter 8  Applications in Numerical Analysis, we cover some useful numerical methods for statistics and econometrics. We discuss optimization methods, numerical integration methods, and methods for solving ordinary differential equations.

In Chapter 9  Symbolic Computing, we introduce the SymPy library for symbolic computation. We explain how to define symbols, expressions, and functions. We present basic operations for manipulating expressions. We then briefly discuss symbolic methods for calculus and linear algebra.

Finally, in Chapter 10  Object-Oriented Programming, we introduce the basics of object-oriented programming (OOP) in Python. We explain how to define classes with attributes and methods, create objects, and use inheritance to build new classes from existing ones. We conclude by showing how to import classes from modules.

The material in this part mainly builds on Sheppard (2021), McKinney (2022), and VanderPlas (2023). For further details, readers can refer to the respective chapters in these references.