I would like to code the earnings of a household which consists of a retired parent and a child. The parent faces health and survival risk. Parent receives social security payment SS if alive. If parent is not healthy, the child needs to take care of the parent. There is a time cost xi if the parent is not healthy since when taking care of the parent, the child cannot work. Assume the household lives for 7 periods, and the probability of being alive and healthy is different in each period. The code is something as follows
Aind = 1:N_grid;
[AIND,HIND,DIND] = ndgrid(Aind,Hind,Dind);
My question is , when parent dies, there will be no time cost for taking care of the parent. But this cannot be done by my code above. I tried to code as follows, but it returns an error of "Index exceeds the number of array elements (1)." I think this is because I have vectorized d, so the dimension is different, but I don't know how I should code. Thank you!