Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: How to convert multiple numeric variables into a single string variable?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: How to convert multiple numeric variables into a single string variable?
Date   Sun, 7 Oct 2007 17:05:13 +0100

Tiago: 

You really would benefit from skimming the on-line 
-help-, using -search- and browsing the manuals. 

In the first instance, there is a built-in 
command: 

egen var4 = concat(var1 var2 var3), p(_) 

and in the second instance, there is another 

split var4, p(_) destring 

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

tiago.pereira@incor.usp.br
 
> I would like to know if there is a command in Stata to 
> convert multiple
> numeric variables into a single string variable (and vice-versa). For
> example, suppose I have the following dataset:
> 
> var1 var2 var3
> 0 2 3
> 4 5 6
> 7 8 9
> 
> In this respect, I would like to create a new string 
> variable, say, var4,
> using the var1, var2 as well as var3. That is:
> 
> var1 var2 var3 var4
> 0 2 3 0_2_3
> 4 5 6 4_5_6
> 7 8 9 7_8_9
> 
> Finally, I would like to do the inverse process. From:
> 
> var1
> 0_2_3
> 4_5_6
> 7_8_9
> 
> to
> 
> var1 var2 var3 var4
> 0_2_3 0 2 3
> 4_5_6 4 5 6
> 7_8_9 7 8 9

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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