Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Gillian.Frost@hsl.gov.uk |
To | statalist@hsphsun2.harvard.edu |
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 follows: 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 addresses. 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, Gillian ------------------------------------------------------------------------ ATTENTION: 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 expressed. 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 www.marshal.com ------------------------------------------------------------------------ * * 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/