Announcement

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

  • Creating loop to convert SPSS to CSV

    Hi everyone, new user here. I have some basic skill in Stata but am trying to become more advanced. I have several SPSS files that I am trying to convert to CSV. I created a do-file where one-by-one I import the SPSS files using "import spss" and export as a CSV using "export delimited." I know I can do this all at once using a loop and a local with the different file names, but I'm not sure how to put it together. Would someone more advanced be willing to help me? I'd be very grateful!

  • #2
    Hi everyone, ok so I figured out how to create the loop. This is what I did:

    local mylist dataset1 dataset2 dataset3

    foreach x of local mylist {

    import spss using `x'.sav
    export delimited using `x'.csv
    clear all

    }

    However, my issue now is I can only make the loop work when the files names are single words, e.g. dataset1, dataset2, etc. But all the files have several names in the titles, like "2018 dataset." When I try adding the extra names in quotes in the do-file, it no longer works. Could anyone with knowledge of using quotes in Stata give me a hand?

    Comment


    • #3
      You've accidentally posted in the Sandbox, which is where people try out the forum software rather than ask questions about problems with Stata (See the descriptions of the different fora.) Items posted here are pretty likely to be skipped over.

      Comment

      Working...
      X