Justin <[email protected]> asks:
> I am performing a cluster analysis, and have come up with 4 clusters. I would
> like to get a list of certain variables (in this case country & year) based on
> the cluster. So, I have cluster1 returning 275, cluster2:116, cluster3:318,
> cluster4:787. I would like to export the list of clusters 1,2,3 into excel
> since the results window would certainly not allow all to be displayed.
>
> I don't know if I have made myself clear at all with this, but can anyone help
> me out?
I am not 100% clear on what you are asking. But, if you are
asking how you can get a list or table of the countries and years
for each cluster you can do something like the following.
Here I am using the invest2 dataset used in the Stata manuals.
It has variables time and company (similar to your year and
country). It has 3 other variables invest, market, and stock
that I will cluster on and request 4 clusters.
webuse invest2
keep if time <= 6 <-- just to make smaller example
set seed 4328 <-- just to make it deterministic
cluster kmeans invest market stock, k(4) gen(clusvar)
tab clusvar
bysort clusvar : table time company
Also, if you read through the examples in "[CL] cluster kmeans"
and "[CL] cluster kmedians" you will see the use of -tabstat- to
display the min, mean, and max for the variables used in the
cluster analysis for each cluster group.
Other summary and display methods are also possible (all of Stata's
tools can be used on the cluster grouping variable along with
the other variables in your dataset).
You mention wanting to get the information out to excel. You might
do something like
outsheet time company using group1 if clusvar==1
outsheet time company using group2 if clusvar==2
outsheet time company using group3 if clusvar==3
outsheet time company using group4 if clusvar==4
This would produce 4 ASCII files that could easily be brought in
to excel. You could wrap those four lines in a loop (see -help
forvalues-).
I am sure there are also other ways.
Ken Higbee [email protected]
StataCorp 1-800-STATAPC
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/