Projektkurs Volkswirtschaftslehre: let the computer do the calculations

News

  • Solutions for week 6 exercises are at the end of the page.
  • Due to public holidays, there is no class on May 14 and on June 4.

Description

Modern economics relies heavily on mathematical models. Solving these models by hand is usually burdensome and often outright infeasible. In these cases, computers can be used to analyse and solve economic models numerically. This project course gives an introduction to solving models numerically with the help of the computer. It is suitable for students with no (or little) prior knowledge of numerical analysis and/or programming.

The first part of the course gives an introduction to programming using the programming language "julia". The second part shows how to use julia to do numerical analysis (solving equations, maximizing functions, creating plots etc.). In the third part, students undertake a small project in which they use the skills acquired in the first two parts.

Students are asked to watch video tutorials (part 1) or "notebooks" (part 2) at home. In class questions on these are answered and students work on small exercises.

The skills acquired in this course will be particularly useful for writing term papers or a thesis but are also valued on the job market.

Time and place: Thursdays 10:00-11:30, SSC basement, 102 Seminarraum S37 (102/U1/-1.314)

Grading: The grade is based on three elements: First, a "julia cheat sheet" which is a document in which you write down the julia commands and functions you have learned together with a brief description of what they do or an example. Second, a jupyter notebook with solutions to the exercises. You will work on this during class. Third, your project which will be presented in class and handed in as a jupyter notebook.

Preliminary plan

The following plan might be adapted over the course of the semester. I use the following abbreviations:

  • jpfnb: "Julia Programming for Nervous Beginners"
  • jfmt: "Julia for micro theory"

    Week content to do before next week's class
    1 info, installing julia, jupyter notebooks "week 1" of jpfnb
    2 strings, data containers "week 2" of jpfnb
    3 numbers, functions "week 3" of jpfnb
    4 loops, if/else "week 4" of jpfnb, notebooks 1-2 jfmt
    5 plotting and maximizing functions, interact.jl notebooks 3,4,6,7 jfmt
    6 equation solving, multivariate maximization notebook 8 jfmt, notebooks data (skip sections 3.3, 4.3,4.5-4.7)
    7 data and statistics notebooks on hypothesis testing (only sections 1 and 2) and on regressions
    8 OLS  
    9 project work  
    10 project work  
    11 project presentations  

Material and links

Setting up Julia

Material

Beyond this course

  • QuantEcon is a graduate course in quantitative economics using julia. The material is beyond the scope of this course but might give you an idea how the tools taught in this course are used in economic research.

Week 6 solution

  1. Let market demand be \(D(p)=10-p\) if \(p<10\) and \(D(p)=0\) if \(p\geq10\). Let market supply be \(S(p)=2p-2\) if \(p>1\) and 0 else. Use the julia Roots.jl package to compute the market equilibrium (price and quantity). (Hint: Market equilibrium occurs where the difference between demand and supply is zero.) Plot supply and demand to verify your result graphically.
using Roots
function D(p)
    if p<10
          return 10-p
    else
          return 0.0
    end
end
function S(p)
    if p>1
          return 2p-2
    else
          return 0.0
    end
end
excessDemand(p)=D(p)-S(p)
pstar = fzero(excessDemand,5.0)
qstar = D(pstar)
  1. Recall that the expected value of a continuously distributed random variable is calculated as \(\int_a^b xf(x)\,dx\) where \(f\) is the density of the random variable and \([a,b]\) is the support of the distribution (i.e. the density of the random variable is 0 outside the interval \([a,b]\)). Consider a random variable with triangular density namely \(f(x)=2x\) for \(x\in[0,1]\) and \(f(x)=0\) for \(x\not\in[0,1]\) and use integration with the QuadGK.jl package to compute its expected value.
using QuadGK
function f(x)
    if 0<x<1
          return 2x
    else
          return 0.0
    end
end
quadgk(x-> x*f(x),0,1)[1]
  1. A consumer consumes 3 perfectly divisible goods \(x_1\), \(x_2\) and \(x_3\). The price of one unit of good 1 is 1 while the price of one unit of good 2 is 2 and the price of good 3 is \(3\). The utility function of the consumer is \(u(x_1,x_2)=x_1*x_2*x_3\) and his income is 12. Use julia to solve the consumers utility maximization problem, i.e. how many units of each good will the consumer consume? What is his utility level? (Hint: Solve the budget constraint for one of the variables and plug it into the objective. The resulting objective you still have to maximize over two variables.)
using Optim
u(x1,x2,x3) = x1*x2*x3
v(x) = -u(x[1],x[2],(12-x[1]-2*x[2])/3)
res = optimize(v,[1.0,1.0])
x1star,x2star = Optim.minimizer(res)[1],Optim.minimizer(res)[2]
x3star = (12-x1star-2*x2star)/3
ustar = u(x1star,x2star,x3star)

Disclaimer