Hi,
I have the following dataset:
I would like to count the consecutive "USREC"=="1", reinitialize the counter again when "0", not count the "0"s and start the counter over again when a new series a "1" starts. Manually, it looks as follow:
I'm not sure how to program that. I have tried using "_n", unsuccessfully. Can someone help? Thanks!
I have the following dataset:
Code:
USREC myear 1 2001m4 1 2001m5 1 2001m6 1 2001m7 1 2001m8 1 2001m9 1 2001m10 1 2001m11 0 2001m12 0 2002m1 0 2002m2 0 2002m3 0 2002m4 0 2002m5 1 2002m6 1 2002m7 1 2002m8 1 2002m9 0 2002m10 0 2002m11 1 2002m12 1 2003m1 1 2003m2 0 2003m3 0 2003m4
Code:
USREC myear rec_month 1 2001m4 1 1 2001m5 2 1 2001m6 3 1 2001m7 4 1 2001m8 5 1 2001m9 6 1 2001m10 7 1 2001m11 8 0 2001m12 0 0 2002m1 0 0 2002m2 0 0 2002m3 0 0 2002m4 0 0 2002m5 0 1 2002m6 1 1 2002m7 2 1 2002m8 3 1 2002m9 4 0 2002m10 0 0 2002m11 0 1 2002m12 1 1 2003m1 2 1 2003m2 3 0 2003m3 0 0 2003m4 0
Comment