Announcement

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

  • Loops, locals and saving files

    I want to save a number of files within a loop using the local macro as filename, for example
    Code:
    forvalues i = 1/10 {
                                 clear all
                                 insobs 10
                                 gen test = `i'
                                 save "C:\Users\matoh389\Downloads\`i'", replace
    }
    In this case, I want to save ten files namned "1.dta", "2.dta", ..., "10.dta" respectively in the directory "C:\Users\matoh389\Downloads". However, what the above code does is to save one file (probably overwriting it nine times) namned "Downloads`i'.dta" in the directory "C:\Users\matoh389". What am I doing wrong?

    I am using the Windows version of Stata 14.0, current update level: 10 Jun 2015.

  • #2
    See [U] 18.3.11 Constructing Windows filenames by using macros

    and/or

    SJ-8-3 pr0042 . . . . . . . Stata tip 65: Beware the backstabbing backslash
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q3/08 SJ 8(3):446--447 (no commands)
    tip to use forward slash instead of backslash for
    directory and file names

    http://www.stata-journal.com/article...article=pr0042
    Last edited by Nick Cox; 12 Jun 2015, 09:20.

    Comment


    • #3
      Ah, of course! Thanks!

      Comment

      Working...
      X