Announcement

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

  • Import DAT file using stata import wizard

    Dear all,

    I have a DAT file with over 200,000 observation. It has 12 variables, with all numeric values. I attached a sample with a few observation .

    When i use stata import wizard, and select text data (second option), it imports all 12 variables as 1 single variable.

    Can you suggest a different way to import it?


    Thanks,
    Rochelle
    Attached Files

  • #2
    I cannot help with the import wizard but here is a crude method. Replace all consecutive spaces in the text file by single spaces and them import the file with a single space as the delimiter. Other list members can probably suggest a more elegant way to do this.
    Code:
    copy "TBL-2-TEST.txt" "TBL-2-TEST2.txt", replace
    forval i = 1/3 {
      filefilter "TBL-2-TEST2.txt" "TBL-2-TEST3.txt", from("  ") to(" ") replace
      copy "TBL-2-TEST3.txt" "TBL-2-TEST2.txt", replace
    }
    erase "TBL-2-TEST3.txt"
    import delimited using "TBL-2-TEST2.txt", delim(" ")

    Comment


    • #3
      you want infix:
      Code:
      infix str x1 1-6 str x2 7-13 x3 14-15 x4 16-24 x5 25-33 x6 26-34 x7 35-43 x8 44-52 x9 53-61 using c:\data\TBL-2-TEST.txt
      Last edited by ben earnhart; 13 Nov 2015, 17:18. Reason: made first tow variables strings to keep leading zeros.

      Comment


      • #4
        Many Thanks to Friedrich and Ben !!! Ben's approach is easier for me.


        Comment

        Working...
        X