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

st: RE: RE: combinig two variables into one


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: combinig two variables into one
Date   Thu, 1 Aug 2002 17:42:58 +0100

pgupta@worldbank.org
>
> I have two variables which I need to use to generate a new
> variable. to be
> more
> specific, suppose I have variable X (which is a numeric
> string) and variable
> Y
> (which is numeric). the observations are as follows:
>
> X                                      Y
>
> 2  23  3000                    2
> 212343000                   3
> 2     4       20                 12
>
> and I need to generate a new variable, say Z which looks like
>
> Z
> 2  23  3000  2
> 212343000  3
> 2    4        2012
>
>
> can someone suggest whats the best way of handling this problem?

Tao Jiang

> how about
>
> gen str80 z=X+" "+string(Y)
>

I can't see from the layout of the original exactly
what is wanted, but my answer is on the same lines:

egen z = concat(X Y), p(" ")

-egen, concat()- is a convenience command for concatenation
of string variables and (the string equivalent of) numeric variables.

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

*
*   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