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: RE: cluster analysis with foreach


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: RE: cluster analysis with foreach
Date   Thu, 10 Jun 2010 16:07:55 +0200

<> 

In this special case, -cluster- saves them itself:


*************
sysuse nlsw88, clear
levelsof union
foreach level in `r(levels)'{
cluster kmeans age industry wage hours if union==`level', k(3)
}
*************

BTW, -if- is much better to condition than your -keep-. If you do want
-keep-, wrap it in -preserve-, -restore-...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Maximiliano
Manuel Silva Correa
Gesendet: Donnerstag, 10. Juni 2010 15:16
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: RE: cluster analysis with foreach

Greetings gentlemen

and how would go if I save the clsuetr analysis per state, sort to say

foreach s in states{
keep if state == `s'
do the cluster analysis for `s'
save in C\power by state\`s'.dta
}

How is the sintaxis to save a name that is the current macro value??

2010/6/9 Nick Cox <n.j.cox@durham.ac.uk>:
> I have comments on three levels.
>
> First, your example implies that you have two variables, -state- and
> -power_city-. I don't know what real scientific purpose clustering would
> serve here. Clustering on virtually any criterion will just tend to
> group together lots of smaller values of consumption, necessarily more
> similar than others, as larger cities will typically be more spread out
> in what for most if not all states will be very skewed distributions.
>
> Second, you set yourself up for the task of collating 50 or so cluster
> analyses. ("or so" depending on DC, Puerto Rico, etc.)
>
> Third, should you persist, your syntax might be something like
>
> egen group = group(state), label
> su group, meanonly
>
> forval i = 1/`r(max)' {
>        cluster ... if group == `i'
> }
>
> Nick
> n.j.cox@durham.ac.uk
>
> Maximiliano Manuel Silva Correa
>
> 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/


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