Announcement

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

  • Appending CSV files

    Hi All,

    I am encountering a strange problem. There are two excel files that I wish to combine in a dataset (one of them is from years 1950-1975, the other is from 1976-2000). All variables are the same in both. The way in which I combine these datasets is to use first the insheet command for one, and then the append command for the other.

    Now, when I insheet either of them first, each of them is read by stata. However, when I try to append the other, I get an r(601) error message, stating that the file in question is not found. When I try the insheet command, the file is found, but the same file is not found with the append command. Am I missing something obvious?

  • #2
    Hi Chinmay,

    I find it helpful to first convert the csv files to dta. Please double check if the file paths you are asking STATA to follow are correct. Using the GUI for this kind of activity is safer (since you are required to manually find both files using an explorer-like window). Go to Data -> Combine datasets -> Append datasets. Once you get the command right, you can copy it to your do-file.

    Good luck.

    Comment


    • #3
      An example of the code and exact message you are getting would be helpful, but I'm guessing the issue is that you can only append .dta files. When you -insheet- the first, you convert it to .dta. If, as I presume, but can't be sure, you are using the -append- command, you are attempting to then append a .csv which won't work. The file not found error is probably because it is either assuming you mean append filename.dta whether or not you specify the .dta. The solution is to convert both to .dta, roughly:
      Code:
      ***Insheet the first file
      insheet filename.csv, clear //add other options as needed
      tempfile yourfilename //declare the temporary file
      sa `yourfilename' //save the temporary file
      insheet filename2.csv, clear //import the second file
      append using `yourfilename' //append (both now .dta)

      Comment

      Working...
      X