Statalist The Stata Listserver


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

st: RE: Manipulating strings


From   "Alex Ogan" <[email protected]>
To   <[email protected]>
Subject   st: RE: Manipulating strings
Date   Fri, 7 Apr 2006 10:41:27 -0400

In the file that has 'Y10  5DD', 

gen merge_postcode = postcode
replace merge_postcode = " " + substr(merge_postcode,1,3) +
substr(merge_postcode,5,4) if substr(merge_postcode,4,1)==" "

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Friday, April 07, 2006 10:25 AM
To: [email protected]
Subject: st: Manipulating strings

I want to merge two files using a postcode variable.  In both the master
and
using files postcode is an 8 character string.  And in both files the
postcode comprises an outward part (of up to the first four characters),
followed by a blank, followed by an inward element (the remaining three
characters).  For example: YO10 5DD, B1 4TH, DR3 5HJ.

The problem is that the outward part is left justified in one file but
right
justified (to the blank) in the other.  Consequently the merge works for
postcodes - such as 'YO10 5DD' - where the outward part occupies all
four
positions (the left and right justification generate the same result)
but
does not work where the outward part has less than four characters e.g.,
for
Y10 5DD which is ' Y10 5DD' in one file but 'Y10  5DD' in the other. 

Any suggestions how to overcome this would be most welcome.

Thanks.

Steve


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


This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message. 

Arrowstreet Capital, L.P. is an Equal Opportunity Employer. 



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index