Teaching macroeconomics with an open-source online model simulation in R and Python
Karsten Kohler
Leeds University Business School
k.kohler at leeds.ac.uk
Published February 2024
A new DIY Macroeconomic Model Simulation platform provides free pedagogical resources for the simulation of macroeconomic models in the open-source programming languages R and Python.
Why an online macroeconomic model simulation?
Teaching mathematical economic models is not an easy task. Between solving equations and shifting curves, students often struggle to grasp the underlying economic intuition. Seeing the connection between a system of equations and the causal stories a model aims to tell is not always facilitated by the diagrams and algebra commonly used in macroeconomics textbooks.
Yet, there is another way of building a thorough understanding of economic models: computer simulations. Simulations allow students to solve economic models and visualise their results through plots. They enable a comparison of a model’s results under different scenarios, helping to develop an understanding of the causal mechanisms embedded in a model. In this way, algebra can be postponed to a later stage, prioritising the building of intuition.
To facilitate the use of such computer simulations for the teaching of macroeconomics, I have built a new open-source website along with Franz Prante (Chemnitz University of Technology, Germany).
What does the website offer?
The DIY Macroeconomic Model Simulation platform provides a code repository and online script for macroeconomic model simulation. It follows a Do-It-Yourself (DIY) approach, empowering users to numerically simulate key macroeconomic models on their own using the open-source programming languages R and Python. In this way, the platform offers resources to deepen users’ understanding of both macroeconomic modelling and coding. The platform’s DIY approach aims to foster reproducibility and open-source principles in macroeconomics education by providing learning materials that are freely available and modifiable by everyone. The platform’s content will expand over time through new entries added by the project team.
The platform covers an array of macroeconomic models, including canonical textbook models, models from different economic paradigms (e.g. Neoclassical, New Keynesian, Post Keynesian), and seminal models from the history of economic thought (e.g. Malthus and Ricardo). It bridges a gap between intermediate and advanced level macroeconomics by providing detailed yet accessible treatments of seminal macroeconomic models.
Using it for teaching intermediate and advanced macroeconomics
The website’s content directly lends itself for use in seminars and computer lab sessions. The first chapter of the website provides an introduction to the programming languages R and Python, which can be used in class or assigned as homework to make students familiar with basic principles of coding. The chapter allows students to work through examples of basic operations as well as some simple exercises. Chapter 2 then introduces the general principles of numerical simulation and explains how to visualise the output from a simulation run.
After that, the website presents a series of different macroeconomic models. These model entries are largely self-contained and can be used independently of each other. For each model, the chapters provide three main components:
- Model descriptions that concisely explain the key ideas, assumptions, and equations of each model. This helps users grasp the underlying concepts and intuition behind the models.
- Annotated code that allows users to numerically simulate the models, examine their results under different scenarios, and produce visualisations to better understand the models’ structure and output.
- Analytical discussions for users who are interested in delving deeper into the mathematical properties of the models.
To further facilitate the understanding of dynamic models in which variables change over time, Chapter 9 offers a general introduction to the mathematical analysis of dynamic models.
First impressions from using simulations in a macroeconomic module at the postgraduate level
The website’s content was used in the seminars of a postgraduate macroeconomics module in 2023-2024. The purpose was twofold: first, to enable students to develop a deeper understanding of some of the models that were covered in the lecture, and second, to provide students with an opportunity to develop coding skills in one of the most prominent open-source programming languages that are widely used in academia and industry (students could choose between R or Python). Students were also encouraged but not required to make use of the simulations in their written coursework.
In preparation for the seminar sessions, students were asked to work through the first chapter of the website to learn basic principles of coding. Next, they were supposed to use the code from chapter 6 of the website to simulate a Post-Keynesian macro model with endogenous money on their own machines. They were then asked to implement a scenario consisting of a reduction of risk perceptions by banks by slightly modifying the code and report how the model’s results (e.g. output, lending rate, price level, employment, and so on) change. Using the directed graph of the model provided on the website, the model’s results and the causal mechanisms generating them were then jointly discussed by the students in small groups in the seminars.
Many students showed a keen interest in working with and understanding the code. In the seminar discussions, it also became apparent that the visualisations helped many students to better understand the model’s causal mechanisms. That said, some students also struggled with the material due to a lack of prior knowledge of coding. Only a few of those students that did not bring prior knowledge of coding made an effort to work through the exercises at home. Likewise, only a handful of students made use of the simulations in their final written coursework. However, the opportunity to learn coding through model simulations was emphasised as a positive feature of the course in the module evaluation.
Four main take-aways arise from this first experience of using the website in a macroeconomics course. First, many students are indeed highly interested in developing coding skills through model simulation. Second, simulations contribute an interactive element to teaching that fosters intuition for economic models. Third, without coding and simulations forming part of the summative assessment, many students will not spend much time learning the basics through independent study. Fourth, sufficient in-class time must thus be allocated to explain the codes step-by-step to ensure that all students can benefit from the material.
Overall, implementing simulations from the DIY Macroeconomic Model Simulation website has yielded promising results in teaching. I certainly intend to make this a regular feature in my teaching and invite colleagues to experiment with this pedagogical tool and share their experiences and feedback.
↑ Top