Announcement

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

  • Double quotes in outsheet

    Dear All,

    I need to export data in a particular format and I am hoping outsheet or export delimited can deliver tab-delimited output where values are enclosed in quotes if and only if they contain leading or trailing spaces.

    The default is to write all values in quotes, and option noquote removes quotes everywhere. I am looking for something in between.

    I can clearly loop over observations and variables and write the tab-delimited content myself, but I was hoping there is a way to convince the canned commands to achieve the same.

    Thank you, Sergiy Radyakin



  • #2
    Sergiy-- If no one can think of how to work this with -export delimited-, what about using -fileread- and -filewrite()- to touch up the file after the fact? I'm thinking of something like this:

    Code:
    export delimited using SomeTempfile ....noquote
    clear
    set obs 1
    gen strL s = fileread(SomeTempfile)
    local tabchar = char(9)
    local blank = " "
    replace s = subinstr(s, "`tabchar'`blank'" , ........ )    // You will fill in the escaped quotes better than me!
    gen numcharwritten = filewrite(SomeTempfile, s)

    Comment


    • #3
      Dear Mike, thank you for the advice!

      I thought about this in the context of filefilter , from() to().
      But the problem is that when the quote is opened, it also needs to be closed, while leading and trailing spaces are not necessarily matched (can be one, other, or both).
      Using fileread/filewrite should allow me to use regular expressions to try to identify the cell elements and enclose them with quotes, but with two potential issues:
      • performance - as the files are North of 1GB;
      • accuracy - any mistake in regex may ruin the file.
      Perhaps just reading the file line by line in Mata, tokenizing it there and processing each token would be my way in the absence of another advice.

      Thank you, Sergiy

      Comment


      • #4
        -fileread- and -filewrite- are amazingly fast. (Much faster than filefilter, if I recall correctly.) In fact, I posted something on this a while back and started to write a Stata Tip on their power in common with regular expressions and the like, but there was a bug in Stata (multiple version) that led to crashes occasionally. As of the most recent update, I think that bug may be fixed. I think speed will be fine. Now, regarding accuracy, that's a tough one! <grin>

        Comment

        Working...
        X