Announcement

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

  • Keeping Observations Based on Conditional Row Numbers

    Dear Statalist,

    Apologies for this rather elementary question. I've dug through the manual and the web but am still in need of a final touch from the community.

    So I would like to only keep the 1st, 10th, 19th, ... and 32653rd observation of my data. So the sequence condition is 9x+1 when x progresses from 0 to 3628 by 1. I understand it should be a simple line of command of:

    keep if _n = ...

    And my question is how can I specify the condition of 9x+1 where x ranges from 0 to 3628 by 1 in order for the keep command to work?

    Thank you very much!

    Best,
    Yangxi Z.

  • #2
    Code:
    keep if mod(_n, 9) == 1 & _n <= 3628*9 + 1
    (Note: if the size of your data set is such that there are not 32,662 observations, then the & and everything that follows it can be omitted.)

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      keep if mod(_n, 9) == 1 & _n <= 3628*9 + 1
      (Note: if the size of your data set is such that there are not 32,662 observations, then the & and everything that follows it can be omitted.)
      Thank you very much!

      Comment

      Working...
      X