Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A Demonstration of the Harmenberg (2021) Aggregation Method

# Set Up the Computational Environment: (in JupyterLab, click the dots)

Description of the problem

Macroeconomic models with heterogeneous agents sometimes incorporate a microeconomic income process with a permanent component (𝐩t) that follows a geometric random walk. To find an aggregate characteristic of these economies such as aggregate consumption 𝐂t, one must integrate over permanent income (and all the other relevant state variables):

𝐂t=∫𝐩∫𝐦c(𝐦,𝐩)×ft(𝐦,𝐩)d𝐦d𝐩,

where 𝐦 denotes any other state variables that consumption might depend on, c(⋅,⋅) is the individual consumption function, and ft(⋅,⋅) is the joint density function of permanent income and the other state variables at time t.

Under the usual assumption of Constant Relative Risk Aversion utility and standard assumptions about the budget constraint, such models are homothetic. This means that for a state variable 𝐦 one can solve for a normalized policy function c(⋅) such that

c(𝐦,𝐩)=c(𝐦/𝐩)×𝐩

In practice, this implies that one can defined a normalized state vector m=𝐦/𝐩 and solve for the normalized policy function. This eliminates one dimension of the optimization problem problem, 𝐩.

While convenient for the solution of the agents’ optimization problem, homotheticity has not simplified our aggregation calculations as we still have

𝐂t=∫∫c(𝐦,𝐩)×ft(𝐦,𝐩)d𝐦d𝐩=∫∫c(1𝐩×𝐦)×𝐩×ft(𝐦,𝐩)d𝐦d𝐩,

which depends on 𝐩.

To further complicate matters, we usually do not have analytical expressions for c(⋅) or ft(𝐦,𝐩). What we often do in practice is to simulate a population I of agents for a large number of periods T using the model’s policy functions and transition equations. The result is a set of observations {𝐦i,t,𝐩i,t}i∈I,0≤t≤T which we then use to approximate

𝐂t≈1|I|∑i∈Ic(𝐦i,t/𝐩i,t)×𝐩i,t.

At least two features of the previous strategy are unpleasant:

  • We have to simulate the distribution of permanent income, even though the model’s solution does not depend on it.

  • As a geometric random walk, permanent income might have an unbounded distribution. Since 𝐩i,t appears multiplicatively in our approximation, agents with high permanent incomes will be the most important in determining levels of aggregate variables. Therefore, it is important for our simulated population to achieve a good approximation of the distribution of permanent income among the small number of agents with very high permanent income, which will require us to use many agents (large I, requiring considerable computational resources).

Harmenberg (2021) solves both problems. His solution constructs a distribution f~(⋅) of the normalized state vector that he calls the permanent-income-weighted distribution and which has the convenient property that

𝐂t=∫∫c(1𝐩×𝐦)×𝐩×ft(𝐦,𝐩)d𝐦d𝐩=∫c(m)×f~(m)dm.

Therefore, his solution allows us to calculate aggregate variables without the need to keep track of the distribution of permanent income. Additionally, the method eliminates the issue of a small number of agents in the tail having an outsized influence in our approximation and this makes it much more precise.

This notebook briefly describes Harmenberg’s method and demonstrates its implementation in the HARK toolkit.

Description of the method

To illustrate Harmenberg’s idea, consider a buffer stock saving model in which:

  • The individual agent’s problem has two state variables:

    • Market resources 𝐦i,t.

    • Permanent income 𝐩i,t.

  • The agent’s problem is homothetic in permanent income, so that we can define mt=𝐦t/𝐩t and find a normalized policy function c(⋅) such that

c(m)×𝐩t=c(𝐦t,𝐩t)∀(𝐦t,𝐩t)

where c(⋅,⋅) is the optimal consumption function.

  • 𝐩t evolves according to

    𝐩t+1=ΦΨt+1𝐩t,

    where Ψt+1 is a shock with density function fΨ(⋅) satisfying 𝔼t[Ψt+1]=1.

To compute aggregate consumption 𝐂t in this model, we would follow the approach from above

𝐂t=∫∫c(m)×𝐩×μt(m,𝐩)dmd𝐩,

where μt(m,𝐩) is the measure of agents with normalized resources m and permanent income 𝐩.

First insight

The first of Harmenberg’s insights is that the previous integral can be rearranged as

𝐂t=∫mc(m)(∫𝐩×μt(m,𝐩)d𝐩)dm.

The inner integral, ∫𝐩𝐩×μt(m,𝐩)d𝐩, is a function of m and it measures the total amount of permanent income accruing to agents with normalized market resources of m. De-trending this object by the deterministic component of growth in permanent income Φ, Harmenberg defines the permanent-income-weighted distribution μ~m(⋅) as

μ~tm(m):=Φ−t∫𝐩𝐩×μt(m,𝐩)d𝐩.

The definition allows us to rewrite

𝐂t=Φt∫mc(m)×μ~tm(m)dm.

There are no computational advances yet: We have merely hidden the joint distribution of (m,𝐩) inside the μ~m object we have defined. This helps us notice that μ~m is the only object besides the solution that we need in order to compute aggregate consumption. But we still have no practial way of computing or approximating μ~m.

Second insight

Harmenberg’s second insight produces a simple way of generating simulated counterparts of μ~m without having to simulate permanent incomes.

We start with the density function of mt+1 given mt and Ψt+1, Λ(mt+1|mt,Ψt+1). This density will depend on the model’s transition equations and draws of random variables like transitory shocks to income in t+1 or random returns to savings between t and t+1. If we can simulate those things, then we can sample from Λ(⋅|mt,Ψt+1).

Harmenberg shows that

𝚝𝚛𝚊𝚗𝚜𝚒𝚝𝚒𝚘𝚗: μ~t+1m(mt+1)=∫Λ(mt+1|mt,Ψt)f~Ψ(Ψt+1)μ~tm(mt)dmtdΨt+1,

where f~Ψ is an altered density function for the permanent income shocks Ψ, which he calls the permanent-income-neutral measure, and which relates to the original density fΨ through

f~Ψ(Ψt+1):=Ψt+1fΨ(Ψt+1)∀Ψt+1.

What’s remarkable about this equation is that it gives us a way to obtain a distribution μ~t+1m from μ~tm:

  • Start with a population whose m is distributed according to μ~tm.

  • Give that population permanent income shocks with distribution f~Ψ.

  • Apply the transition equations and other shocks of the model to obtain mt+1 from mt and Ψt+1 for every agent.

  • The distribution of m across the resulting population will be μ~t+1m.

Notice that the only change in these steps from what how we would usually simulate the model is that we now draw permanent income shocks from f~Ψ instead of fΨ. Therefore, with this procedure we can approximate μ~tm and compute aggregates using formulas like the equation transition, all without tracking permanent income and with few changes to the code we use to simulate the model.

Harmenberg’s method in HARK

Harmenberg’s method for simulating under the permanent-income-neutral measure is available in HARK’s IndShockConsumerType class and the (many) models that inherit its income process, such as PortfolioConsumerType.

As the cell below illustrates, using Harmenberg’s method in HARK simply requires setting an agent’s property agent.neutral_measure = True and then computing the discrete approximation to the income process. After these steps, agent.simulate will simulate the model using Harmenberg’s permanent-income-neutral measure.

# Implementation in HARK:

Farther down in the notebook, code like this solves the standard model:

# Create a population with the default parametrization

popn = IndShockConsumerType(**params)

# Specify which variables to track in the simulation
popn.track_vars=[
    'mNrm',  # mLvl normalized by permanent income (mLvl = market resources)
    'cNrm',  # cLvl normalized by permanent income (cLvl = consumption)
    'pLvl']  # pLvl: permanent income

popn.cycles = 0  # No life cycles -- an infinite horizon

# Solve for the consumption function
popn.solve()

# Simulate under the base measure
popn.initialize_sim()
popn.simulate()

Later, code like this simulates using the permanent-income-neutral measure

# Harmenberg permanent-income-neutral simulation

# Make a clone of the population weighted solution
ntrl = deepcopy(popn)

# Change the income process to use the neutral measure

ntrl.neutral_measure = True
ntrl.update_income_process()

# Simulate
ntrl.initialize_sim()
ntrl.simulate()

All we had to do differently to simulate using the permanent-income-neutral measure was to set the agent’s property neutral_measure=True.

This is implemented when the function update_income_process re-constructs the agent’s income process. The specific lines that achieve the change of measure in HARK are in this link, or reproduced here:

if self.neutral_measure == True:
    PermShkDstn_t.pmv = PermShkDstn_t.atoms*PermShkDstn_t.pmv

Simple!

The efficiency gain from using Harmenberg’s method

To demonstrate the gain in efficiency from using Harmenberg’s method, we will set up the following experiment.

Consider an economy populated by Buffer-Stock savers, whose individual-level state variables are market resources 𝐦t and permanent income 𝐩t. Such agents have a homothetic consumption function, so that we can define normalized market resources mt:=𝐦t/𝐩t, solve for a normalized consumption function c(⋅), and express the consumption function as c(𝐦,𝐩)=c(m)×𝐩.

Assume further that mortality, impatience, and permanent income growth are such that the economy converges to stable joint distribution of m and 𝐩 characterized by the density function f(⋅,⋅). Under these conditions, define the stable level of aggregate market resources and consumption as

𝐌:=∫∫m×𝐩×f(m,𝐩)dmd𝐩,𝐂:=∫∫c(m)×𝐩×f(m,𝐩)dmd𝐩.

If we could simulate the economy with a continuum of agents we would find that, over time, our estimate of aggregate market resources 𝐌ˆt would converge to 𝐌 and 𝐂ˆt would converge to 𝐂. Therefore, if we computed our aggregate estimates at different periods in time we would find them to be close:

𝐌ˆt≈𝐌ˆt+n≈𝐌and𝐂ˆt≈𝐂ˆt+n≈𝐂,for n>0 and t large enough.

In practice, however, we rely on approximations using a finite number of agents I. Our estimates of aggregate market resources and consumption at time t are

𝐌ˆt:=1I∑i=1Imi,t×𝐩i,t,𝐂ˆt:=1I∑i=1Ic(mi,t)×𝐩i,t,

under the basic simulation strategy or

𝐌ˆt:=1I∑i=1Im~i,t,𝐂ˆt:=1I∑i=1Ic(m~i,t),

if we use Harmenberg’s method to simulate the distribution of normalized market resources under the permanent-income neutral measure.

If we do not use enough agents, our distributions of agents over state variables will be noisy at approximating their continuous counterparts. Additionally, they will depend on the sequences of shocks that the agents receive. With a finite sample, the stochasticity of the draws will cause fluctuations in 𝐌ˆt and 𝐂ˆt. Therefore an informal way to measure the precision of our approximations is to examine the amplitude of these fluctuations.

First, some setup.

  1. Simulate the economy for a sufficiently long “burn in” time T0.

  2. Sample our aggregate estimates at regular intervals after T0. Letting the sampling times be 𝒯:={T0+Δt×n}n=0,1,...,N, obtain {𝐌ˆt}t∈𝒯 and {𝐂ˆt}t∈𝒯.

  3. Compute the variance of approximation samples Var({𝐌ˆt}t∈𝒯) and Var({𝐂ˆt}t∈𝒯).

We will now perform exactly this exercise, examining the fluctuations in aggregates when they are approximated using the basic simulation strategy and Harmenberg’s permanent-income-neutral measure. Since each approximation can be made arbitrarily good by increasing the number of agents it uses, we will examine the variances of aggregates for various sample sizes.

# Setup computational environment:

# Define tool to calculate summary statistics:

We now configure and solve a buffer-stock agent with a default parametrization.

Under the basic simulation strategy, we have to de-normalize market resources and consumption multiplying them by permanent income. Only then we construct our statistics of interest.

Note that our time-sampling strategy requires that, after enough time has passed, the economy settles on a stable distribution of its agents across states. How can we know this will be the case? Szeidl (2013) and Harmenberg (2021) provide conditions that can give us some reassurance.

  1. Szeidl (2013) shows that if

    log⁡[(𝖱β)1/ρΦ]<𝔼[log⁡Ψ],

    then there is a stable invariant distribution of normalized market resources m.

  2. Harmenberg (2021) repurposes the Szeidl proof to argue that if the same condition is satisfied when the expectation is taken with respect to the permanent-income-neutral measure (f~Ψ), then there is a stable invariant permanent-income-weighted distribution (μ~m)

We now check both conditions with our parametrization.

Szeidl's condition is satisfied, there is a stable invariant distribution of normalized market resources
Harmenberg's condition is satisfied, there is a stable invariant permanent-income-weighted distribution

Knowing that the conditions are satisfied, we are ready to perform our experiments.

First, we simulate using the traditional approach.

Update and simulate using Harmenberg’s strategy. This time, not multiplying by permanent income.

Now Compare the Variances of Simulated Outcomes

Harmenberg (2021) and Szeidl (2013) prove that with an infinite population size, models of this kind will have constant and identical growth rates of aggregate consumption, market resources, and noncapital income.

A method of comparing the efficiency of the two methods is therefore to calculate the variance of the simulated aggregate variables, and see how many agents must be simulated using each of them in order to achieve a given variance. (An infinite number of agents would be required to achieve zero variance).

The plots below show the (logs of) the estimated variances for the two methods as a function of the (logs of) the number of agents.

<Figure size 1000x700 with 2 Axes>

Harmenberg’s Method Produces Large Gains in Efficiency

The number of agents required to achieve a given variance is revealed by choosing that variance and then finding the points on the horizontal axis that correspond to the two methods.

The upper variance plot shows that the efficiency gains are very large for consumption: The horizontal gap between the two loci is generally more than two orders of magnitude. That is, Harmenberg’s method requires less than one-hundredth as many agents as the standard method would require for a given precision. Alternatively, for a given number of agents it is typically more than 10 times as precise.

The improvement in variance is smaller for market resources, likely because in a buffer stock model the point of consumers’ actions is to use assets to absorb shocks. But even for 𝐌, the Harmenberg method attains any given level of precision (var({𝐌ˆt}t∈𝒯)) with roughly one tenth of the agents needed by the standard method to achieve that same level.

Of course, these results apply only to the particular configuration of parameter values that is the default in the HARK toolkit (but which were chosen long before Harmenberg developed his method). The degree of improvement will vary depending on the calibration -- for example, if the magnitude of permanent shocks is small or zero, the method will yield little or no improvement.

<Figure size 640x480 with 1 Axes>
References
  1. Harmenberg, K. (2021). Aggregating heterogeneous-agent models with permanent income shocks. Journal of Economic Dynamics and Control, 129, 104185. 10.1016/j.jedc.2021.104185