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

st: RE: recoding variables in order to merge datasets


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: recoding variables in order to merge datasets
Date   Wed, 2 Jul 2003 14:30:15 +0100

Erica Seiguer
>
> I am trying to merge two datasets which have the same variable coded
> differently in each.
>
> In dataset 1, the variable is 6 digits, with the first
> digit being a zero.
>
> in dataset 2, the same variable is 5 digits, and the first
> digit (which
> should be a zero) as been truncated.
>
> Does anyone know how to add a zero to the variable in the
> second dataset?

This is a variant on a question asked yesterday on
leading zeros.

If your variables are both numeric, then whether or
not a leading zero is shown is a matter of display
format and should not affect comparison.

If your variables are both string, then prepending a zero
is a -replace-

. replace myvar = "0" + myvar

If one variable is numeric and another string, then
convert one or the other. -destring- is one canned
solution in official Stata to convert string to numeric.

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