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]

AW: st: cluster analysis with foreach


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: cluster analysis with foreach
Date   Wed, 9 Jun 2010 21:36:46 +0200

<> 


" If you want to do it that way, fine but 

levelsof state, local(allstates) 
foreach s of local allstates { 
	...
} 

is one statement fewer."



Shortest version yet: 


*************
levelsof state
foreach s in `r(levels)'{ 
	...
}
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox
Gesendet: Mittwoch, 9. Juni 2010 19:02
An: statalist@hsphsun2.harvard.edu
Betreff: RE: st: cluster analysis with foreach

If you want to do it that way, fine but 

levelsof state, local(allstates) 
foreach s of local allstates { 
	...
} 

is one statement fewer. 

Nick 
n.j.cox@durham.ac.uk 

Stas Kolenikov

You seem to be thinking in R terms here :)). In Stata, this would be
something like

levelsof state
local allstates `r(levels)'
foreach s in `allstates' {
 cluster kmeans <list of power variables> if state == "`s'", k(#)
}

Of course you would also need to think how you will utilize the results.

On Wed, Jun 9, 2010 at 11:36 AM, Maximiliano Manuel Silva Correa
<maxsilvacorrea@gmail.com> wrote:

> Im stuck trying to run a cluster analysis routine throuth diferent
> sections of my data. Suppose we have power consumtion data about
> different cities of the US. What I'd like to do is to run a cluster
> analysis routine (cluster kmeans for example) by state, because i
> would like to see in every state which cities have similar power
> consumtion.
>
> It would be something like
>
> foreach s in states{
>
> cluster(kmeans, power_city)
>
> }
>
> (states is a string variable)
>
> Could someone show me the sintax here, or send similar examples?

*
*   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/


*
*   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