Projektkurs Volkswirtschaftslehre: let the computer do the calculations

News

  • The project presentations (around 15 minutes per group) take place on July 18. The deadline for your final submission is August 11. The final submission consists of (i) a jupyter notebook with your project, (ii) a jupyter notebook with solutions to the exercises listed below and (iii) your cheat sheet as a pdf document. Please upload all three files to sciebo or another cloud storage provider (like Dropbox, GoogleDrive etc.) and send me a link to the folder via email. The exercises for which solutions have to be handed in are the following:
    • Week 4: E1, E3
    • Week 5: E1, E2, E3
    • Week 6: E2
    • Week 7: E1, E3
    • Week 8: E1, E2
  • We will talk about "week 1" of jpfnb on May 2 and have a make-up zoom-meeting in which we answer questions about the material of "week 2" and the corresponding exercises on May 8 17:30 (Meeting ID: 988 9247 0093 Password: 843160). Solutions to some of the exercises of the first two weeks are on this website below.
  • Due to health issues, there is no meeting on April 25. I will inform you as soon as I am better about a make up meeting.
  • There is no meeting on April 11 as I am attending an international conference. We will have our first meeting on April 18.
  • In week 1, we talk a bit about the course and try to install julia on your computer. Please note that you need to bring a notebook to class every week in order to be able to work. (It does not matter whether your operating system is Windows, MacOS, Linux or FreeBSD. However, tablets or phones with mobile operating systems like Android and iOS will not work.)
  • A sample project description is available now.

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, Mensa building, 118/03/3.03

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.

Selected solutions

Week 2

  1. Using list comprehension create an array that contains all the lower case characters of the alphabet and bind this array to the variable name alphabet. (Hint: Recall that 'a'+0='a', 'a'+1='b' etc.)

    Then create a single string that contains all the letters of the alphabet and bind it to the name alphabetstring. Also create another string variable alphabetcomma that contains all letters of the alphabet separated by comma.

    Next create an array that contains the string "letter number 1 in the alphabet is a" as first element, the string "letter number 2 in the alphabet is b" as its second element and so on until "letter number 26 in the alphabet is z".

    alphabet = ['a'+i for i in 0:25]
    alphabetstring = join(alphabet)
    alphabetstring = join(alphabet, ", ")
    ["letter number $(i) in the alphabet is $(alphabet[i])" for i in 1:26]
    
  2. Use the string function with the keyword pad as well as a list comprehension and the join function to create a string "101001000100001000001000000100000001". Can you also do it without using pad (and without typing it in digit by digit, of course)?

    join([string(1;pad=i) for i in 1:7])
    string(join(["1"*"0"^i for i in 1:7]),"1")
    

Week 3

  1. Out of how many code blocks does the following code block consist and what does the function move1 do?

    var = "xyz"
    function move1(input)
        output = string(input[2:end],input[1])
        return output
    end
    move1(var)
    

    The function moves the first letter to the end of the word.

  2. If we add the following to the code of the previous exercise

    function move1(input::Number)
        output = input + 1
        return output
    end
    

    What output do you expect for the following function calls? Think first before trying!

    move1(3)
    move1(3.0)
    move1("3")
    move1("3.0")
    move1('3')
    move1([1, 2, 3])
    

    Adds 1 to a number. The important question is whether the input is a "number" or not. If not, the first definition of move1 that moves the first letter to the end is used.

  3. Write a function addfractions(numerator1,denominator1,numerator2,denominator2) that returns the sum of the fractions \(numerator1/denominator1\) and \(numerator2/denominator2\) as \(numeratorSum,denominatorSum\); e.g. addfractions(1,2,1,3) should return \(5,6\) as \(1/2+1/3=5/6\). (Note that you do not have to cancel common multipliers in the result.)

    function addfractions(numerator1,denominator1,numerator2,denominator2)
         denominatorSum = denominator1*denominator2
         numeratorSum = numerator1*denominator2 + numerator2*denominator1
         return numeratorSum, denominatorSum
    end
    
  4. Write a function evaluatef that takes two inputs: (i) another function (that I call f in the following), (ii) a range (e.g. 1:5). The function evaluatef should evaluate f at each point of the range and print the output. For example, if \(f(x)=x^2\), then \(evaluatef(f,1:3)\) should print:

    f(1) equals 1

    f(2) equals 4

    f(3) equals 9

    (Hint: to get the text printed line by line you have to recall what we did last week, namely list comprehension and escape sequences.)

    function evaluatef(f,range)
       println(join(["f($(i)) equals $(f(i)) \n" for i in range]))
    end
    

Disclaimer