Bookmark and Share

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 15:53:57 +0000

On Mon, Sep 13, 2010 at 3:44 PM,  <[email protected]> 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 - [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/


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