Announcement

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

  • Creating new sheet in an imported .csv file

    Hi,
    I am coming up blank on this one and have spent some time going through putexcel + tabout commands and various other ways to do what I want, which should be basic...I'd hoped
    We are running STATA 15 - and all I want to do is create new sheets in an imported [to memory] excel .csv file or .dta.....
    I would have thought this easy to do but is like splitting time

    Can someone please provide some code that creates new sheets to an excel file please ?

    ie: sheet1 [contains my imported data], sheet 2 [I output from my imported data into here], sheet 3 [same as sheet 2], sheet 4 [same as sheet 2] etc...
    Last edited by Clincal Epidemiology; 25 Sep 2017, 21:48.

  • #2
    Your question is inconsistently worded and appears to ask the impossible.

    A CSV file cannot have multiple sheets. A CSV file is nothing more or less than an ordinary text file in which data have been placed, with the values of the variables separated by commas (or tabs). And although Excel works nicely with CSV files, CSV files are in no way specific to Excel. There is no possibility of having multiple tabs in such a file. Not from Stata, not from any software. In fact, try it. Open an Excel spreadsheet (.xls or .xlsx) that has multiple tabs and Save As a .csv file. You will see that the multi-tab structure is lost when you do that.

    What can have multiple tabs is an Excel spreadsheet. You can easily create them using the -export excel- command. And -export excel- has a -sheet()- option that lets you specify which of the tabs in the file you want to write the data into (or create a new one if it does not already exist.) Just run -help export excel- and read about it. You can have all the tabs you want in there; but it's not a CSV file. It's an .xls or .xlsx file.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Your question is inconsistently worded and appears to ask the impossible.

      A CSV file cannot have multiple sheets. A CSV file is nothing more or less than an ordinary text file in which data have been placed, with the values of the variables separated by commas (or tabs). And although Excel works nicely with CSV files, CSV files are in no way specific to Excel. There is no possibility of having multiple tabs in such a file. Not from Stata, not from any software. In fact, try it. Open an Excel spreadsheet (.xls or .xlsx) that has multiple tabs and Save As a .csv file. You will see that the multi-tab structure is lost when you do that.

      What can have multiple tabs is an Excel spreadsheet. You can easily create them using the -export excel- command. And -export excel- has a -sheet()- option that lets you specify which of the tabs in the file you want to write the data into (or create a new one if it does not already exist.) Just run -help export excel- and read about it. You can have all the tabs you want in there; but it's not a CSV file. It's an .xls or .xlsx file.
      Thank you Kindly Clyde - explains my problem using STATA with this format in some detail, greatly appreciated.

      I might add I did export to an .xlsx format - but when re-importing to further modify - I noticed [using browse func] that my numeric data had suddenly turned into odd characters - which threw me..!
      Last edited by Clincal Epidemiology; 25 Sep 2017, 22:17.

      Comment


      • #4
        I might add I did export to an .xlsx format - but when re-importing to further modify - I noticed [using browse func] that my numeric data had suddenly turned into odd characters - which threw me..!
        Can you provide a reproducible example of that: an example Stata data set that, when exported to Excel and then re-imported garbles the numeric data into odd characters?

        Now, you need to read the FAQ before you proceed. In #12 you will learn that the useful way to show a Stata data example is to use the -dataex- command, which you can get by running -ssc install dataex-. Then run -help dataex- to see the simple instructions for using it. By using -dataex-, your example will be a complete and faithful replica of your Stata example, and anyone who wants to help you will be able to easily import it to Stata with a simple copy/paste operation. So use -dataex- whenever you post a data example.

        Another thing you will learn in the FAQ is that the norm in this community is to use our real first and last names. It promotes both collegiality and professionalism. Unfortunately, the Forum software does not permit you to change your username by editing your profile. So you will need to click on CONTACT US in the lower right hand corner of this page and ask the system administrator to change your username.

        The other parts of the FAQ, not immediately relevant to your thread but useful for your future use of Statalist, will give you excellent advice on how to write clear posts that have a good chance of drawing a helpful and timely response. Well worth the time it takes to read.

        Comment

        Working...
        X