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

st: RE: Long integer as string bugaboo


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Long integer as string bugaboo
Date   Wed, 19 May 2004 21:31:11 +0100

. gen var1 = substr(string(numvar, "%12.0f"),1,6) 

You need to provide a format to override -string()-

Also, the sometimes maligned -tostring- has a default 
which avoids the need for working this out for yourself, 
plus extra safety features. 

Nick
n.j.cox@durham.ac.uk 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Wallace, John
Sent: 19 May 2004 21:03
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: Long integer as string bugaboo


Sorry to rehash old problems, but several archive searches haven't been on-point enough at the moment.  The problem is I have a serial number that I want to parse into two different variables.  The serial is stored as double, but when I try to -string()- it I get the following:

In: 
numvar
123456001
123457001
123458001

.gen var1=substr(string(numvar),1,6)

out:
var1
1.23e+
1.23e+
1.23e+

I know I dealt with this once in the past, but I can't remember how I handled it.

John Wallace | Research Associate | Test Method Development
AFFYMETRIX, INC. | 3380 Central Expressway | Santa Clara, CA 95051 | Tel:  408-731-5574 | Fax:  408-481-0435

*
*   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