Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Mini-Project: Build a Small Economy Simulator

Build a small Python model of an open economy: find equilibrium income, test fiscal policy, add a recession shock and track the budget and public debt over time.

In this project you will combine ideas from the whole chapter into one working model: the spending multiplier, the budget balance, public debt and a simple policy rule. The result is a small economy simulator that you can use to run experiments. It is a stand-in model with invented numbers; real economies are far more complicated, but the logic is the same.

The model

The economy has these equations (all amounts in billions):

  • Consumption: C = a + b ร— (Y - T), with autonomous consumption a and marginal propensity to consume b.
  • Taxes: T = t ร— Y, with a tax rate t.
  • Investment I, government purchases G and exports X are fixed.
  • Imports: M = m ร— Y.
  • Equilibrium: Y = C + I + G + X - M.

Solving for Y:

Y = (a + I + G + X) / (1 - b ร— (1 - t) + m)

The denominator is the one from the fiscal multiplier lesson. The budget balance is T - G (positive means a surplus).

Step 1: equilibrium income

Start with a = 100, b = 0.8, t = 0.25, I = 150, G = 300, X = 100, m = 0.1. Autonomous spending is 100 + 150 + 300 + 100 = 650. The denominator is 1 - 0.6 + 0.1 = 0.5, so Y = 1,300.

Python Step 1: equilibrium and budget

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The assertion at the end checks the model against the identity Y = C + I + G + NX. Whenever you build a model, add checks like this one.

Step 2: policy experiments

Now test policies. What happens if the government raises spending by 50? What if it cuts the tax rate from 25 to 20 percent? Which has the bigger effect on income and on the budget?

Python Step 2: fiscal policy experiments

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look for patterns in the results. A spending rise lifts income and also raises tax revenue, so the budget deteriorates by less than the extra spending. A tax cut raises income but reduces the revenue per unit of income. A drop in exports hits income and the budget at the same time: this is one example of an automatic stabilizer working in reverse, because revenue falls as income falls.

Step 3: a recession and the debt

Now make the model dynamic. Add a public debt D starting at 600, with an interest rate of 3 percent on the debt. Each year:

D_next = D ร— (1 + r) - (T - G)

(A surplus pays debt down; a deficit adds to it.)

The scenario: in year 3, private investment collapses from 150 to 50 for two years. Then it recovers. We compare two governments:

  • Passive: keeps G unchanged.
  • Active: raises G by half of the income gap each year, divided by the multiplier. The aim is to close part of the gap using the multiplier idea.
Python Step 3: recession, policy and public debt

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The active government keeps output closer to potential in the recession years (1,200 instead of 1,100), but it ends the ten years with a higher debt than the passive one. This is the central trade-off of fiscal stabilization. Its size depends on the multiplier: with a smaller multiplier (more imports, higher taxes) the same spending buys less output.

Step 4: your extensions

Choose at least two of these and implement them:

  1. Interest rate response: make investment depend on an interest rate, I = 200 - 10 ร— r, and add a central bank that lowers r when output falls below potential (see the monetary policy lesson).
  2. Debt ratio: divide debt by income each year and print the debt-to-GDP ratio. Does it rise or fall after the recession ends?
  3. Debt brake rule: make the government cut G whenever the debt ratio exceeds 60 percent, and compare the outcomes.
  4. Open economy: let exports depend on a foreign income that you can change, and a real exchange rate that shifts X and m (see exchange rates).
  5. Growth: add potential output that grows 2 percent a year and let investment add to capital (see the Solow model).

A simulator gives answers that follow from the equations you wrote. It does not predict the real world. Always say which assumptions are built in, such as fixed investment, constant prices and no crowding out.

What you practiced

  • Building a model as a Python class with parameters.
  • Using the multiplier and checking the model with an identity.
  • Comparing policy options by running experiments.
  • Tracking a stock (debt) with a flow (the budget balance).

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. In the model, what happens to equilibrium income if exports fall?

    Exports are part of autonomous spending, so a fall of ฮ”X reduces income by ฮ”X times the multiplier.
  2. 2. Why does tax revenue fall in a recession in this model?

    T = t ร— Y, so lower income means lower revenue, which is an automatic stabilizer.
  3. 3. Which is the best use of the identity check (assert) in the simulator?

    An identity that must hold in any correct model reveals coding or algebra errors when it fails.

Summary

  • A small macro model needs a few equations: consumption, taxes, imports and the equilibrium condition.
  • The multiplier 1 / (1 - b(1 - t) + m) converts changes in autonomous spending into changes in income.
  • Public debt accumulates through the budget balance and interest; a recession both lowers revenue and raises the need for stimulus.
  • Fiscal stabilization trades a smoother economy for higher debt.
  • Simulators are tools for thinking, not forecasts.

Return to the Macroeconomics track page to continue your study.