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/