STATA Cluster Analysis (Need is 12 hours max)
Cluster Analysis1 One of the most fundamental marketing activities is market segmentation. As companies cannot
connect w/ all their potential customers, they must divide markets into groups of consumers.
Cluster analysis (CA) allows segments to be formed that are based on data that are less dependent on
subjectivity.
Understanding CA
CA is a convenient method for identifying homogeneous groups of objects called clusters.
Objects (cases, observations) in a specific cluster share many characteristics, but are very dissimilar to
objects not belonging in to that cluster.
Imagine that you are interested in segmenting your customer base to better target them through pricing
strategies.
The 1st step is to decide on the characteristics that you will use to segment your customers – i.e., you
must decide which clustering variables will be included in the analysis.
For example, you may wish to segment a market based on customers’ price consciousness (𝑥) and brand
loyalty (𝑦), both measured on a 7-point scale w/ higher values denoting more 𝑥 and 𝑦.
The objective of CA is to identify groups of objects (customers) that are similar w/ regard to price
consciousness and brand loyalty and assign them into clusters.
After having decided on the clustering variables, we need to decide on the clustering procedure.
Popular approaches that we’ll discuss include hierarchical methods, partitioning methods, and two-step
clustering procedures.
Each CA method follows a different approach to grouping the most similar objects into clusters.
But how do we measure similarity?
Most methods calculate measures of (dis)similarity by estimating the distance b/w pairs of objects.
Objects w/ larger distances are more dissimilar.
An important problem in CA is the decision regarding how many clusters should be derived from the
data.
On the one hand, you want as few clusters as possible to make clusters easy to understand and
actionable.
On the other hand, having many clusters allows you to identify more segments.
However, we must ensure that segments are large enough to make marketing programs worthwhile.
1 Notes from “A Concise Guide to Market Research,” by Sarstedt and Mooi.
As a result, we create some w/n-cluster heterogeneity, which makes targeted marketing programs less
effective.
In the final step of CA, we need to interpret the solution by defining and labeling the obtained clusters.
This can be done by examining the clustering variables’ mean values or by identifying explanatory
variables to “profile” clusters.
Ultimately, managers should be able to identify customers in each segment based on easily measurable
variables.
Finally, we must validate and interpret our CA solution.
Hence, the steps to perform a CA are graphically depicted below.
Decide on the Clustering Variables
Clustering variables can be categorized as being general or specific. Within each category, variables can
be observed or unobserved. Examples include
To facilitate the choice of clustering variables, you should consider the following guiding questions:
1. Do the variables sufficiently differentiate the segments?
It is important to select those clustering variables that provide a clear-cut differentiation b/w the
segments regarding a specific management objective.
Criterion validity is of special interest; that is, the extent to which the “independent” clustering variables
are associated w/ one of more “dependent” variables not included in the analysis.
Such DVs typically relate to some aspect of behavior, such as purchase intention or willingness-to-pay.
Given this relationship, there should be significant differences b/w the DVs across the clusters (e.g.,
consumers in one cluster exhibit a significantly higher willingness-to-pay than those in other clusters).
Note: These associations might not be causal, but it is essential that the clustering variables
automatically generated by Stata distinguish the outcome variable(s) of interest significantly.
2. Are the clustering variables highly correlated?
If there is strong correlation b/w the variables, they are not sufficiently unique to identify distinct
market segments. Absolute correlations > 0.90 are problematic.
3. Is the relation b/w sample size and number of clustering variables reasonable?
It is recommended that the sample size is at least 2𝑚, where 𝑚 equals the number of clustering
variables.
4. Are the data underlying the clustering variables of high quality?
Only those variables that ensure that high quality data can be used should be included in the CA. Data
are of high quality if:
Questions included in the survey have a strong theoretical basis
Respondent fatigue or response styles do not contaminate the data
The data reflect the current market situation (i.e., they are current)
Decide on the Clustering Procedure
By choosing a specific clustering procedure, we determine how clusters are to be formed.
This always involves optimizing some kind of criterion, such as minimizing the w/n-cluster variance, or
maximizing the distance b/w the objects or clusters.
Below is a quick overview of hierarchical, partitioning, and two-step clustering methods.
Hierarchical Methods
In this category, clusters are consecutively formed from objects.
This type of procedure starts w/ each object representing an individual cluster. These clusters are then
sequentially merged according to their similarity.
First, the 2 most similar clusters are merged to form a new cluster at the bottom of the hierarchy. In the
next step, another pair of clusters is merged and linked to a higher level of the hierarchy, and so on.
Below is a graphical representation of agglomerative clustering.
Select a Measure of Similarity or Dissimilarity
A straightforward way to assess two objects’ proximity is by drawing a straight line between them.
This type of distance is referred to as Euclidean distance (or straight-line distance) and is the most
commonly used type when it comes to analyzing ratio or interval-scaled variables.
Note: Market researchers usually treat ordinal variables as metric data to calculate distance metrics by
assuming that the scale steps are equidistant.
Suppose you want to segment a market based on customers’ price consciousness (price) and brand
loyalty (brand).
We can put this data into Stata using the input command.
. input str1 cust price loyalty
A 3 7
B 6 7
C 5 6
D 3 5
E 6 5
F 4 3
G 1 2
end
These data can be graphed as follows:
. scatter loyalty price, mlabel(cust)
Using the data above, we can compute the Euclidean distance b/w customer B and C w/ the following
formula (we are just solving for the length of the hypotenuse of a right triangle):
𝑑𝐸𝑢𝑐𝑙𝑖𝑑𝑒𝑎𝑛(𝐵, 𝐶) = √(𝑝𝑟𝑖𝑐𝑒𝐵 − 𝑝𝑟𝑖𝑐𝑒𝐶) 2 + (𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐵 − 𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐶)
2
= √(6 − 5)2 + (7 − 6)2 = 1.414
We can automatically compute the distance b/w all other pairs of objects in Stata.
. matrix dissimilarity distance = loyalty price
7. G 1 2
6. F 4 3
5. E 6 5
4. D 3 5
3. C 5 6
2. B 6 7
1. A 3 7
cust price loyalty
A B
C
D E
F
G2 3
4 5
6 7
lo y a
lt y
1 2 3 4 5 6 price
. matrix list distance
Another distance measure is the city block’s distance solved for as the sum of the variables’ absolute
differences.
𝑑𝐶𝑖𝑡𝑦−𝑏𝑙𝑜𝑐𝑘(𝐵, 𝐶) = |𝑝𝑟𝑖𝑐𝑒𝐵 − 𝑝𝑟𝑖𝑐𝑒𝐶| + |𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐵 − 𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐶| = |6 − 5| + |7 − 6| = 2
Researchers also use the Chebychev distance (called Linfinity in Stata), solved for as the maximum of the
absolute difference in the cluster variables’ values.
𝑑𝐶ℎ𝑒𝑏𝑦𝑐ℎ𝑒𝑣(𝐵, 𝐶) = max(|𝑝𝑟𝑖𝑐𝑒𝐵 − 𝑝𝑟𝑖𝑐𝑒𝐶|, |𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐵 − 𝑙𝑜𝑦𝑎𝑙𝑡𝑦𝐶|) = max(|6 − 5|, |7 − 6|) = 1
In many analysis tasks, the variables under consideration have a different number of categories.
We can solve this problem by standardizing the data prior to the analysis.
Nominal Variables
Applying the distance measures presented thus far to nominal variables is problematic.
When nominal variables are involved you should rather select a similarity measure expressing the
degree to which variables’ values share the same category.
These matching coefficients take different forms, but rely on the allocation scheme below.
Note: For variable w/ more than 2 categories, you need to convert the categorical variable into a set of
binary variables to use matching coefficients.
The simple matching coefficient can be solved for as
𝑆𝑀 = 𝑎 + 𝑑
𝑎 + 𝑏 + 𝑐 + 𝑑
obs7 5.3851648 7.0710678 5.6568542 3.6055513 5.8309519 3.1622777 0
obs6 4.1231056 4.472136 3.1622777 2.236068 2.8284271 0
obs5 3.6055513 2 1.4142136 3 0
obs4 2 3.6055513 2.236068 0
obs3 2.236068 1.4142136 0
obs2 3 0
obs1 0
obs1 obs2 obs3 obs4 obs5 obs6 obs7
This coefficient considers both the joint presence and the joint absence of a characteristic (as indicated
by cells 𝑎 and 𝑑 above).
This feature makes the simple matching coefficient useful for symmetric variables, where the joint
presence and absence of a characteristic carries an equal degree of information (e.g., gender).
SM can be a problem if used on non-symmetric variables.
Objects may appear very similar b/c they both lack the same characteristics (as expressed through cell
𝑑) rather than b/c they share common characteristics (as expressed through cell 𝑎).
In light of this issue, researchers have proposed the Jaccard (JC) and the Russel and Rao (RR)
coefficients, which do not include missing observations in the calculation of similarity.
They are defined as follows:
𝐽𝐶 = 𝑎
𝑎 + 𝑏 + 𝑐
𝑅𝑅 = 𝑎
𝑎 + 𝑏 + 𝑐 + 𝑑
To provide a brief example comparing the 3 coefficients, consider the following 3 variables:
Gender: male, female
Produce use: light, medium, heavy
Income: low, medium, high
We consider the following 2 objects:
Object 1: male customer, light user w/ low income and
Object 2: female customer, medium user w/ a low income
We 1st transform the measurement data into binary data by recoding the original 3 variables into 8
binary variables. The resulting binary data matrix is below.
Using the allocation scheme above yields the following results for the cells: 𝑎 = 1, 𝑏 = 2, 𝑐 = 2, and
𝑑 = 3.
This means that the 2 objects have only 1 shared characteristic (𝑎 = 1), but 3 characteristics which are
absent from both objects (𝑑 = 3).
SM, JC, and RR can be solved for as follows:
𝑆𝑀 = 𝑎 + 𝑑
𝑎 + 𝑏 + 𝑐 + 𝑑 = 4
8 = 0.5
𝐽𝐶 = 𝑎
𝑎 + 𝑏 + 𝑐 =
1
1 + 2 + 2 = 0.2
𝑅𝑅 = 𝑎
𝑎 + 𝑏 + 𝑐 + 𝑑 =
1
1 + 2 + 2 + 3 = 0.125
As can be seen, the SM coefficient suggests that the 2 objects are reasonably similar, but the JC and RR
coefficients suggest they are not.
Try to avoid combining metric and nominal variables in a single CA.
Select a Clustering Algorithm
After having chosen the distance or similarity measure, we need to decide which clustering algorithm to
apply.
There are several agglomeration procedures and they can be distinguished by the way they define the
distance from a newly formed cluster to a certain object, or to other clusters in the solution.
The most popular agglomerative procedures include the following:
Single linkage (nearest neighbor): The distance b/w 2 clusters corresponds to the shortest
distance b/w any 2 members in the 2 clusters.
Complete linkage (furthest neighbor): Assumes that the distance b/w 2 clusters is based on the
longest distance b/w any 2 members in the 2 clusters.
Average linkage: The distance b/w 2 clusters is defined as the average distance b/w all pairs of
the 2 clusters’ members.
Centroid: The geometric center (centroid) of each cluster is computed 1st. this is done by
computing the clustering variables’ average values of all the objects in a certain cluster. This
distance b/w the 2 clusters equals the distance b/w the 2 centroids.
Let’s look at how a clustering algorithm works. We will manually work through some of the single
linkage procedure’s calculation steps.
Start by looking the initial (Euclidean) distance matrix.
In the very 1st step, 2 objects exhibiting the smallest distance in the matrix are merged. Although there
is a tie, let’s proceed w/ forming a new cluster using objects B and C.
Having made this decision, we then form a new distance matrix by considering the single linkage
decision rule as discussed above.
According to this rule, the distance from object 𝐴 to the newly formed cluster is the minimum of 𝑑(𝐴, 𝐵)
and 𝑑(𝐴, 𝐶). Since 𝑑(𝐴, 𝐶) = 2.236 < 𝑑(𝐴, 𝐵), 2.236 is entered below.
We also compute the distances from cluster [𝐵, 𝐶] to all other objects (i.e., D, E, F, G) and simply copy
the remaining distances – such as 𝑑(𝐸, 𝐹) – that the previous clustering step has not affected.
Continuing the cluster procedure, we simply repeat the last step by merging the objects in the new
distance matrix that exhibit the smallest distance.
Now, calculate the distance from our new cluster [B, C, E] to all other objects to get the following:
Try to calculate the remaining steps yourself. Solutions are below.
A common way to visualize the CA is by drawing a dendrogram, which displays the distance level at
which there is a merger of objects and clusters.
We can perform our CA in Stata as follows:
. cluster single price loyalty
. cluster dendrogram
Again, the dendrogram is a graphical representation of the agglomeration schedule sketched out above.
By looking at the dendrogram, we could justify a 2-cluster solution ([1, 4, 2, 3, 5, 6) and [7]), as well as a
5-cluster solution ([2, 3, 5], [1], [4], [6], and [7]).
Research has suggested several other procedures for determining the number of clusters in a dataset.
One example is the variance ratio criterion (VRC) by Calinski and Harabasz.
For a solution w/ 𝑛 objects and 𝑘 segments, the VCR is solved for as
𝑉𝑅𝐶𝑘 = ( 𝑆𝑆𝐵
𝑘 − 1⁄ )
( 𝑆𝑆𝑤
𝑛 − 𝑘⁄ )
where 𝑆𝑆𝐵 is the sum of the squares b/w the segments and 𝑆𝑆𝑤 is the sum of the squares w/n the
segments.
The VRC for different segment sizes can be obtained in Stata using the “cluster stop” command.
. cluster stop
. cluster stop, rule(calinski)
0 1
2 3
L 2 d
is s im
ila ri ty
m e
a s u
re
1 4 2 3 5 6 7
Dendrogram for _clus_1 cluster analysis
We can also help to determine the number of segments by computing 𝜔𝑘 for each segment solution.
The formula for “little omega” is
𝜔𝑘 = (𝑉𝑅𝐶𝑘+1 − 𝑉𝑅𝐶𝑘) − (𝑉𝑅𝐶𝑘 − 𝑉𝑅𝐶𝑘−1)
This can be obtained in Stata w/ the following commands:
. do chomega.ado
. cluster single price loyalty
. cluster steop
. chomega
Note: In this example, there are not enough consecutive groups to calculate little omega.
If we are comfortable w/ a 2-cluster solution (or a 5-cluster solution), we can “segment” customers
using the “cluster generate” command.
. cluster generate group = group(2)
. cluster generate group2 = group(5)
Partitioning clustering methods
One of the most popular partitioning clustering methods is the k-means procedure.
This k-means algorithm uses the within-cluster variation as a measure to form homogenous clusters.
Specifically, the procedure aims at partitioning the data in such a way that the within-cluster variation is
minimized.
The clustering process starts by randomly assigning objects to a pre-specified number of clusters.
The objects are then successively reassigned to other clusters to minimize the w/n-cluster variation,
which is basically the (squared) distance from each observation to the center of the associated cluster.
w/ k-means, cluster affiliations can change in the course of the clustering process.
Another important property of k-means clustering is that we have to pre-specify the number of clusters
prior to running the analysis.
The 4 steps of the k-means clustering process are:
1. Using the pre-specified number of clusters are input, the algorithm randomly selects a center for
each cluster.
2. Euclidean distances are computed from the cluster centers to every single object. Each object is
then assigned to the cluster center w/ the shortest distance to it.
3. Based on the initial partition in step (2), each cluster’s geometric center (i.e., its centroid) is
computed. This is done by computing the mean values of the objects contained in the cluster
(e.g., A, B, C in the 1st cluster) regarding each of the variables. As you can see in the figures
below, both clusters’ centers shift into new positions.
4. The distance from each object to the newly located cluster centers are computed and objects
are again assigned to a certain cluster on the basis of their minimum distance to the other
clusters.
To help in deciding on the number of clusters before running a k-mean CA, consider the following:
1. Apply the VRC on different member clusters and chose the number that minimizes “little
omega.”
2. Run a hierarchical procedure to determine the number of clusters and k-means afterwards.
3. Rely on prior research findings.
We can run a k-means CA in Stata w/ 2 clusters using the commands below.
. cluster kmeans loyalty price, k(2)
. list
Validate and Interpret the Cluster Solution
Stability
Before interpreting the solution, we need to assess the stability of the results.
Stability means that the cluster membership of individuals does not change, or only changes little when
different clustering methods are used to cluster the objects.
You can use different clustering procedures on the same dataset and test whether they yield the same
results.
If more than 20% of the cluster affiliations change from one technique to the next, reconsider the set-up
and use a different set of clustering variables.
Another common approach is to split the data in 2 halves and to analyze each separately using the same
settings.
You then compare the two solutions’ cluster centroids using t-tests or an ANOVA.
Differentiation
The aim of any cluster analysis is to differentiate well b/w the objects. Thus, the identified clusters
should substantially differ from each other.
Members of different clusters should respond differently to different marketing-mix elements and
programs.
We can assess differentiation by examining the cluster centroids – i.e., clustering variables’ average
values of all objects in a certain cluster.
This can be ascertained by comparing the means of the clustering variables across the clusters w/
independent t-tests or ANOVA.
Profiling
Lastly, we need to profile the cluster solution by using observable variables. This step ensures that we
can easily assign new objects to clusters based on observable traits.
For example, we could identify clusters based on loyalty to a product, but to use these different clusters,
their membership should be identifiable according to tangible variables such as income, location, or
family size to be actionable.
Interpret the Clustering Solution
The interpretation of the solution requires characterizing each segment by using the criterion or other
variables (in most cases, demographics).
For example, you could highlight that customers in one segment have a lower willingness to pay and are
satisfied w/ lower service levels, whereas customers in another segment are willing to pay more for a
superior service.