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]

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


From   <catherine.tisch@ed.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Formatting a string variable (UK postcodes) to always be seven characters in length
Date   Tue, 4 Feb 2014 15:43:39 -0000

Good afternoon

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.

Many thanks
Catherine



-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

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