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

Re: st: From: "Adolf Mkenda" <[email protected]>


From   "Dev Vencappa" <[email protected]>
To   <[email protected]>
Subject   Re: st: From: "Adolf Mkenda" <[email protected]>
Date   Tue, 19 Jul 2005 17:38:59 +0100

>>
*convert your numeric variable to string first
tostring varname, replace force
format newvar %13.0f
gen newvar=substr(varname,6,1)

*convert the new variable back to numeric
destring newvar, replace force

I think this should work.

Dev

>>> [email protected] 07/19/05 5:21 pm >>>
Hi,
I am trying to isolate some digits from a variable to form a new variable.
For example, I have a variable with 13 digits (e.g. 5101232120011) and I
want to extract the 6th digit (in this case 3) and make it a separate
variable. The original variable always has 13 digits in it. I wonder
whether I can use Stata to do this. I will appreciate suggestions.
Adolf Mkenda
Dar es Salaam.
*
*   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/


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.


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