Skip to content
Open
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
26 changes: 6 additions & 20 deletions HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,9 +2171,12 @@ def get_shocks(self):
"""
PermShkNow = np.zeros(self.AgentCount) # Initialize shock arrays
TranShkNow = np.zeros(self.AgentCount)
newborn = self.t_age == 0
for t in range(self.T_cycle):
these = t == self.t_cycle

draw_age = self.t_cycle - 1
draw_age[draw_age < 0] = 0

for t in np.unique(draw_age):
these = t == draw_age

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now realizing that draw_age already contains the -1 index shift. Therefore, I think indices inside the cycle should be t, not t-1. Does that sound right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you, that's right.

N = np.sum(these)
if N > 0:
IncShkDstnNow = self.IncShkDstn[
Expand All @@ -2188,23 +2191,6 @@ def get_shocks(self):
) # permanent "shock" includes expected growth
TranShkNow[these] = IncShks[1, :]

# That procedure used the *last* period in the sequence for newborns, but that's not right
# Redraw shocks for newborns, using the *first* period in the sequence. Approximation.
N = np.sum(newborn)
if N > 0:
these = newborn
IncShkDstnNow = self.IncShkDstn[0] # set current income distribution
PermGroFacNow = self.PermGroFac[0] # and permanent growth factor

# Get random draws of income shocks from the discrete distribution
EventDraws = IncShkDstnNow.draw_events(N)
PermShkNow[these] = (
IncShkDstnNow.X[0][EventDraws] * PermGroFacNow
) # permanent "shock" includes expected growth
TranShkNow[these] = IncShkDstnNow.X[1][EventDraws]
# PermShkNow[newborn] = 1.0
TranShkNow[newborn] = 1.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line might be one of the sources of failing tests.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2206 is the line I mean.


# Store the shocks in self
self.EmpNow = np.ones(self.AgentCount, dtype=bool)
self.EmpNow[TranShkNow == self.IncUnemp] = False
Expand Down
Loading