Announcement

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

  • append to file

    I am sure I am missing something basic here...

    I want to save the memory data to a file like
    Code:
    save "data.dta", append
    but of course, save doesn't allow append.

    There is the
    Code:
    append using "data.dta"
    command, but my understanding is that it does the opposite of what I seek - it appends contents of file into memory, while I want to append contents of memory to file.
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    The only solution I can see is something like:
    Code:
    tempfile datainmemory
    save 'datainmemory'
    use dataset.dta, clear
    append using 'datainmemory'

    Comment


    • #3
      Dennis finds the right approach - combine the files in memory, then save the combined file. Elaborating on his approach, if it's not important to you that the data in memory be at the end of the combined files, then
      Code:
      append using dataset
      save dataset, replace
      would do the job. If the order of the data makes a difference, then it's likely there's a variable, say ID, that determines the sort order, so
      Code:
      append using dataset
      sort ID
      save dataset, replace
      would do the job. If there is no variable to sort by, then
      Code:
      tempfile datainmemory
      save `datainmemory'
      use dataset, clear
      append using `datainmemory'
      sae dataset, replace
      would do what you need, correcting Dennis's typo on the left quotation mark surrounding the local macro references -
      Code:
      `datainmemory'
      not
      Code:
      'datainmemory'

      Comment


      • #4
        Thank you William! Both for the elaboration and the correction, my (more or less) smart phone can not distinguish ` and ', so I had to deliver a idea rather than a fully functional code. But I should have made a disclaimer. I stand corrected and beg pardon for my misguiding :-)

        Comment


        • #5
          Thank you both.
          Thank you for your help!

          Stata SE/17.0, Windows 10 Enterprise

          Comment

          Working...
          X