Search code examples
statalinefeed

Stata: removing line feed control characters


I have a dataset which I export with command outsheet into a csv-file. There are some rows which breaks line at a certain place. Using a hexadecimal editor I could recognize the control character for line feed "0a" in the record. The value of the variable producing the line break shows visually (in Stata) only 5 characters. But if I count the number of characters:

gen xlen = length(x)

I get 6. I could write a Perl programm to get rid of this problem but I prefer to remove the control characters in Stata before exporting (for example using regexr()). Does anyone have an idea how to remove the control characters?


Solution

  • The char() function calls up particular ASCII characters. So, you can delete such characters by replacing them with empty strings.

    replace x = subinstr(x, char(10), "", .)