StatsSA's CPI inflation statistics
Whilst the Headline Consumer Price Index (CPI) is the price index that is most commonly referred to (it is the index for all urban areas, for all items), there are in fact many Consumer Price Indicies, across various different geographical regions, or types of goods.
Scrapes the latest CPI data from StatsSA's website
Graphs of all the different types of inflation indicies
Data downloads of the indicies
A calculation tool to see the increase in prices compared to an earlier date
Scrape and tidy the latest StatsSA inflation data
Do you need the latest inflation index, to show your analysis at the most recent level of prices? You can use this R code to scrape the latest price indicies from StatsSA's website, and tidy the dataset. I often check that there are no bugs with the scraping code month-to-month. You may find future CPI publication dates in the UCT Economics Society's online calendar.
If you cannot run R, you can use the tidy Excel file that I keep updated in my Dropbox storage, or you can pull the .csv file programmatically. I maintain stable URL redirects for those files at http://xlsx.cpi.aidanhorn.co.za (download) and http://csv.cpi.aidanhorn.co.za (raw) respectively.
For example, in Stata, type this at the beginning of your .do file:import delimited using "https://www.dropbox.com/s/nuv21cnr5w4qaz8/CPI.csv?raw=1"
keep if region=="All urban areas"
scalar latest_CPI = allitems in -1
scalar latest_CPI_month= month in -1
scalar latest_CPI_year= year in -1
Then merge the data with your dataset.
Or, in R, type:
filter(Region=="All urban areas")
# Headline CPI is the CPI for all urban areas, all items.
latest.CPI <- setNames(
See the first page of https://aidanhorn.shinyapps.io/time-series-analytics for my inflation graphs web app.
Whilst StatsSA typically reports year-on-year statistics, I also calculate a smooth inflation rate trend, the derivative of a stochastic filter on log CPI. The formula is
=( exp( slope(log CPI trend) )^(time intervals per year) -1 ) *100%
where I use an HP filter for slope(log CPI trend). This formula can also be applied to other time-series variables to find the smooth growth rate trend. (My tweet.)