If there aren't any decimal values in your numeric variable, you may
destring the variable, i.e.
destring numvar, gen(strvar)
followed by a invoking the substr() function
replace strvar = substr(strvar,1,4)
If numvar contains decimal values, it won't destring properly due to the
problems related to converting decimals values (stored using binary digits)
to string, such as when converting 0.1 to a string. The binary
representation of 0.1 (and of many other numbers) is not exact; this has
been often discussed on statalist in the past. I will hold off making
recommendations on how to proceed if numvar contains decimals, for now,
given the complexity involved.
Patrick Joly
[email protected]
[email protected]
-----Original Message-----
From: Lassen, Peter, pla [mailto:[email protected]]
Sent: Thursday, January 16, 2003 9:30 AM
To: [email protected]
Subject: st: reduce a variables numbers of digits to 4 counting from
left
Hi,
I have a numeric variable of 9-12 digits, of wich only the first 4 digits
counting from the left is of importance. I therefore have to get rid of the
remaining 5-8 digits.
But how?
Best regards and thanks
Peter
*
* 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/
*
* 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/