[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Re: modifying id code (p.s. bootstrapping)
> > 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?
> 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
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
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: