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

st: RE: converting format

From   "Nick Cox" <>
To   <>
Subject   st: RE: converting format
Date   Mon, 14 Oct 2002 09:30:33 +0100

Satyarth Kulshrestha
> I need to convert a integer variable to string so that i 
> can add "51" at 
> the end of all the values. how to do this?

A concurrent thread touches on pertinent issues. 
Also, there is a longer discussion in Stata Journal 
2(3), 314-329 (2002). 

In that thread I urged the merits of keeping ids as 
string, although much depends on the details.

In this case, 

. gen str1 newid = "" 
. replace newid = string(id, "%12.0g") + "51" 

Naturally you could try it as a numeric operation: multiply by 100 
and add 51, but to keep precision in all digits, make sure the 
result is put in a -double- or -long-. 

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index