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]

AW: st: RE: cluster analysis with foreach


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
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: [email protected]
[mailto:[email protected]] Im Auftrag von Maximiliano
Manuel Silva Correa
Gesendet: Donnerstag, 10. Juni 2010 15:16
An: [email protected]
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 <[email protected]>:
> 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
> [email protected]
>
> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index