Statalist


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

Re: st: RE: Splitting numeric values


From   "Michael S. Hanson" <mshanson@wesleyan.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Splitting numeric values
Date   Mon, 23 Jul 2007 21:29:29 -0400

On Jul 23, 2007, at 8:32 PM, Susan Olivia wrote:

Thanks so much for your suggestions. Unfortunately, it didn't work for me
after trying several of suggested solutions.

I think the culprit is due to having the id as numeric variable that comes
with 18 digits and stored as double as suggested by Profs Buis and Cox.
	Re: your original question, the following works for me:

. clear

. set obs 1
obs was 0, now 1

. gen double id = 610102001001010300

. gen str4 newvar = substr(string(id,"%20.0g"),10,4)

. list

     +--------------------+
     |        id   newvar |
     |--------------------|
  1. | 6.101e+17     0010 |
     +--------------------+


Any further insights on how to deal with this in STATA is much appreciated
since I am trying to avoid taking a brute-force approach in Excel/ Notepad to
split the variable and bring it back to STATA.
Assuming your original data are in Excel, I suspect you'd be in much better shape overall if you read the "id" variable in as a string from the start.

Hope this helps.

-- Mike

P.S.: No need to shout the name of the program! (See the below- cited FAQ.)

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