Announcement

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

  • how to calculate the loop for variables?

    I need to calculate the second row variable minus the first row variable, the fourth row variable minus the third row variable, the sixth row variable minus the fifth row variable
    How to write such loop?
    Thanks so much!
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(var1 var2 v3 v4 variable5 variable6)
    1 2 3 5 6 7
    end

  • #2
    Code:
    rename * v#, addnumber
    
    forval i=2(2)6 {
    local j=`i'-1
    gen v`i'_v`j' = v`i' - v`j'
    }

    Comment


    • #3
      Great, thanks so much!

      Comment

      Working...
      X