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

st: RE: Re: modifying id code (p.s. bootstrapping)

From   "Nick Cox" <>
To   <>
Subject   st: RE: Re: modifying id code (p.s. bootstrapping)
Date   Mon, 14 Oct 2002 16:07:11 +0100

Kit Baum
> > i have to add "51" to all the id-codes in my dataset
> [variable "idcode" is
> > in the integer format]. can i convert it to string and
> add 51 at the end?
> Use
> gen str?? newcode = string(idcode)+"51"
> Fill in the ?? with the maximum length of the resulting code.
> The + operator is overloaded to denote concatenation of
> strings. Thus you
> could also do string(givenname)+" "+string(surname)
> although there are
> other ways of doing that.

There is a pitfall here.

-string(,)- takes two arguments, (1) a number
or a numeric variable and (2) a numeric format to use in converting to
Stata does not squawk if you provide just one
argument, but then you get the default format,
which in this circumstance is not ideal.
Thus, if you type

di string(123456789)

you will get


which is unlikely to be what you
want from this expression when manipulating
identifiers. A format such as %12.0g is likely to give better
results here.

di string(123456789,"%12.0g")

The fact that -string(,)- takes two
arguments is well documented, and it
is axiomatic that no default format
can be optimal for all circumstances.


*   For searches and help try:

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