Announcement

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

  • How to Identify the Position of a Value within Group in Stata?

    I have a dataset like this,
    clear
    input byte (id state)
    1 0
    1 .
    1 1
    2 0
    2 0
    2 1
    3 0
    3 .
    3 1
    4 0
    4 .
    4 0
    4 .
    4 1
    end
    I want to find the position of the "1" within id, which is always in the last place within a person.
    I want to use integer to represent the position.
    Thank you for your help!

  • #2
    Sorry, it is wrong. bys id: gen position=[_N]
    It is very simple.

    Comment

    Working...
    X