Announcement

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

  • forvalues with skipped values

    I have about 300 items for which I want to run the forvalues loop. However, I need to skip about 6 values.

    Can I do something like
    Code:
    forvalues i = 1/111 113/134 136/139 141/189 191/203 205/222 224/317 {
    ?
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    Code:
    foreach i of numlist 1/111 113/134 136/139 141/189 191/203 205/222 224/317{
    May be easier with

    Code:
    forval i=1/317{  
    if inlist(`i',112,135,140, 190, 204, 223) continue
    Last edited by Andrew Musau; 02 Dec 2018, 14:51.

    Comment


    • #3
      Clever! Thanks
      Thank you for your help!

      Stata SE/17.0, Windows 10 Enterprise

      Comment


      • #4
        Andrew's answer is fine, but check out more detailed discussion at https://www.stata.com/support/faqs/d...-with-foreach/ -- especially Method 1, creating a new grouping variable with egen.

        Comment


        • #5
          I want to use the forvalues command with number non consecutive as 10 11 13(1) 33
          how should i write it?

          Comment


          • #6
            Code:
            foreach x of numlist 10 11 13/33 {
            as in #2.

            Comment

            Working...
            X