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

st: RE: extract a subset of numbers from a bigger number


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: extract a subset of numbers from a bigger number
Date   Wed, 15 Sep 2004 18:36:09 +0100

Similar questions are often asked on this list. 

If X is numeric, 

gen newvar = mod(X,100000) 

If it is string, 

gen newvar = substr(X,-5,5) 

For this kind of basic operation, rummaging in the 
help for functions is illuminating. 

Nick 
[email protected] 

Alejandro Ria�o
 
> How can I extract the last 5 digits a 9-digit number
> (say a social security number) creating a new variable
> ?
> 
> i.e.
> 
> X                  newvar
> 999912345 --->     12345

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index