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

RE: st: recoding variables in order to merge datasets

From   "Nick Cox" <>
To   <>
Subject   RE: st: recoding variables in order to merge datasets
Date   Wed, 2 Jul 2003 14:55:18 +0100

Ernest Berkhout

> >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?
> I take it that both matchvars are string variables.
> Otherwise there would
> be no problem at all as the difference would be just in the
> formatting. If,
> as you suggest, in dataset 1 there is always a zero first, its more
> efficient to get rid of that one. This implies creating a
> str5 variable
> using the string finction substr(matchvar1,2,5). See -help substr-

Ernest apologised for sending this, but it's
a good solution.

However, to be hyper-cautious, what if -- contrary
to expectation -- the first character is not always
"0"? My best answer is that it is easy to check:

. assert substr(matchvar1,1,1) == "0"

No news is good news. If Stata confirms this assertion,
it says nothing. If it is false, in even one observation,
Stata will protest.


*   For searches and help try:

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