Announcement

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

  • How to Replace the Missing Values with a Set of Appropriate Integers between a Range within ID in Stata?

    clear
    input byte (id year)
    1 1
    1 .
    1 .
    1 4
    2 1
    2 2
    2 .
    2 .
    2 5
    3 1
    3 2
    3 .
    3 .
    3 .
    end
    I want to fill the missing values with the consecutive integers. For example,
    for id==1, the values to be added should be 2,3.
    for id==2, the values to be added should be 3,4.
    for id==3, the values to be added should be 3,4,5.
    Thanks for your code.

  • #2
    for your example above, try
    Code:
    replace year=year[_n-1] + 1 if year==.
    note that the above code assume that the data is already in the correct order

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X