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: Post codes to locality


From   "Scholes, Shaun" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Post codes to locality
Date   Tue, 24 Apr 2012 08:58:59 +0000

Paul, I have done the postcode/LSOA merge many times (mainly in SPSS!) so I thought it would be useful to 
show a quick Stata example using Phil's code below. Hope this helps. 

input str7 postcode	str9 lsoa
BL31HF	E01025667
BL41HF	E00135645
EC1V0AX	E00013457
end
sort postcode
save "R:\postcode_LSOA.dta",replace

// Patient data (with more than 1 observation with same postcode)

clear
input str7 postcode	
BL31HF	
BL31HF	
BL41HF	
EC1V0AX	
end
sort postcode
merge m:1 postcode using "R:\postcode_LSOA.dta", keep(match master)


Note however that in my experience it is rare for two different datasets containing postcode to be formatted in exactly the same way. What I do therefore
is create a postcode variable that contains no spaces/blanks (in both datasets: master and using) and 
perform the matching using that new postcode variable (so BL3 1HF becomes BL31HF; E1 1AA becomes E1AAA etc). 
I give an example below using a previous post:

//// create postcode variable with no spaces/blanks.

See (http://www.stata.com/statalist/archive/2003-01/msg00219.html)

clear
input str10 postcode
"BL3  1HF"
"E1 AAA"
"EC1V0AX"
end
gen str8 postcod2 = subinstr(postcode," ","",.)


Hope this helps 
Best wishes
Shaun






-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Phil Clayton
Sent: 23 April 2012 20:49
To: [email protected]
Subject: Re: st: Post codes to locality

How about:
merge m:1 postcode using lookupfile, keep(match master)

Phil

On 23/04/2012, at 3:41 PM, Paul O'Brien wrote:

> Thanks Kit,
> 
> But I get the error message: variable postcode does not uniquely 
> identify observations in the master data
> 
> Many of our patients share the same post code.
> 
> Paul
> 
> On 23 Apr 2012, at 12:28, Christopher Baum wrote:
> 
>> <>
>> I have a clinical database with postcodes of patients and want to convert the post codes to locality (LSOA). I have  a file with corresponding post codes/locality, but there are over 1m post codes in England and around 35,000 localities.
>> 
>> An gen .. if ... command takes for ever.
>> 
>> Is there a simper way?
>> 
>> 
>> http://www.stata.com/support/faqs/data/characteristics.html
>> 
>> 
>> Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
>>                            An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
>> An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html
>> 
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
> 
> -------------------------------
> Dr Paul O'Brien
> Raymede Clinic
> Westside Contraception and Sexual Health Services Central London 
> Community Healthcare Exmoor St London
> W10 6DZ
> UK
> +44 (0)20 8962 4450
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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