[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: -tostring- updated on SSC
Thanks to Kit Baum, -tostring- has been updated
on SSC. Stata 8 is required. To install, use -ssc-
-tostring- was originally written for Stata 6 by
Jeremy Wernow, then of Stata Corporation, and myself,
and published in STB-56 (with a revision in STB-57).
That version, 1.2.3, remains available for download
by users of Stata 6 or Stata 7 in the STB archives
on the Stata website.
The revised version, 2.0.0, implements some overdue
revisions to bring -tostring- into line with (my
interpretation of) good Stata practice.
-tostring-, as the name implies, exists to convert
numeric variables to string. It is the inverse of
the official Stata command -destring-. One reason
is for using it is that you have, somehow, numeric
variables which you realise really should be string.
This happens more rarely than the opposite, but
it does happen. Often users have identifiers composed
entirely of numeric digits, but then they realise that
these are more appropriately stored as string. Another
use is in conjunction with Roger Newson's programs
in which you have datasets which are really resultssets
(so to speak), but you are producing some "results are
like restaurants" presentation in which stars are
attached to numbers. For such a purpose, you need
to convert your numbers to strings before you can
affix the decoration desired.
In a general discussion
"On numbers and strings", Stata Journal 2(3): 314-329
it was suggested that the main ways of converting back
and forth between numbers and strings should be
thought of in pairs, namely
(1) brute force: functions -real()-, -string()-
(2) handling value labels: commands -encode-
(3) correcting accidents of birth: commands
-destring- and -tostring-.
In the same article, it was noted that some features
of -tostring- are, in retrospect, bad, or at least arguable,
choices, and would be withdrawn in future versions:
being able to -decode-; being able to over-write existing
variables without specifying -, replace-;
and being able to ignore details (especially
in fractional parts) without specifying a -force- option.
Now the author is able to announce a less powerful program
from which all this functionality has been withdrawn --
but with the intent of
(1) trying to produce a command which does one thing well
(2) making it much more difficult for users accidentally to lose
what may be important details in their
In particular, one of two options, either -generate()- or
-replace-, must now be specified. And if converting any numeric
variable to string would result in loss of information,
no variable will be produced unless the -force- option is
* For searches and help try: