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   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Formatting a string variable (UK postcodes) to always be seven characters in length
Date   Tue, 4 Feb 2014 12:14:37 -0500

Catherine,

I believe you can transform this code (in Stata):

view http://radyakin.org/statalist/2014/20140204_1200.do
do http://radyakin.org/statalist/2014/20140204_1200.do

        zip       code
    aa9a9aa   AA9A 9AA
     a9a9aa    A9A 9AA
      a99aa     A9 9AA
     a999aa    A99 9AA
     aa99aa    AA9 9AA
    aa999aa   AA99 9AA

The rules are from Wikipedia:
http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#The_modern_postcode_system

Best, Sergiy Radyakin


On Tue, Feb 4, 2014 at 10:51 AM, Roberto Ferrer <[email protected]> wrote:
> Catherine,
>
> I believe you need a set of rules before figuring out the Stata
> syntax. If the postcode has 8 characters, which one do you delete? If
> it has 5, what do you add? And so on...
>
> On Tue, Feb 4, 2014 at 11:13 AM,  <[email protected]> wrote:
>> 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/
> *
> *   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/
*
*   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