Announcement

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

  • Adding values if cell above is not empty

    Hi everyone,

    How can I create a variable Y that sums the values of variable X that follow a missing observation?

    Example:

    X Y
    . .
    . .
    1 1
    1 2
    . .
    . .
    1 1
    1 2
    1 3
    1 4
    1 5
    . .
    . .
    1 1
    1 2
    1 3

    Thanks!

  • #2
    try something like
    Code:
    gen want=0 if x==.
    replace want=want[_n-1]+x if x!=.

    Comment


    • #3
      Thanks so much, Sarah!
      It worked like a charm!

      Comment

      Working...
      X