Announcement

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

  • Generating a running count variable based on a condition

    Hello. This is my first post on the forum. Many thanks in advance.

    I am trying to create a running count variable which would start on 1 and only change (to the next number) when the Repeat value is over 60.

    The Repeat value relates to the time (days) between prescriptions. Patid is the patient id.

    So what I would like to end up with is var3 (which I have manually generated).

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long patid float Repeat byte var3
    1  18  1
    1  35  1
    1  23  1
    1  26  1
    1  21  1
    1  38  1
    1  22  1
    1  67  2
    1 108  3
    1  19  3
    1  76  4
    1  41  4
    1 105  5
    1  35  5
    1 211  6
    1  26  6
    1  99  7
    1  57  7
    1  98  8
    1 105  9
    1   6  9
    1 119 10
    1  46 10
    1  81 11
    1  77 12
    1  20 12
    1  79 13
    1  79 14
    1  84 15
    1  89 16
    end

    Please let me know if you require any further details.

    Best wishes

    Debabrata



  • #2
    Hello.

    I have come across a similar problem answered on the Stata.com, Resources and Support, FAQs (What is true and false in Stata?) and the following was suggested:

    generate var3 = sum(Repeat > 60)

    Thanks and apologies if my question was not relevant to post.

    Debabrata

    Comment

    Working...
    X