Announcement

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

  • Issues with multiple conditions with IF and Foreach

    Hello All,

    Please could you help me?

    Could you help me identify what's not working in the code below, please? What I'm trying to do is find the second value after the minimum in a set of 7 variables, while also considering conditions regarding other variables. When executing this code, it often happens that the two variables created have the same values, and the condition that the second variable should be greater than the first is not met.

    Here is the code:

    gen Var1 =.y
    forvalues i=1/7 {
    replace Var1 = ACHB`i'C if ACHB`i'C < Var1 & ~missing(ACHB`i'C) & RCI30_`i'== 1
    }

    gen Var2 =.y
    forvalues i=1/7 {
    replace Var2 = ACHB`i'C if (ACHB`i'C > Var1 & ACHB`i'C < Var2) & ~missing(ACHB`i'C) & (RCI30_`i'== 1)
    }

    Thank you for your assistance.

  • #2
    Duplicate post. If interested, follow at https://www.statalist.org/forums/for...ns-within-loop.

    Comment


    • #3
      Thank you so much for your reply, Mr Clyde. I'll see your advice in the other page.

      Comment

      Working...
      X