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

st: RE: converting to string


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: converting to string
Date   Mon, 22 Sep 2003 17:29:29 +0100

Ban,R (pgt) 

I'm having a bit of trouble with my reshape command because 
not all the variables that are to be put together are of the 
same type. Namely, say a1, a2, a3, which are to be reshaped 
into a, are not all string.
In my case there's a lot of these occurences. So I want to know 
if there's an easy way to make all the variables that I _know_ 
are supposed to be string, string.

I tried:
unab forcestring : *name
foreach i of local forcestring {
    gen str1 xx`i' = ""
    replace xx`i' = string(`i')
    drop `i'
    renpfix xx
}

this gives me an error, because i realize now that string(`i') 
works only if  `i' is numeric. Now a forceful method would be to do
_cap replace_, but i was wondering if there's something more elegant.
Thanks so much.

-radu ban

-tostring- is now an official Stata command. 
It leaves existing string variables untouched. 

However, I am not clear whether it is really 
the other way round and you should be applying 
-destring-. 

You decide; the syntax is (now) similar 
and the help for both is at -whelp destring-
(or -help destring-). 

Nick
n.j.cox@durham.ac.uk 

<<attachment: winmail.dat>>




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