Announcement

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

  • How to create a variable representing the max length of consecutively same numbers in a row?

    I am trying to find a way to caculate the max length of consectively same numbers in each row . For example, let's look at the data below

    Code:
    clear all
    input str1(id) byte(a1) byte(b2) byte(c1) byte(f4) byte(m1) byte(m2) byte(t3)
    a 2 2 2 2 3 3 3
    b 5 5 1 2 3 4 5
    c 1 1 1 1 1 1 1
    d 5 4 5 6 4 5 3
    e 1 1 2 2 2 2 1
    f 7 7 7 1 1 1 1
    g 2 2 2 2 2 2 1
    h 3 3 3 1 1 1 2
    end
    I would like to generate a variable called 'maxlength'. Idealy, it would be like the following.

    Code:
    id    a1    b2    c1    f4    m1    m2    t3    maxlength
    a    2    2    2    2    3    3    3    4
    b    5    5    1    2    3    4    5    2
    c    1    1    1    1    1    1    1    7
    d    5    4    5    6    4    5    3    1
    e    1    1    2    2    2    2    1    4
    f    7    7    7    1    1    1    1    4
    g    2    2    2    2    2    2    1    6
    h    3    3    3    1    1    1    2    3
    Could we do so in Stata?

  • #2
    Duplicate post. If interested, please follow https://www.statalist.org/forums/for...mbers-in-a-row

    Comment

    Working...
    X