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: cluster analysis with foreach
From
Stas Kolenikov <[email protected]>
To
[email protected]
Subject
Re: st: cluster analysis with foreach
Date
Wed, 9 Jun 2010 12:16:11 -0500
I don't think there is an elegant way to do that (and, as Nick said,
this may or may not be meaningful enough). Each cluster analysis will
create its own variable. If you are going to have say less than 100
clusters in each of the analyses, and your states are numeric rather
than string ids, you can modify mine or Nick's syntax to:
levelsof state, local(allstates)
gen int allclus = 0
foreach s of local allstates {
cluster kmeans if state == `s', gen( state`s' )
replace allclus = `s'*100 + state`s' if state == `s'
}
On Wed, Jun 9, 2010 at 12:07 PM, Maximiliano Manuel Silva Correa
<[email protected]> wrote:
> Than you guys. How could I join the sucessive cluster analysis in one
> cluster variable??
>
> 2010/6/9 Nick Cox <[email protected]>:
>> If you want to do it that way, fine but
>>
>> levelsof state, local(allstates)
>> foreach s of local allstates {
>> ...
>> }
>>
>> is one statement fewer.
>>
>> Nick
>> [email protected]
>>
>> 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
>> <[email protected]> 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/
>
--
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
* 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/