Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Removing quotation marks in string variables


From   John Adam Roberts <[email protected]>
To   [email protected]
Subject   Re: st: Removing quotation marks in string variables
Date   Fri, 5 Jul 2013 13:38:06 -0400

That's excellent!  Thank you very much.

On Fri, Jul 5, 2013 at 1:24 PM, Nick Cox <[email protected]> wrote:
> The logic is this.
>
> 1. You want to look for " as a literal character, not a delimiter.
>
> 2. Therefore compound double quotes `" "' must be used as delimiters.
>
> replace tags = subinstr(tags, `"""',  "", .)
>
> The awkward argument is
>
> `"    left compound double quote
> "    double quote to be taken literally
> "'   right compound double quote
>
> A trick to avoid all this is to note that  " is char(34)  [see
> -asciiplot- from SSC for a cheat sheet] so that
>
> replace tags = subinstr(tags, char(34), "", .)
>
> But hang on: "Jackson, Collin" is recognisably one field: if you strip
> the " you will lose that. So, this may not be your best strategy.
>
> Note also -split-.
>
>
> Nick
> [email protected]
>
>
> On 5 July 2013 17:57, John Adam Roberts <[email protected]> wrote:
>> Hi,
>>
>> I have a dataset that is full of strings that look like this:
>>
>> ATUS00001213, "ATUS00001256","Jackson,Collin"
>>
>> I'm going to separate these values into different variables and I'm
>> wondering how to remove the "s from the dataset.
>>
>> For other characters, like commas, I would use the following command:
>> replace tags = subinstr(tags,",","",.)
>>
>> but
>> replace tags = subinstr(tags,""","",.)
>> replace tags = subinstr(tags,'"',"",.)
>> replace tags = subinstr(tags,""",.,.)
>> replace tags = subinstr(tags,'"',.,.)
>> don't work.
>>
>> Thanks in advance for the help!
>>
>> -Adam
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/



-- 
Sincerely,
(John) Adam Roberts
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index