Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning message and autodocs around IncShkDstn fixes #955

Merged
merged 6 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interpolation for problems with CRRA utility. See [#888](https://github.com/econ
* Adds a module with tools for parsing and using various income calibrations from the literature. It includes the option of using life-cycle profiles of income shock variances from [Sabelhaus and Song (2010)](https://www.sciencedirect.com/science/article/abs/pii/S0304393210000358). See [#921](https://github.com/econ-ark/HARK/pull/921), [#941](https://github.com/econ-ark/HARK/pull/941).
* remove "Now" from model variable names [#936](https://github.com/econ-ark/HARK/pull/936)
* Moves state MrkvNow to shocks['Mrkv'] in AggShockMarkov and KrusellSmith models [#935](https://github.com/econ-ark/HARK/pull/935)
* Replaces `ConsIndShock`'s `init_lifecycle` with an actual life-cycle calibration [#951](https://github.com/econ-ark/HARK/pull/951).

#### Minor Changes

Expand All @@ -39,6 +40,7 @@ interpolation for problems with CRRA utility. See [#888](https://github.com/econ
* Rename IncomeDstn to IncShkDstn
* AgentType simulate() method now returns history. [#916](https://github.com/econ-ark/HARK/pull/916)
* Rename DiscreteDistribution.drawDiscrete() to draw()
* Update documentation and warnings around IncShkDstn [#955](https://github.com/econ-ark/HARK/pull/955)

### 0.10.8

Expand Down
26 changes: 13 additions & 13 deletions HARK/ConsumptionSaving/ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,11 +1102,11 @@ def solveConsAggShock(
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [np.array]
A list containing five arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, idisyncratic permanent shocks, idiosyncratic transitory
and the one immediately following (in solution_next). Order:
idiosyncratic permanent shocks, idiosyncratic transitory
shocks, aggregate permanent shocks, aggregate transitory shocks.
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
Expand Down Expand Up @@ -1292,11 +1292,11 @@ def solveConsAggShockNEW(solution_next, IncShkDstn, LivPrb, DiscFac, CRRA, PermG
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [np.array]
A list containing five arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, idisyncratic permanent shocks, idiosyncratic transitory
and the one immediately following (in solution_next). Order:
idiosyncratic permanent shocks, idiosyncratic transitory
shocks, aggregate permanent shocks, aggregate transitory shocks.
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
Expand Down Expand Up @@ -1438,11 +1438,11 @@ def solveConsAggMarkov(
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [[np.array]]
A list of lists, each containing five arrays of floats, representing a
discrete approximation to the income process between the period being
solved and the one immediately following (in solution_next). Order: event
probabilities, idisyncratic permanent shocks, idiosyncratic transitory
IncShkDstn : [distribution.Distribution]
A list of
discrete approximations to the income process between the period being
solved and the one immediately following (in solution_next). Order:
idisyncratic permanent shocks, idiosyncratic transitory
shocks, aggregate permanent shocks, aggregate transitory shocks.
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
Expand Down
11 changes: 5 additions & 6 deletions HARK/ConsumptionSaving/ConsGenIncProcessModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class ConsGenIncProcessSolver(ConsIndShockSetup):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, persistent shocks, transitory shocks.
Expand Down Expand Up @@ -199,11 +199,10 @@ def setAndUpdateValues(self, solution_next, IncShkDstn, LivPrb, DiscFac):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, persistent shocks, transitory shocks.
and the one immediately following (in solution_next).
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down
99 changes: 59 additions & 40 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
from HARK import _log
from HARK import set_verbosity_level

from HARK.Calibration.Income.IncomeTools import ParseIncomeSpec, ParseTimeParams, Cagetti_income
from HARK.datasets.SCF.WealthIncomeDist.SCFDistTools import income_wealth_dists_from_scf
from HARK.datasets.life_tables.us_ssa.SSATools import parse_ssa_life_table

__all__ = [
"ConsumerSolution",
Expand Down Expand Up @@ -460,11 +463,10 @@ class ConsIndShockSetup(ConsPerfForesightSolver):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
and the one immediately following (in solution_next).
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down Expand Up @@ -1152,11 +1154,10 @@ class ConsKinkedRsolver(ConsIndShockSolver):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
and the one immediately following (in solution_next).
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down Expand Up @@ -2467,16 +2468,15 @@ def constructLognormalIncomeProcessUnemployment(self):

Returns
-------
IncShkDstn : [[np.array]]
A list with T_cycle elements, each of which is a list of three arrays
representing a discrete approximation to the income process in a period.
Order: probabilities, permanent shocks, transitory shocks.
PermShkDstn : [[np.array]]
A list with T_cycle elements, each of which is a list of two arrays
representing a discrete approximation to the permanent income shocks.
TranShkDstn : [[np.array]]
A list with T_cycle elements, each of which is a list of two arrays
representing a discrete approximation to the transitory income shocks.
IncShkDstn : [distribution.Distribution]
A list with T_cycle elements, each of which is a
discrete approximation to the income process in a period.
PermShkDstn : [[distribution.Distributiony]]
A list with T_cycle elements, each of which
a discrete approximation to the permanent income shocks.
TranShkDstn : [[distribution.Distribution]]
A list with T_cycle elements, each of which
a discrete approximation to the transitory income shocks.
"""
# Unpack the parameters from the input
PermShkStd = self.PermShkStd
Expand Down Expand Up @@ -2732,7 +2732,7 @@ def applyFlatIncomeTax(

Parameters
----------
IncShkDstn : [income distributions]
IncShkDstn : [distribution.Distribution]
The discrete approximation to the income distribution in each time period.
tax_rate : float
A flat income tax rate to be applied to all employed income.
Expand All @@ -2745,7 +2745,7 @@ def applyFlatIncomeTax(

Returns
-------
IncShkDstn_new : [income distributions]
IncShkDstn_new : [distribution.Distribution]
The updated income distributions, after applying the tax.
"""
unemployed_indices = (
Expand Down Expand Up @@ -2825,27 +2825,46 @@ def constructAssetsGrid(parameters):


# Make a dictionary to specify a lifecycle consumer with a finite horizon

# Main calibration characteristics
birth_age = 25
death_age = 90
adjust_infl_to = 1992
# Use income estimates from Cagetti (2003) for High-school graduates
education = "HS"
income_calib = Cagetti_income[education]

# Income specification
income_params = ParseIncomeSpec(
age_min=birth_age,
age_max=death_age,
adjust_infl_to=adjust_infl_to,
**income_calib,
SabelhausSong=True
)

# Initial distribution of wealth and permanent income
dist_params = income_wealth_dists_from_scf(
base_year=adjust_infl_to, age=birth_age, education=education, wave=1995
)

# We need survival probabilities only up to death_age-1, because survival
# probability at death_age is 1.
liv_prb = parse_ssa_life_table(
female=False, cross_sec=True, year=2004, min_age=birth_age, max_age=death_age - 1
)

# Parameters related to the number of periods implied by the calibration
time_params = ParseTimeParams(age_birth=birth_age, age_death=death_age)

# Update all the new parameters
init_lifecycle = copy(init_idiosyncratic_shocks)
init_lifecycle["PermGroFac"] = [
1.01,
1.01,
1.01,
1.01,
1.01,
1.02,
1.02,
1.02,
1.02,
1.02,
]
init_lifecycle["PermShkStd"] = [0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0, 0, 0]
init_lifecycle["TranShkStd"] = [0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0, 0, 0]
init_lifecycle["LivPrb"] = [0.99, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1]
init_lifecycle["T_cycle"] = 10
init_lifecycle["T_retire"] = 7
init_lifecycle[
"T_age"
] = 11 # Make sure that old people die at terminal age and don't turn into newborns!
init_lifecycle.update(time_params)
init_lifecycle.update(dist_params)
# Note the income specification overrides the pLvlInitMean from the SCF.
init_lifecycle.update(income_params)
init_lifecycle.update({"LivPrb": liv_prb})


# Make a dictionary to specify an infinite consumer with a four period cycle
init_cyclical = copy(init_idiosyncratic_shocks)
Expand Down
26 changes: 15 additions & 11 deletions HARK/ConsumptionSaving/ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ def __init__(
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn_list : [[np.array]]
IncShkDstn_list : [distribution.Distribution]
A length N list of income distributions in each succeeding Markov
state. Each income distribution contains three arrays of floats,
representing a discrete approximation to the income process at the
beginning of the succeeding period. Order: event probabilities,
permanent shocks, transitory shocks.
state. Each income distribution is a
discrete approximation to the income process at the
beginning of the succeeding period.
LivPrb : np.array
Survival probability; likelihood of being alive at the beginning of
the succeeding period for each Markov state.
Expand Down Expand Up @@ -761,12 +760,11 @@ def _solveConsMarkov(
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn_list : [[np.array]]
IncShkDstn_list : [distribution.Distribution]
A length N list of income distributions in each succeeding Markov
state. Each income distribution contains three arrays of floats,
representing a discrete approximation to the income process at the
beginning of the succeeding period. Order: event probabilities,
permanent shocks, transitory shocks.
state. Each income distribution is
a discrete approximation to the income process at the
beginning of the succeeding period.
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down Expand Up @@ -906,7 +904,13 @@ def checkMarkovInputs(self):
# conditional on a particular Markov state.
# TODO: should this be a numpy array too?
for IncShkDstn_t in self.IncShkDstn:
if not isinstance(IncShkDstn_t, list) or len(IncShkDstn_t) != StateCount:
if not isinstance(IncShkDstn_t, list):
raise ValueError(
"self.IncShkDstn is time varying and so must be a list"
+ "of lists of Distributions, one per Markov State. Found "
+ f"{self.IncShkDstn} instead"
)
elif len(IncShkDstn_t) != StateCount:
raise ValueError(
"List in IncShkDstn is not the right length, it should be length equal to number of states"
)
Expand Down
20 changes: 9 additions & 11 deletions HARK/ConsumptionSaving/ConsMedModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,13 @@ class ConsMedShockSolver(ConsGenIncProcessSolver):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
MedShkDstn : [np.array]
IncShkDstn : distribution.Distribution
A discrete
approximations to the income process between the period being solved
and the one immediately following (in solution_next).
MedShkDstn : distribution.Distribution
Discrete distribution of the multiplicative utility shifter for med-
ical care. Order: probabilities, preference shocks.
ical care.
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down Expand Up @@ -977,11 +976,10 @@ def setAndUpdateValues(self, solution_next, IncShkDstn, LivPrb, DiscFac):
----------
solution_next : ConsumerSolution
The solution to next period's one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
and the one immediately following (in solution_next).
LivPrb : float
Survival probability; likelihood of being alive at the beginning of
the succeeding period.
Expand Down
4 changes: 2 additions & 2 deletions HARK/ConsumptionSaving/ConsPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ def solveConsPortfolio(
transitory income shocks, and risky returns. This is only used if the
input IndepDstnBool is False, indicating that income and return distributions
can't be assumed to be independent.
IncShkDstn : [np.array]
List with three arrays: discrete probabilities, permanent income shocks,
IncShkDstn : distribution.Distribution
Discrete distribution of permanent income shocks
and transitory income shocks. This is only used if the input IndepDsntBool
is True, indicating that income and return distributions are independent.
RiskyDstn : [np.array]
Expand Down
12 changes: 6 additions & 6 deletions HARK/ConsumptionSaving/ConsPrefShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class ConsPrefShockSolver(ConsIndShockSolver):
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
Expand Down Expand Up @@ -542,8 +542,8 @@ def solveConsPrefShock(
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
Expand Down Expand Up @@ -620,8 +620,8 @@ class ConsKinkyPrefSolver(ConsPrefShockSolver, ConsKinkedRsolver):
----------
solution_next : ConsumerSolution
The solution to the succeeding one period problem.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
Expand Down
14 changes: 7 additions & 7 deletions HARK/ConsumptionSaving/ConsRepAgentModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def solveConsRepAgent(
Intertemporal discount factor for future utility.
CRRA : float
Coefficient of relative risk aversion.
IncShkDstn : [np.array]
A list containing three arrays of floats, representing a discrete
IncShkDstn : distribution.Distribution
A discrete
approximation to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
and the one immediately following (in solution_next). Order:
permanent shocks, transitory shocks.
CapShare : float
Capital's share of income in Cobb-Douglas production function.
DeprFac : float
Expand Down Expand Up @@ -135,9 +135,9 @@ def solveConsRepAgentMarkov(
Intertemporal discount factor for future utility.
CRRA : float
Coefficient of relative risk aversion.
IncShkDstn : [[np.array]]
A list of lists containing three arrays of floats, representing a discrete
approximation to the income process between the period being solved
IncShkDstn : [distribution.Distribution]
A list of discrete
approximations to the income process between the period being solved
and the one immediately following (in solution_next). Order: event
probabilities, permanent shocks, transitory shocks.
CapShare : float
Expand Down
Loading