# Age-dependent health shocks

**URL:** <https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331>\
**Category:** Uncategorized\
**Created:** [November 7, 2024, 7:32pm UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331 "2024-11-07T19:32:30Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)\
**Post date:** [November 12, 2024, 9:20pm UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/22 "2024-11-12T21:20:15Z")

</div>

Note that when you run the codes, a bunch of the agent mass will end up in ‘dead’. Hence why you will likely want to use simoptions.conditionalrestrictions so as to evaluate all your model statistics conditional on being alive.

Also, you need to be careful when setting up the age weights. You don’t want to include survival probabilities in them (as these are accounted for in the ‘dead’ mass), just the population growth rates (of the young).

---

<div class="post-metadata">

**Author:** ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)\
**Post date:** [November 12, 2024, 11:54pm UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/23 "2024-11-12T23:54:29Z")

</div>

Thanks for the answer, Robert. Now the probability of dying depends on whether your health status is good or bad (i.e. ds\>dh). However, you would want the probability of dying to depend on age as well. In my toy example above I had the survival rate depend on age. In your example the survival rate depends on health. Is there a way to make the survival rate depend on both age _and_ health?

---

<div class="post-metadata">

**Author:** ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)\
**Post date:** [November 13, 2024, 3:32am UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/24 "2024-11-13T03:32:08Z")

</div>

Just make Params.dh and Params.ds be age-dependent parameters (and Params.h and Params.s would likely be age-dependent parameters too).

[And of course create pi\_z\_J instead of the above pi\_z. Except I believe you want it to be a semi-exo state, so obviously do the equivalent version for a semi-exo state]

[And have different ones for each ptype (can just be different parameter values and the same SemiExoStateFn)]

---

<div class="post-metadata">

**Author:** ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)\
**Post date:** [November 18, 2024, 11:36pm UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/25 "2024-11-18T23:36:11Z")

</div>

Another question about age-dependent health shocks, this time NO semi-exogenous shocks 🙂  
I would like to have two z shocks: zn is an income shock, NOT age-dependent, and zh is a health shock, age-dependent. You explained very clearly how to do this in your first answer above. Now I want to make zh also depend on a permanent type. Can I do the following:

(i) `n_z=[n1,n2];` with n1 the number of grid points for zn (income), and n2 the number of grid points for zh (health). Let `N_j` be the number of model periods.  
(ii) create `[zn_grid, pi_zn]` for the (not age-dependent) income shock (sizes are [n1,1] and [n1,n1];  
(iii) create `[zh_grid_J, pi_zh_J]` for the (age-dependent) health shock where now zh\_grid\_J and pi\_zh\_J are not numeric arrays but structures  
zh\_grid\_J.sick = array with size [n2,N\_j]  
zh\_grid\_J.healthy = array with size [n2,N\_j]  
pi\_zh\_J.sick = array with size [n2,n2,N\_j]  
pi\_zh\_J.healthy = array with size [n2,n2,N\_j]

Question: How do I combine the grids and the transition matrices? For example, I want to combine `zn_grid_J = zn_grid*ones(1,N_j)` with `zh_grid_J` but now `zh_grid_J` is a structure

---

<div class="post-metadata">

**Author:** ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)\
**Post date:** [November 19, 2024, 12:25am UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/26 "2024-11-19T00:25:06Z")

</div>

You can do (i), (ii) and (iii) exactly as you describe.

Toolkit either has to let all of z depend on permanent type or none of z depend on permanent type. So essentially we have to set up two copies of z, one for each permanent type (both will contain the same zn, but different zh parts). So you are going to want z\_grid\_J.sick and z\_grid\_J.healthy, as well as pi\_z\_J.sick and pi\_z\_J.healthy.

So now you just need a (iv).  
Keep your `n_z=[n1,n2];`  
Set

```auto
z_grid_J.sick=[zn_grid*ones(1,N_j); zh_grid_J.sick]; % array with size [n1+n2,N_j]
z_grid_J.healthy=[zn_grid*ones(1,N_j); zh_grid_J.healthy]; % array with size [n1+n2,N_j]
pi_z_J.sick=zeros(n1*n2,n1*n2,N_j); % array with size [n1*n2,n1*n2,N_j]
pi_z_J.healthy=zeros(n1*n2,n1*n2,N_j); % array with size [n1*n2,n1*n2,N_j]
for jj=1:N_j
   pi_z_J.sick(:,:,jj)=kron(pi_zh_J.sick(:,:,jj), pi_zn); % note: kron in reverse order
   pi_z_J.healthy(:,:,jj)=kron(pi_zh_J.healthy(:,:,jj), pi_zn); % note: kron in reverse order
end

```

(Formatting has gone weird, the ; is starting a comment which is not intended, read the z\_grid\_J lines carefully. I don’t want to change it as it is in matlab format.)

---

<div class="post-metadata">

**Author:** ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)\
**Post date:** [November 19, 2024, 10:41am UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/27 "2024-11-19T10:41:59Z")

</div>

Thank you very much for the detailed answer, Robert!

EDIT  
I think this part

```auto
for jj=1:N_j
   pi_z_J.sick(:,:,jj)=kron(pi_zh_J.sick, pi_zn); % note: kron in reverse order
   pi_z_J.healthy(:,:,jj)=kron(pi_zh_J.healthy, pi_zn); % note: kron in reverse order
end

```

should actually be

```auto
for jj=1:N_j
   pi_z_J.sick(:,:,jj)=kron(pi_zh_J.sick(:,:,jj), pi_zn); % note: kron in reverse order
   pi_z_J.healthy(:,:,jj)=kron(pi_zh_J.healthy(:,:,jj), pi_zn); % note: kron in reverse order
end

```

---

<div class="post-metadata">

**Author:** ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)\
**Post date:** [November 19, 2024, 7:15pm UTC](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331/28 "2024-11-19T19:15:51Z")

</div>

quite right, have corrected my post

[Previous page](https://discourse.vfitoolkit.com/t/age-dependent-health-shocks/331.md?page=1)
