Python for economists

Table of Contents

Introduction

this lecture

  • in this lecture, we look at:
    • motivation to learn python
    • overview of the course
    • typing texts in markdown and \(\LaTeX\)
    • markdown files on github
    • initial assignment
    • first look at jupyter server

motivation

  • in this course we teach you
    • to combine rigorous economics
    • and how to present it in an understandable way
    • while your results can be easily reproduced
  • we do this by teaching you
    • a programming language: Python
    • how to create notebooks where you can explain your code and
    • publish them on-line, e.g. on github

things to learn

  • when you finish this course, you can
    • solve models in Python
    • do simulations in Python
    • create a file or notebook like this
    • go on to the Datascience course next semester

finishing the course

  • helps you to present economics in a way that is
    • understandable and
    • reproducible
  • gives a good starting point to write your thesis
  • check the website and Canvas for relevant information

Overview of the course

  • Python (most of the time)
    • programming economic models, e.g. market outcome, asymmetric information, oligopoly
    • simulating outcomes and interpreting these results
  • Career Services offers training:
    • these classes are compulsory!
    • see Canvas for details
  • Gender economics taught by Mery Ferrando:
    • helps you to understand gender economics and
    • what we have in mind for the final assignment
  • This course used to be called Applied Economic Analysis; hence you may occasionally find references to AEA

Office and Excel

Excel is great for programming?

  • indeed, simple things can be done in excel
  • e.g. keep track of your grades and calculate the average
  • but possibilities are limited: it is not a programming language
  • however, the main problem is reproducibility
  • if you've done a serious project in excel, look at it again in 3 months time…

Open source word processing

markdown

  • open source is great!
  • markdown allows you to create structure in a simple way
  • This is illustrated in a screencast: Short introduction to JupyterLab
  • examples are:

# this is a heading

## subheading

* first bullet
* second bullet

[link text](actual link, e.g. http://www.etc)

![Alt text for image](/path/to/img.jpg "Optional title")
  • look on the web for other syntax like footnotes etc.
  • equations you can type in \(\LaTeX\)

\(\LaTeX\)

  • \(\LaTeX\) is great word processing software
  • many students write their thesis in \(\LaTeX\)
  • here we focus on writing math in \(\LaTeX\)
  • you can guess what the following will do:
$x^2$, $\beta$, $\sqrt{9}$, $\frac{1}{2}$, $\bar x$

\begin{equation}

a^2 + b^2 = c^2

\end{equation}
  • if you need something, just google; e.g. google "latex phi" or google "latex empty set" etc.
  • students write their thesis in \(\LaTeX\) using Overleaf

What do you need?

Install software

Working in the cloud

github

  • github allows you to
    • publish web pages
    • work "in the cloud" with version control
    • collaborate in the cloud
    • have different versions ("branches") of the same project
  • version control takes a bit of time to learn
  • but once you get it, the benefits are huge!
  • for this course learning git is optional
  • you can just drag and drop your notebooks on github as we will practice in class
  • you need github to submit your assignments (using github classroom)

Rules of the game

to learn python we use datacamp, screencasts and lectures:

  • you need to finish the datacamp courses and screencasts in time
  • otherwise you will be lost during the lectures
  • see the Lecture schedule for the planning
  • if you want to learn everything on your own, you do not need to attend my lectures
  • but if you do attend the lectures, you participate actively
  • you do not learn Python by passively typing in answers!
  • you have to attend Joyce's career services classes
  • Mery's lectures on gender economics, coupled with the Python notebook, give you an idea of what we expect in the final assignment

lecture format

  • in the lectures we will answer questions that you ask us
  • in order to prepare these answers, it is useful if you create a github issue
    • create an "issue" where you explain what your question is: what did you try and why did it not work?
      • hence not something like "I do not know the answer to: Question Calculate the total welfare that this planner can achieve. Denote this value max_welfare."
      • but "I tried to calculate total welfare in the following way … but then I get the following error …"
  • for us to be able to prepare these answers, submit the issue on the Friday before the week in which we discuss the topic

suggested workflow

  • follow the Datacamp courses and make notes of what you learn at Datacamp in a notebook on the jupyterlab server
    • in this way it is easy to refer back to useful code snippets that you see on Datacamp
  • go through the notebook and try to answer the questions and assignments
  • if you get stuck with a problem, watch the corresponding screencast for this part
  • if you still cannot figure it out, create an issue on github to ask us
  • we will answer your questions in class

to get a grade for this course:

  • finish the initial assignment (see below) before the deadline
  • attend the career services workshops
  • Final Assignment
  • Deadlines for the final assignment

Assignments

Initial Assignment

Bonus point assignments

  • assignments can be viewed here: https://github.com/janboone/python_assignments
  • assignments 1 and 2 have deadlines before the lectures in the Lecture schedule
  • in this lecture, we will discuss the assignment
  • then you add to the assignment what you have learned from the assignment and what you got wrong the first time
  • we grade both assignments after the deadline of the 2nd assignment
  • note that github keeps track of the date on which you submit
  • if you get a pass on both assignments, you receive a bonus point for the final assignment
  • what we are looking for in assignments 1 and 2 is that you are up-to-date with the course and can google a bit to find (new) python commands

Doing the assignments

  • you can do the assignments on your own or together with 1 other student
  • you cannot change team during the semester
  • before assignment 1 we will post a link to github classroom with the assignments
  • this is the moment where you create your team
  • before the deadline you submit your assignment via github classroom
  • assignments 1 and 2 you submit two times
  • the final assignment you submit only once
  • when submitting your first assignment, you fill in the google form (link will be on Canvas)
  • see Assignments for details

Date: Dept. of Economics, Tilburg University

Author: Jan Boone