Assuming reg and ed are already strings with up to 2 and 5 digits, try
gen zpid = substr("00"+ref,-2,2) + substr("00000"+ed,-5,5)
Here + concatenates strings, we padd each part of the id with enough zeroes
and then take the last 2 or 5 characters. The minus sign in substr tells it
to count from the end.
You probably don't need this for ref if it is always >= 10. I assume you
have no missing values (blanks) but if you do the relevant part will be
coded as all zeroes.
Cheers,
Germ�n
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of ainsley charles
Sent: Thursday, February 16, 2006 10:23 PM
To: [email protected]
Subject: st: How can I add leading zeros conditionally?
Hello Statalisters,