[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Kompal Sinha" <kompal.sinha@anu.edu.au> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: Re: generating a string from floats |

Date |
Wed, 30 Oct 2002 14:51:25 +1100 |

Thanks It works just fine. Just Curious: Is there a single command to do the exactly opposite thing:-splitting the string in subparts. Thanks Kompal -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Nick Cox Sent: Tuesday, October 29, 2002 8:01 PM To: statalist@hsphsun2.harvard.edu Subject: st: RE: Re: generating a string from floats Kompal Sinha wrote: > I have 5 variables(floats) in following format: (the > first row looks like this): > x y z t q > 123456 78965 12345 45678 56 > > I want to make a new Identifier variable (preferably > string) which just puts > the five variables side by side like: > 12345678965123454567856 > > I tried gen str23 caseid = x+y+z+t+q but it gives the > error type mismatch. > I also tried to convert floats to strings using > stattransfer but it didn't > work I am getting blank columns. I can't do it > mathematically as the number > created will be more than sixteen digits and won't solve > my purpose. Zhiqiang Wang > Use -string- function: > . gen str23 caseid=string(x) +string(y) + string(z) + > string(t) +string(q) Another solution is . egen caseid = concat(x y x t q) It is important to realise why Kompal got the error message reported. First, the expression x + y + z + t + q can only be interpreted as a numeric expression given that these variables are numeric and "+" means addition in that context. Only when you force Stata to deal with the string equivalents will Stata treat "+" as meaning concatenation. -egen, concat()- bundles into one command concatenation when all you need is to convert any numerics via string. For the details, see [R] egen. Nick n.j.cox@durham.ac.uk * * 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/

**Follow-Ups**:**st: Re: RE: RE: Re: generating a string from floats***From:*"Scott Merryman" <smerryman@kc.rr.com>

**References**:**st: RE: Re: generating a string from floats***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: help with record length problem** - Next by Date:
**st: Re: RE: RE: Re: generating a string from floats** - Previous by thread:
**st: RE: Re: generating a string from floats** - Next by thread:
**st: Re: RE: RE: Re: generating a string from floats** - Index(es):

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