title: Cumulatively counting up a variable in Stata
body: <p>I feel like this is very simple. I have a variable, that goes like this [0, 1, 2, 3, 0, 1, 2, 0, 1], starting at 0, ticking up and then reset. I need to be able to track which number reset each observation is at. So for that dataset, the values I'd expect are [1, 1, 1, 1, 2, 2, 2, 3, 3]. I can't quite figure this out.</p>
  
  <p>I'm using Stata at the moment, but I swap over to R, if that's easier. I have about half a million observations, so something that doesn't take too long would be appreciated.</p>