Announcement

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

  • Importing CSV data containing multiline cells into Stata


    Hello everyone,

    I have a CSV dataset where some cells contain multiline text separated by "enters". When I try to import it into Stata, I'm facing an issue where only the first line of the multiline text is imported, and the rest gets truncated.

    For example, in the CSV file, the data might look like this:

    166559;26723;"Pauta:
    •yadaydaydaydaydayda
    •lololololololol
    •xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    •jajajajajajajjaa

    blablablablabalbalba
    2353546

    yadaydayada
    ";

    However, when I import it into Stata, it looks like this:

    Var1 Var2 Var3
    166559 26723 Pauta

    As you can see, I lose the rest of the information in Var3, which is crucial for my analysis. This issue occurs in several columns of the dataset, and due to the large number of lines and lack of a consistent pattern, manual correction or simple routines are not feasible options.

    Could someone please provide guidance on how to import this data correctly into Stata, preserving the multiline structure of the cells?

    Thank you in advance for your help!

  • #2
    Originally posted by Alex Mark View Post
    Could someone please provide guidance on how to import this data correctly into Stata, preserving the multiline structure of the cells?
    use the bindquote(strict) option.
    Code:
    import delimited <filename>, bindquote(strict)

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      use the bindquote(strict) option.
      Code:
      import delimited <filename>, bindquote(strict)
      Thanks, I tried but still having the same problem.

      Comment


      • #4
        Works for me using your example dataline. Data file, do-file and log file attached.
        Code:
        version 18.0
        
        log using Mark.smcl, nomsg name(lo)
        
        clear *
        
        type Data.txt
        
        quietly import delimited Data.txt, bindquote(strict) varnames(nonames)
        describe
        
        list v1 v2, noobs clean
        list v3, noobs clean
        
        log close lo
        
        exit
        I don't know why the code above wouldn't work for you, but you can also try something like filefilter beforehand.
        Code:
        help filefilter
        Attached Files

        Comment


        • #5
          Originally posted by Joseph Coveney View Post
          Works for me using your example dataline. Data file, do-file and log file attached.
          Code:
          version 18.0
          
          log using Mark.smcl, nomsg name(lo)
          
          clear *
          
          type Data.txt
          
          quietly import delimited Data.txt, bindquote(strict) varnames(nonames)
          describe
          
          list v1 v2, noobs clean
          list v3, noobs clean
          
          log close lo
          
          exit
          I don't know why the code above wouldn't work for you, but you can also try something like filefilter beforehand.
          Code:
          help filefilter
          Thanks again. True, with this example I gave it works, my example is that it was bad. another part of the base and what didn't work is the following CELINA MARIA FERRO DE OLIVEIRA; INTEROPERABI STANDARD MANAGER AND INFO ANALYSIS; MANAGER;60428;26792;Meeting with AMIL Assistência Médica Internacioan S/A;60427;Share with ANS on AMIL's initiatives on the COPISS theme and AMIL TOKEN;10 /10/2018 11:00;10/10/2018 12:30;ANS;;"Participants: Rodrigo Rodrigues de Aguiar/ Director of Sector Development - ANS Daniel Meirelles Fernandes Pereira/ Director - Deputy for Sector Development - ANS Laís Perazo / Director of institutional relations - AMIL Anderson Farias / IT Director - AMIL ";RJ This way, only "Participants" appears in the variable where I would like all the text to appear. I'll take a look at filefilter, if it works I'll come back here with the answer.

          Comment

          Working...
          X