Announcement

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

  • What workaround do you use for short-circuit operations?

    I want to write

    Code:
    if (g0 > 1 & v[g0] - v[g0-1] >= 5 ) ...
    but this errors out when g0 == 1 (since it tries to access v[g0-1] which is out of subscript bounds).

    I guess this is something Stata users commonly have to deal with. What do you do? I think I'll just put a double if

    Code:
    if (g0 > 1) if (v[g0] - v[g0-1] >= 5 ) ...
    since my code happens to be on one line, but that does not seem like a good general approach.

    Reference: https://en.wikipedia.org/wiki/Short-circuit_evaluation
Working...
X