Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Looping through entries in csv file


From   Neil Shephard <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Looping through entries in csv file
Date   Mon, 13 Sep 2010 15:53:57 +0000

On Mon, Sep 13, 2010 at 3:44 PM,  <Gillian.Frost@hsl.gov.uk> wrote:
> Neil and Ada,
>
> A huge thank you for your help so far, I really appreciate this.
>
> Ada, unfortunately I think the number of postcode district (around 2,800)
> is greater than the number of rows in Excel, so I can't quite get my list
> that way.
>
> Neil, thank you for pointing out the -levelsof- command.  I would really
> like the list as a global rather than a local, but this does not appear to
> be an option of -levelsof-.

Ooops, my mistake, not sure why I thought that was an option.

Do away with the equals sign in setting the global macro and try some
single quotes around the scalar, and then encapsulate in double quotes
because its a string...

> I have tried the following code:
>
> - - - - start code - - - -
> levelsof district
> global postcode_district  "`r(levels)'"
>
> foreach l of global postcode_district {
>        display "`l'"
> }
> - - - - end code - - - -
>

Do bear in mind though that there are limits on macro lenghts (see
-man limits- in the version of Stata you are using).

> Also, is it possible to keep a global and use it when I -clear- the
> current dataset, and upload a different one?

Nothing in the help for -clear- indicates that it will destroy
macro's, nor does the -insheet, clear- option either.  Try it out and
see what happens!

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 - nshephard@gmail.com
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index