Announcement

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

  • Data transfer from Excel

    Dear friends,

    I copied my data directly from Excel and pasted into the Stata editor and ran a simple tabulation, but I observed some levels, such as dates and numbers, that are not listed in the string variable in the original dataset. It seems like I am inviting trouble using the copy/paste approach? Please which is the best way to remedy this problem?

    Thank you,

    Aminu.

  • #2
    When you copy/paste, Stata is actually getting text data that it must interpret. Usually, it will guess correctly, but it's easy to get into trouble with either date data or numeric data formatted in a special way, or even numerical values that you want to keep as strings (zip codes for instance).

    For instance, my Excel uses french conventions for decimal separator and thousand separator: copy/pasting will usually produce string variables, that I can then convert with the destring command with options ignore and dpcomma. If your dates are read as text, you can use Stata functions to convert to a Stata date (which is a numeric variable with a date format). See help date functions.

    My advice would be to try to import the Excel file (using import excel), and see if there are still problems. Usually Stata is able to use cell types found in the Excel worksheet, including dates.

    Hop this helps

    Jean-Claude Arbaut

    Comment


    • #3
      Thanks Jean-Claude Arbaut, the import excel actually works, but the problem is that my original variable names were changed to A, B, C, D, E, F... in the Stata. For example, the second variable (column) in the dataset is originally named "province" but in Stata it changed to B, and tabulate B produced a single table of the B variable with "province" listed as a level under the B variable. Is there a way to present the data in Stata as it is in the .xls file?

      Regards,

      Aminu.

      Comment


      • #4
        Oh, I used an option "first row as variable name" and it is now working. Many thanks for your time.

        Aminu.

        Comment

        Working...
        X