Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: String Manipulation Question


From   Alan Neustadtl <alan.neustadtl@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: String Manipulation Question
Date   Fri, 5 Aug 2005 17:12:57 -0400

Thanks for both suggestions--both worked perfectly.  I need the double
quotes so I can easily move data from Stata to a network analysis
application (that requires quoted strings).

Best,
Alan


On 8/5/05, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> You have the correct idea on trimming: just
> use -trim()-.
> 
> I am not clear why you want explicit double
> quotes as part of the string, but you
> can do it this way.
> 
> Example:
> 
> sysuse auto
> gen make2 = `"""' + make + `"""'
> 
> That is, in each case, you need
> 
> a delimiter that is `"
> the character itself, "
> a delimiter that is "'
> 
> The single quotes are left single
> quote and right single quote.
> 
> Compound double quotes are discussed
> at [U] 18.3.5.
> 
> This also works:
> 
> gen make3 = char(34) + make + char(34)
> 
> Nick
> n.j.cox@durham.ac.uk
> 
> > -----Original Message-----
> > From: owner-statalist@hsphsun2.harvard.edu
> > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of
> > Alan Neustadtl
> > Sent: 05 August 2005 21:47
> > To: statalist@hsphsun2.harvard.edu
> > Subject: st: String Manipulation Question
> >
> >
> > Okay, I'm stumped after searching through the manuals.  I have a
> > string variable that has the name of a group.  For example, "Stata
> > Users Group" (stored without the quotes).
> >
> > I want to create a new variable that 1) trims the string, 2) adds " as
> > a prefix, and 3) adds" as a suffix.
> >
> > In other programs you could do something like this:
> >
> > generate newname='"'+trim(name)+'"'
> >
> > That is, enclose the double quotes in single quotes.
> >
> > Can anyone direct me to the relevant portions of the manuals
> > or know the answer?
> >
> > TIA,
> > Alan
> >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index