Dear All, Suppose that I have the following data:
For each id, I'd like to calculate the cumulative sum of `x' and call it variable `y'. The trick is, whenever we encounter x=0, the cumulative sum restarts from 1.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id year x y) 1 1968 1 1 1 1969 1 2 1 1970 0 0 1 1971 1 1 1 1972 1 2 1 1973 1 3 2 1968 0 0 2 1969 1 1 2 1970 1 2 end
Comment