Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating a Counter

    Hi,

    This may seem trivial but I am trying to create a counter of the following nature:

    We have data on date, dummy for a capital stop episode. I want to create a counter of the nature shown below. The counter should identify the number of periods for which the stop episode was observed. It should start afresh as soon as a 0 is encountered for stop.

    Would anyone be able to provide a neat code to do this?

    Many thanks
    Dhruv
    date IFSCode stop stop_counter
    1996q1 578 0 0
    1996q2 578 0 0
    1996q3 578 0 0
    1996q4 578 0 0
    1997q1 578 0 0
    1997q2 578 1 1
    1997q3 578 1 2
    1997q4 578 1 3
    1998q1 578 1 4
    1998q2 578 1 5
    1998q3 578 1 6
    1998q4 578 0 0
    1999q1 578 0 0
    1999q2 578 0 0
    1999q3 578 0 0
    1999q4 578 0 0
    2000q1 578 0 0
    2000q2 578 0 0
    2000q3 578 1 1
    2000q4 578 1 2
    2001q1 578 1 3
    2001q2 578 0 0
    2001q3 578 0 0
    2001q4 578 0 0
    2002q1 578 0 0
    2002q2 578 0 0

  • #2
    Code:
    search tsspell

    Comment


    • #3
      Thanks Nick! This is useful

      Comment

      Working...
      X