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]

Re: st: Looping through entries in csv file

From   Neil Shephard <>
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,  <> 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!


"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 -
Website -
Photos -

*   For searches and help try:

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