Announcement

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

  • importing a csv data in Stata

    Hi. I have been sent a csv list of ID numbers together with their respective values which denotes, whether the people are male or female, etc. However, when I import the data in Stata, it shows the ID numbers together with the variable gender in one cell and thus does not let me to calculate the percentage of the sample which is male or female. I am not sure if I am able to explain well. So it comes up as the following:
    cdy7897QM8nDKfds,"2"
    c456456MmfdgfdgnE7uwM,"1"
    so both information, i.e. id numbers and the values for gender (1-female, and 2 - male, let us say) appear under one variable. Is there anyway I could programme it so it shows them separately in stata, when importing the data?

    Thanks a lot.

    best

  • #2
    Since you didn't tell us what command you used, nor show a copy of the first few lines of your input file, it's hard to know where your mistake was.

    I think the simplest approach is to use Stata's File menu to access the interactive File > Import > Text data (delimited, *.csv, ...) dialog box, then try the various options until you get what you need. Once you import the data, Stata's Results window will show the command that was used, and you can copy it and paste it into your do-file so you can rerun it whenever you need to, and refer to it in the future.

    Comment


    • #3
      HI. I used the following command:
      . import delimited "C:\Users\U0114841\Desktop\dataforoxfordultimate\r esident non resident excel file.csv", clear
      (1 var, 600 obs)

      I have tried everything. I do not understand why the information comes inside one cell, like this (see below). .I am a bit desperate, since there are 600 observations, and I cannot manually separate these two information, i.e. ID and the label "2" or "3" for another variable. Thanks a lot.
      M2I1Yzk0NDdsc3ZmI,"2"
      M2IxNTcwNzUdsyYzF,"3"
      M2IxZGRlMdsdsjA2OTM,"2"
      M2JlMjsdsUyNDk3OWR,"2"
      MDA0YzI1OdsdsDk5YWE,"3"
      MDAwsdsNjM2ODdjYTk,"2"
      MDJhZjU2MzRkdsdsODE,"2"

      Comment


      • #4
        Use split inside Stata parsing on commas.

        Comment


        • #5
          Since the file name ends with "excel file", perhaps the file format is Excel rather than plain text? You could make a backup copy, change the file name extension to ".xlsx" and try import excel. Does the first line in the file contain the listed data or something else such as variable names?

          Edit: Missed Nick's Stata solution which looks good to me (as usual).
          Last edited by Anders Alexandersson; 22 Mar 2018, 06:27. Reason: Edit: Missed Nick's Stata solution which looks good to me (as usual).

          Comment


          • #6
            Dear Nick and Anders, thanks a lot! I have indeed used split command with parse (,), and it worked marvelously. Anders, the file was named an excel, but it was in csv format. Thanks again!

            Comment

            Working...
            X