Using Calligram to identify key contributors to Consumer Price Index
Word clouds are a useful way to visualise data, allowing the size and colour of words to represent different values. The user-written calligram command, developed by Fahad Mirza, provides a flexible way to create customised word clouds in Stata.
In this TechTip, we demonstrate how to use calligram to visualise Australian Consumer Price Index (CPI) data. We will create a word cloud in the shape of Australia, with each word representing an expenditure category. The size and colour of each word will reflect its annual percentage price increase.
Our final graphic will be titled Australian Consumer Price Inflation: A Breakdown.
Installing the calligram command
The calligram command is available from GitHub.
To install the command, enter the following in Stata:
net install calligram, from("https://raw.githubusercontent.com/fahad-mirza/calligram_Stata/main/") replace
Once installed, enter help calligram to explore the command’s available options.
Preparing the CPI data
For this example, we use CPI data published by the Australian Bureau of Statistics (ABS), available through the ABS Data Explorer.
The dataset contains detailed CPI expenditure categories and their annual percentage price changes for August 2026.
To improve the appearance of the word cloud, we have shortened some of the expenditure category names. For example, New dwelling purchase by owner-occupiers has been shortened to New homes.
The dataset contains two important variables:
calligramlabel- the expenditure category displayed in the word cloud.annualchange- the annual percentage price change for that category.
We begin by loading our prepared dataset:
. use "CPI_data.dta", clear
For this example, we want to focus exclusively on expenditure categories that experienced price increases. We therefore remove observations with zero, negative or missing annual percentage changes.
. drop if annualchange <= 0 | missing(annualchange)
(13 observations deleted)
This ensures that the remaining observations contain positive values that can be used to determine word size.
Creating the Australian map
One interesting feature of calligram is its ability to arrange words within a customised shape.
For our example, we will use an Australian geographic boundary shapefile to create a word cloud in the shape of Australia.
We first download an Australian boundary shapefile and extract the files into our working directory. Stata’s spshape2dta command converts the shapefile into Stata datasets:
. spshape2dta "AUS_2021_AUST_GDA2020", replace
(importing .shp file)
(importing .dbf file)
(creating _ID spatial-unit id)
(creating _CX coordinate)
(creating _CY coordinate)
file AUS_2021_AUST_GDA2020_shp.dta created
file AUS_2021_AUST_GDA2020.dta created
This creates a geographic attribute dataset and a coordinate dataset. The coordinate dataset, AUS_2021_AUST_GDA2020_shp.dta, contains the boundary information required by calligram.
We will use this dataset with the shapes() option to define the outline of our word cloud. The coordinate dataset must be accessible from Stata’s current working directory, or its full path must be specified.
Creating the word cloud
With our CPI data prepared and the Australian boundary coordinates available, we can create the word cloud.
. calligram, wordvar(calligramlabel) ///
> countvar(annualchange) ///
> shapes(AUS_2021_AUST_GDA2020_shp.dta) ///
> outline outlinewidth(1) ///
> outlinecolor(#b8b8b8) ///
> minfreq(0) nostopwords ///
> minfontsize(2) maxfontsize(45) ///
> colorby(annualchange) ///
> gradient(#FEE08B #A50026) ///
> font("Open Sans") ///
> title("Australian Consumer Price Inflation: A Breakdown") ///
> savefile(cpi-calligram.html) ///
> image(cpi-calligram.png, replace)
calligram: 56 of 56 words placed (largest font 45px).
calligram: colours: average of Annual change (%) over the responses each word appears in (low #FEE08B, high #A50026)
calligram: image saved to /Users/davidwhite/Library/CloudStorage/OneDrive-surveydesign.com.au/Documents - Survey Design - Team Share/Ruben/Calligram/demo/cpi
> -calligram.png
Word cloud saved to /Users/davidwhite/Library/CloudStorage/OneDrive-surveydesign.com.au/Documents - Survey Design - Team Share/Ruben/Calligram/demo/cpi-calli
> gram.html
Click the path above, or open the file in any web browser.
You can also explore the HTML visualisation below.