I'm having difficultly with what seems a straightforward programming
exercise. I am trying to calculate the cumulative product for a variable
for panel data set.
My data basically consists of the following 3 variables: id, t, x.
id runs from 1 to 1,000; t (time interval) runs from 1 to 20; and x is a
ratio for each t (and id).
I am trying to calculate the cumulative product of x for each id across
time interval 1/20 in a new variable (prodx, say).
x does sometimes take the value zero (so exp(sum(ln(x))) isn't an
option).
I found the following thread unhelpful as "in" cannot be used with "by":
* * *
Assuming your original variable is x:
. generate runprod = x in 1
. replace runprod = runprod[_n-1]*x in 2/l
<snip>