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: Looping through entries in csv file
From
Neil Shephard <[email protected]>
To
[email protected]
Subject
Re: st: Looping through entries in csv file
Date
Mon, 13 Sep 2010 14:44:57 +0000
On Mon, Sep 13, 2010 at 2:37 PM, Ada Ma <[email protected]> wrote:
> Open up the postcode-county file using stata or excel.
>
> I suppose the postcode sectors are all in a column. Select and copy it.
>
> Go into excel if you aren't already in excel. Right click, choose
> "paste special". Transpose the postcode. Now the postcodes all in
> one row. Copy it and paste into a do file. Edit them so that they
> looks nice (this step is optional).
A more direct method would be to do this in Stata. Something along
the lines of....
File with full Postcodes in is called postcodes.dta with the full
postcode held in the variable 'postcode'
use postcodes, clear
/* Get the first 3 characters of the postcode into a new variable */
gen sub_postcode = substr(postcode, 1, 3)
/* Store all of these unique values in a local macro using -levelsof- */
levelsof sub_postcode, local(postcode_districts)
di "`postcode_districts'"
/* Store all of these unique values in a global macro using -levelsof- */
levelsof sub_postcode, global(postcode_districts)
di "$postcode_districts"
(Use local or global macros depending on what you want to do with the
macrolist and how you're structuring/organising your do-files).
Neil
--
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell
Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
* 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/