Bookmark and Share

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

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

st: Looping through entries in csv file

Subject   st: Looping through entries in csv file
Date   Mon, 13 Sep 2010 14:55:36 +0100

Hello Statalist,

I have a bit of a data management problem, and I was hoping that you would 
be able to help me.

I have a Stata data file containing about 60,000 names and addresses.  The 
addresses are held in 6 different variables, add1-add6, corresponding to 
different lines of the address.  The postcode can appear in any of the 
address variables. 

I also have a separate csv file that contains the postcode districts in 
Great Britain (the section of postcode before the space, e.g. for the 
postcode 'SK17 9JN' the postcode district is 'SK17'), and what county the 
district belongs to (for example, the county for SK17 is "East Midlands"). 
 There are about 2,800 postcode districts in total.

What I want to do is identify the county the individual lives in using the 
postcode of their address.  I thought that I might be able to do this as 
For each line in the postcode csv file:
1. Identify if the postcode is present in any of the address variables 
using -strpos(s1,s2)-
2. If present, set the county of the individual to be the county 
corresponding to that postcode district from the csv file.

However, I am struggling to find a way to loop through the rows of the csv 
file to enable me to search for each of the postcode districts in the 

I would greatly appreciate any help with this, as I am struggling to think 
of a way to do it.  Please let me know if anything needs clarifying.

Many thanks,



This message contains privileged and confidential information intended
for the addressee(s) only. If this message was sent to you in error,
you must not disseminate, copy or take any action in reliance on it and
we request that you notify the sender immediately by return email.

Opinions expressed in this message and any attachments are not
necessarily those held by the Health and Safety Laboratory or any person
connected with the organisation, save those by whom the opinions were

Please note that any messages sent or received by the Health and Safety
Laboratory email system may be monitored and stored in an information
retrieval system.
Think before you print - do you really need to print this email?

Scanned by MailMarshal - Marshal's comprehensive email content security
solution. Download a free evaluation of MailMarshal at
*   For searches and help try:

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