<p>The BLS details the construction of the CPI Index in detail <a href="https://www.bls.gov/opub/hom/pdf/cpihom.pdf" rel="nofollow noreferrer">here</a></p>
<p>Moreover, you can find some notes on methodology changes <a href="https://www.bls.gov/cpi/notices/2017/methodology-changes.htm" rel="nofollow noreferrer">here</a></p>
<p>You may find the package IndexNumR in R useful for index number calculation, you can find the documentation <a href="https://cran.r-project.org/web/packages/IndexNumR/vignettes/indexnumr.html" rel="nofollow noreferrer">here</a></p>

CC BY-SA 4.0
2020-11-06T10:19:56.083Z
2020-11-06T10:19:56.083Z
Ali
<p>There are multiple different ways of how CPI can be constructed, if you want just some general approaches then some examples include <a href="https://www.nber.org/books-and-chapters/improving-measurement-consumer-expenditures/constructing-pce-weighted-consumer-price-index" rel="nofollow noreferrer">Blair (2013)</a> or <a href="https://www.nber.org/system/files/working_papers/w5980/w5980.pdf" rel="nofollow noreferrer">Shapiro &amp; Wilcox (1997)</a> and sources cited therein.</p>
<p>Other handbooks than the BLS you do not find useful also have detailed explanations of how they construct CPI. See here for example <a href="https://unstats.un.org/unsd/EconStatKB/KnowledgebaseArticle10296.aspx" rel="nofollow noreferrer">this practical guide</a> to CPI from UN looks good.</p>
<p>However, I am surprised that you say you found BLS Handbook of Methods not useful. In <a href="https://www.bls.gov/opub/hom/pdf/cpihom.pdf" rel="nofollow noreferrer">chapter 17</a> they describe the way how they estimate CPI in excruciating detail (over more than 100 pages).</p>
<p>I dont think there is any publicly avaiable R scrip or stata do file with calculation of CPI from ground up. I doubt that statistical offices even compute these indices with R or stata. However, R package that you might find useful is <a href="https://www.r-bloggers.com/2016/10/use-r-to-calculate-inflation-with-the-blscraper-package/" rel="nofollow noreferrer">blscrapeR</a> - which should allow you to extract CPI even for a subset of data.</p>

CC BY-SA 4.0
2020-11-06T17:00:00.763Z
I guess my question goes more in the sense of how to access and work with the raw data and if there is a document that explains how to use that data to build the CPI. For exameple, I found this: https://download.bls.gov/pub/time.series/cu/cu.txt and the data files that are in the directory, but I cannot see more details on how one could use the data for analysis.
Alex Ruiz
CC BY-SA 4.0
2020-11-06T17:06:46.057Z
@AlejandroRuiz I am little bit confused by what exactly you would like to find. The text document you linked does not have everything, but when I look at the handbook I linked in my answer it covers excruciating detail. It even covers how exactly raw data are collected and how exactly the CPI is constructed. The handbook literary goes even into detail on areas where the sampling is done and how pries are recorded/imputed in different sectors. If you are asking for some further analysis once you already have CPI, that of course wont be in the handbook
1muflon1
CC BY-SA 4.0
2020-11-06T17:06:49.250Z
- which is just a guide to how data are build and has nothing to say how they should be further analyzed, but the latter depends specifically on your research and if this is what you want then your current Q does not reflect that.
1muflon1
CC BY-SA 4.0
2020-11-06T17:22:42.110Z
My main question would be: Where can I find the raw data and the relative weights? My goal is to build some aggregate categories of my own.
Alex Ruiz
CC BY-SA 4.0
2020-11-06T17:26:59.897Z
@AlejandroRuiz oh well I wish you would say this in your original Q because that is quite a different question. However, the weights are in that handbook chapter 17 that I linked. The weights are in text they won’t be published as separate data. For example at pp 30 you have list of different weights for CPI-U. When it comes to raw data on specific areas that won’t be in the handbook of course, for that I think the R command will be useful as it allows you to scrape the data but to just provide direct link I would have to some further search (it was not clear you want this form the original Q)
1muflon1
CC BY-SA 4.0
2020-11-06T17:36:06.127Z
Oh okay. I will then look more into the blscrapeR. Also, in regard to the relative weights, I meant the relative importance of components. I saw in the Handbook they are in Appendix 9. However, I did notice that the ones reported in the Handbook are slightly different from the ones in the CPI-U excel document that was published for September 2020. Also, I already change my original Q. Thanks for that.
Alex Ruiz
CC BY-SA 4.0
2020-11-06T10:30:18.260Z
2020-11-06T10:30:18.260Z
1muflon1
<p>I hope this question is not inconvenient for any of you, so I would appreciate if you do not mark it as not useful.</p>
<p>I want to work with the data of the CPI from the BLS (I am not American, and this is the first time I am using the BLS). I want to ask where I can find the raw data and the relative importance of components. My goal is to build some aggregate categories of my own.</p>
<p>Also, I would like to know if there exists any R script or Stata do file that explains how to build the CPI.</p>
<p>Thank you in advance for your help.</p>

<macroeconomics><inflation><data-request><federal-reserve>
CPI dataset from BLS
Alex Ruiz
# CPI dataset from BLS

(Asked by: username_0 on 2020-11-06)

I hope this question is not inconvenient for any of you, so I would appreciate if you do not mark it as not useful.

I want to work with the data of the CPI from the BLS (I am not American, and this is the first time I am using the BLS). I want to ask where I can find the raw data and the relative importance of components. My goal is to build some aggregate categories of my own.

Also, I would like to know if there exists any R script or Stata do file that explains how to build the CPI.

Thank you in advance for your help.

**Tags:** macroeconomics, inflation, data-request, federal-reserve


---

## 2 answers

### Answer by username_1 on 2020-11-06. Score: 1

The BLS details the construction of the CPI Index in detail [here](https://www.bls.gov/opub/hom/pdf/cpihom.pdf)

Moreover, you can find some notes on methodology changes [here](https://www.bls.gov/cpi/notices/2017/methodology-changes.htm)

You may find the package IndexNumR in R useful for index number calculation, you can find the documentation [here](https://cran.r-project.org/web/packages/IndexNumR/vignettes/indexnumr.html)


---

### Answer by username_2 on 2020-11-06. Score: 1

There are multiple different ways of how CPI can be constructed, if you want just some general approaches then some examples include [Blair (2013)](https://www.nber.org/books-and-chapters/improving-measurement-consumer-expenditures/constructing-pce-weighted-consumer-price-index) or [Shapiro & Wilcox (1997)](https://www.nber.org/system/files/working_papers/w5980/w5980.pdf) and sources cited therein.

Other handbooks than the BLS you do not find useful also have detailed explanations of how they construct CPI. See here for example [this practical guide](https://unstats.un.org/unsd/EconStatKB/KnowledgebaseArticle10296.aspx) to CPI from UN looks good.

However, I am surprised that you say you found BLS Handbook of Methods not useful. In [chapter 17](https://www.bls.gov/opub/hom/pdf/cpihom.pdf) they describe the way how they estimate CPI in excruciating detail (over more than 100 pages).

I dont think there is any publicly avaiable R scrip or stata do file with calculation of CPI from ground up. I doubt that statistical offices even compute these indices with R or stata. However, R package that you might find useful is [blscrapeR](https://www.r-bloggers.com/2016/10/use-r-to-calculate-inflation-with-the-blscraper-package/) - which should allow you to extract CPI even for a subset of data.

> **Comments:**
> **username_0**: I guess my question goes more in the sense of how to access and work with the raw data and if there is a document that explains how to use that data to build the CPI. For exameple, I found this: https://download.bls.gov/pub/time.series/cu/cu.txt and the data files that are in the directory, but I cannot see more details on how one could use the data for analysis.  
> **username_2**: @AlejandroRuiz I am little bit confused by what exactly you would like to find. The text document you linked does not have everything, but when I look at the handbook I linked in my answer it covers excruciating detail. It even covers how exactly raw data are collected and how exactly the CPI is constructed. The handbook literary goes even into detail on areas where the sampling is done and how pries are recorded/imputed in different sectors. If you are asking for some further analysis once you already have CPI, that of course wont be in the handbook  
> **username_2**: - which is just a guide to how data are build and has nothing to say how they should be further analyzed, but the latter depends specifically on your research and if this is what you want then your current Q does not reflect that.  
> **username_0**: My main question would be: Where can I find the raw data and the relative weights? My goal is to build some aggregate categories of my own.  
> **username_2**: @AlejandroRuiz oh well I wish you would say this in your original Q because that is quite a different question. However, the weights are in that handbook chapter 17 that I linked. The weights are in text they won’t be published as separate data. For example at pp 30 you have list of different weights for CPI-U. When it comes to raw data on specific areas that won’t be in the handbook of course, for that I think the R command will be useful as it allows you to scrape the data but to just provide direct link I would have to some further search (it was not clear you want this form the original Q)  
> **username_0**: Oh okay. I will then look more into the blscrapeR. Also, in regard to the relative weights, I meant the relative importance of components. I saw in the Handbook they are in Appendix 9. However, I did notice that the ones reported in the Handbook are slightly different from the ones in the CPI-U excel document that was published for September 2020. Also, I already change my original Q. Thanks for that.  

---

