Dear All,

I am trying to do the calculation illustrated in Excel with Stata. Specifically, I would like to compute values in column M. But as you could see in the formula line, each value in column M needs the previous value as input to compute. For example, the value of M6 depends on the value of M5, and so on. I am struggling to achieve this using Stata with the codes below. It always give me missing values. I really appreciate it if someone could help me with this.


Many thanks in advance for your assistance,
Di

Code:
     *generate counterfactuals (M column) 
    gen cf1 = 0 
    replace cf1 = a0 + a1*cf1'[_n-1] + b2*shock2 + b3* shock3 + et


Array