Statalist


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

Re: st: Splitting numeric values


From   Michael Hanson <mshanson@mac.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Splitting numeric values
Date   Sun, 22 Jul 2007 18:51:03 -0400

On Jul 22, 2007, at 6:30 PM, Susan Olivia wrote:

I have a numeric variable (call it id) that comes with 18 digits and I would
like to create a new variable that extracts from the variable 'id' starting
from the 10th digits and get 4 digits from here.

E.g. my id is given as: 610102001001010300 and I want to create 'newvar'
which has value of 0010.
	[snip]

Any advice on how to handle this would be much appreciated.
	Wouldn't this work?  (Untested)

. gen str4 newvar = substr(string(id),10,4)

Hope this helps.

                                        -- Mike


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