Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Formatting a string variable (UK postcodes) to always be seven characters in length


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Formatting a string variable (UK postcodes) to always be seven characters in length
Date   Tue, 4 Feb 2014 15:51:03 +0000

For readers worldwide, know that (e.g.) my home postcode is DH1 2NJ
with a space.

If some postcodes have already lost internal spaces, putting it back
in each case will be tricky. So, I wonder about taking them all out,

gen postcode2 = subinstr(postcode, " ", "", .)

but I have no idea whether that matches what is outside Stata,

Nick
njcoxstata@gmail.com


On 4 February 2014 15:43,  <catherine.tisch@ed.ac.uk> wrote:

> I'm hoping someone can help me with a formatting issue with regard to UK
> postcodes whereby I want to create a new postcode variable that is always
> seven characters in length from a postcode variable that has between five
> and eight characters (e.g. 7 numbers/letters with a space = 8).  I want to
> ultimately join my cleaned postcode variable created in Stata to a postcode
> shapefile in ArcGIS.  The postcode shapefile variable is always seven
> characters in length, with various combinations of letters, numbers and
> spaces, e.g.
>
> LN  NLL
> LLN NLL
> LNN NLL
> LLNNNLL
> LLNLNLL
> LNL NLL
>
> Where L represents a letter and N a number.  I need to clean my original
> postcode variable as there is little consistency (e.g. LN  NLL (two spaces)
> vs LNNLL (no space) vs LN NLL (one space).
>
> Are there any suggestions on how I can create a new postcode variable in
> Stata that is always seven characters in length bearing in mind that if a
> space/s is required, there always needs to be three characters at the end
> after the split?  I hope this all makes sense?!
>
> I'm using Stata 12.1, any help much appreciated.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index