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
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
justified (to the blank) in the other.  Consequently the merge works for
postcodes - such as 'YO10 5DD' - where the outward part occupies all
positions (the left and right justification generate the same result)
does not work where the outward part has less than four characters e.g.,
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.



*   For searches and help try:

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:

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