Computational Economics

Unit 02 · Three short lessons

Inside one economy

Three short lessons connect the firm's operating decision to the moments of an economy.

The economy is based on De Loecker, Eeckhout and Mongey (2026), with teaching examples and an independent Python implementation.

Given
A parameter vector (σ, N, ζ), fixed technology and demand parameters, and fixed productivity draws for two periods in 10,000 markets. Each market starts with M = floor(N) potential firms.
Find
The operating firms in each period; their shares, prices, production and employment; the wage and output that clear the economy; then three moments of those outcomes.
Check
Each lesson ends with the numbers you should find, folded under “Check your result”. A Python script solves the economy of 02.3 again and compares every number with this page.
  1. 02.1Entry and exitStart with potential firms. Follow the operating set through the profit checks, then compare entry and exit across periods.
  2. 02.2Cournot and equilibriumFor a given operating set, connect competition, prices, demand and the labor market.
  3. 02.3Parameters to momentsChange one input and follow firms’ outcomes into three aggregate moments.

Reference

  • Model and sourceHow the model fits together, the fixed-cost rule, and the downloads.

Read the complete unit on one page

02.1 / Entry and exit

Which firms operate?

Start with potential firms and follow their operating decisions.

  1. Inspect. In Period 1, read a firm's profit and decision in Round 1. Press Next and check which firms are still present.
  2. Follow. Go to the last round. Record proposed exits and applied exits for the whole economy. Use the stopping rule below to explain the difference.
  3. Compare. Open “Between two periods”. Pick an entrant, an exiting firm or a continuing firm and record its two operating states. These states determine which employment changes enter the reallocation moment.
Check your result
  • Period 1, Round 1. The whole-economy exit cutoff is −0.810 millionths. Five firms in Market 1 are at or below it and leave before the next round: Firms 01, 04, 07, 10 and 14. Firm 01, for example, has profit −0.989 and a 4.74% share; in Round 2 it is “Already inactive”. All fourteen firms make a loss in this round, but the other nine are above the cutoff and stay for the next solve.
  • Round 15, the last. Exit candidates in the whole economy: 2. Exit decisions applied: 0. Fewer than three exits are proposed, so the stopping check keeps the current set, and Market 1 ends Period 1 with nine operating firms.
  • Between two periods. In Market 1 the nine operating firms continue into Period 2 and the other five are inactive in both periods. Firm 03, for example, has a 13.38% share in Period 1 and 14.00% in Period 2. Entry and exit happen in other markets: the whole economy has 10,153 entrants, 10,124 exiting firms and 74,432 continuing firms.

Loading the saved operating-set decisions…

One market, round by round

Each frame is a saved equilibrium, just before its exit decision.

The saved round will appear here.

Before deletion. Only firms labelled “Leaves before next round” exit at the next step.

Whole-economy exit cutoff: — millionths of a model profit unit, rounded for display. Across all 10,000 markets, operating firms at or below this cutoff form the proposed exit batch; other loss-making firms stay for the next solve. If fewer than three exits are proposed economy-wide, stop before deletion and keep the current set.

FirmDecisionProfit · millionthsMarket share
Wage W
—
Output Y
—
Operating · whole economy
—
Exit candidates · whole economy
—
Exit decisions applied · whole economy
—
How to read the decision

Begin with potential firms. The operating decision comes first; the next lesson opens up Cournot competition for a given set of firms.

  1. Start with potential firms.
  2. Solve the current operating set and read profits.
  3. Apply the exit decision and solve the remaining set again.

The displayed market belongs to the full economy. The exit rule is evaluated across that economy.

This replay holds φ at 2.064 per million. In lesson 02.3, ζ picks φ for the same parameters (2.063 per million), so the totals there differ slightly from these.

Shares and profits belong to the current operating set. A firm marked “Leaves before next round” is still present in this frame; the next round shows the new set. Profit is displayed in millionths of a model unit.

Each round first solves shares, prices and wages for its current operating set. The full-economy profit rule then selects an exit batch. Some loss-making firms can remain for the next round.

The stopping check comes before deletion: on a stopping round, the proposed exits are not applied.

Compare the two final operating sets in “Between two periods” to see entrants and exiting firms.

60-second worked example · EnglishFrom potential firms to operating firms

Follow fourteen potential firms through the first-round profit check. Five leave, nine remain, and the whole economy continues to adjust before its final stopping check.

Code on GitHub 07_python/qmp/equilibrium.py ↗

02.2 / Cournot and equilibrium

Now solve the operating firms' economy.

Take the current operating set as given. Cournot competition, demand and the labor market jointly determine shares, prices, output and wages.

  1. Trace the share loop. Select Competition, then Demand. A trial share gives elasticity and markup; the implied prices give a new demand share. The two shares must agree.
  2. Close the labor market. Follow Firms → Labor → Households. Add production and operating labor across active firms and compare that demand with labor supplied at wage W.
  3. Return to profits. With quantities and prices solved, calculate profits for the exit decision in 02.1. If the operating set changes, solve these conditions again.
The two conditions to write down

εij = 1 / [sij/θ + (1 − sij)/η],   μij = εij / (εij − 1).

The price-implied market share must return the same sij. This is the share fixed point.

Σactive i,j (nij + φ) = φ̄ Wϕ.

The left side is labor used; the right side is household labor supplied. The labor-supply scale φ̄ and elasticity ϕ are fixed parameters; φ is the fixed labor that each operating firm uses.

Check your result
  • The two conditions are the ones under “The two conditions to write down”: the share fixed point and labor market clearing.
  • The arrows. Shares → elasticities and markups → prices → demand → implied shares, which must equal the trial shares. Then output Y and wage W → production labor; production labor plus the fixed labor of the operating firms must equal the labor households supply at W. Profits follow, and they feed the exit decision of 02.1.
  • The saved checks, baseline economy. Shares: in Market 1’s first exit round, Firm 3’s share moves from 8.1% to 10.0% in 41 updates, and then prices and shares agree. Labor: of every 100 employed workers, 75.8 produce and 24.2 cover fixed operations, in both periods, and employment equals labor supplied.
The economic relationships

Everything has to fit.

Click a part, or follow the arrows below.

One period. Linked equilibrium conditions.
01 / 06

Households supply labor.

A higher wage raises labor supplied.

Wage W → labor supplied Ls
The operating set is supplied by the entry and exit calculation.
48-second explanation · EnglishHow the parts of one economy fit together

Follow labor, production, competition and demand through the connected economy.

Code on GitHub 07_python/qmp/equilibrium.py ↗

02.3 / Parameters to moments

Change an input. Trace the result.

Follow one parameter change through the operating set and the equilibrium into three moments.

  1. Start with one case. Keep the default middle point. Record σ, N, M, ζ, the seed and φ. This is one evaluation, not an estimate.
  2. Inspect the solution. Use Operating firms → Shares → Labor below. Record the operating count and the share and labor checks. Then choose Moments to open the firm-to-economy calculations.
  3. Make one comparison. Move one point along the σ path and repeat the same table. Keep ζ and the seed fixed. φ changes too, because ζ picks it again from the new economy’s firms.
Check your result

The baseline is the middle point of the σ path, σ = 0.047041; the next point raises σ to 0.054500. N = 14.2227 (M = 14), ζ = 0.919212 and seed 100 stay the same.

Saved resultBaselineNext σ point
φ, millionths2.0632.144
Operating firms per market, Period 18.468.02
E₁0.7206235550.722964449
E₂0.7205612600.722900565
JC0.1031496600.109662963
JD0.1032119550.109726847
Employment reallocation28.638%30.347%
Sales-weighted markup1.45011.4611
SGA / total cost20.499%20.098%

Firm 02 of Market 1, baseline: employment falls from 7.320678 to 7.204523 millionths, a change of −0.116154 that enters job destruction. Its first-period sales weight is 0.000936% of economy sales. At the next σ point, Firm 02 operates in Period 1 only.

—
—Five precomputed values—

Dispersion σ
—
Potential firms N
—
M = floor(N)
Fixed-cost control ζ
—
Draw seed
—

Fixed labor per operating firm · φ

—

In millionths of a model labor unit.

84-second worked example · EnglishFrom productivity dispersion to three moments

Compare two saved economies with the same shocks and the same ζ. Follow fourteen firms in one market, then read three moments for the full economy.

Inputs

A parameter vector and fixed draws define one economy.

Loading the computed economy…

Employment reallocation
—
Sales-weighted markup
—
SGA / total cost
—

Fixed operating labor φ creates a wage bill Wφ. The model converts this to SGA costs using its labor-share parameter: SGA = Wφ / ψSGA. The reported moment averages each operating firm’s SGA / total cost ratio using first-period sales weights.

Numerical checks accompany this case.

Try it yourself

Solve this economy on your computer.

Download the Python source, unpack it, and run this command in the unpacked folder or at the root of the course repository. It needs Python 3.10 or later with NumPy and SciPy, and takes about ten seconds.

python lessons/02_one_economy/parameters_to_moments.py

The script solves the baseline economy with the page’s random draws. It prints what this page shows for it: φ, the operating firms, the three moments, the employment totals, Firm 02 of Market 1 and Market 1’s contributions. Next to each line it says whether the page shows the same value. Add --case sigma_3 for the next point on the σ path, or --firm 3 for another firm.

Check your result

All 25 lines should say “same”, and the output should end like this:

25 of 25 lines match the page.
At full precision the three moments differ from the saved values by at most 0, and 17 other saved values by at most 4.04e-16 relative.

The moments are 28.638%, 1.4501 and 20.499%, as in the readouts above; with --case sigma_3 they are 30.347%, 1.4611 and 20.098%. On another computer the full-precision differences can be a little larger, but they stay below about 10−15. The 17 other values can differ in the last digit even here, because the page built job creation, job destruction and sales from other saved totals.

The page draws productivity for 18 potential firms per market and keeps the first M, so that adding potential firms keeps the others’ draws. Unit 03 draws exactly M firms per market, so its candidate 2, which has the same parameters as this baseline, gives slightly different numbers.

Code on GitHub lessons/02_one_economy/parameters_to_moments.py ↗ · 07_python/qmp/draws.py ↗ · 07_python/qmp/__init__.py ↗ · 07_python/qmp/equilibrium.py ↗ · 07_python/qmp/moments.py ↗

Unit 02 / Reference

Model, interpretation and source

The model in four lines, and the downloads.

Model & interpretation
  • Shares ↔ prices. Shares set elasticities and markups; prices imply new demand shares.
  • Labor clears. Production and fixed labor together equal household labor supplied.
  • Exit repeats. The sequential rule removes firms and solves the economy again. It does not test profitable re-entry, so it does not certify a Nash equilibrium.
  • Fixed cost from ζ. Before any firm exits in period 1, ζ picks φ, the fixed labor of each operating firm, from the firms’ break-even values. φ then stays the same in every exit round and in period 2.