Announcement

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

  • Automating web downloads when 0 is included, an issue with forvalue

    The blog post on the Stata Blog has helped me a lot in creating a loop to download folders at once ( https://blog.stata.com/2010/12/01/au...ile-unzipping/ )


    All the files followed the structure " DO@@yyyy.dbc " where @@ = acronym of each state and yyyy = year (4digits)


    So I was doing

    Code:
    local groups " AL CT NJ PA "
    forvalues i = 1996/2010 {
    foreach x of local groups{ 
    copy http://example.com/DO`x'`i'.dbc DO`x'`i'.dbc 
    }
    }

    However, now that they changed the structure of the file name to " DO@@yymm.dbc ", I am having troubles. In the file name structure "mm" varies from 01 to 12 and "yy" from 08 to 18. However, theforvaluefunction does not recognize the first 0, making the download fail.

    Does anyone have any advice on how to solve this problem?

  • #2
    Fairly limited range of values, so might be easiest to just write it out

    Code:
    local groups " AL CT NJ PA "
    local years "08 09"
    local months "01 02 03 04"
    foreach x of local groups{ 
    foreach y of local years{
    foreach m of local months{ 
    copy http://example.com/DO`x'`y'`m'.dbc DO`x'`y'`m'.dbc 
    }
    }
    }

    Comment


    • #3
      Note also the technique shown by

      Code:
      forval j = 1/12 { 
          local J : di %02,0f `j' 
          di "`J'" 
      }
      For more, see https://www.stata-journal.com/sjpdf....iclenum=pr0051 (despite the paper title...).

      Comment

      Working...
      X