Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: using matrix expression


From   David Kantor <kantor.d@att.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: using matrix expression
Date   Tue, 03 Oct 2006 12:00:06 -0400

At 03:42 PM 10/2/2006, Sayda G Wentworth wrote:
Hi,
I have thousands of observations (individuals) and earnings data for each of them covering 53 years, in the form earnings1951, earnings1952,...,earnings2003.
I'd like to convert those nominal earnings to 2003 dollars.
I have a price index variable called cpi with 53 values * for each of the 53 years, where the first value is equal to cpi1951/cpi2003, the second is cpi1952/cpi2003 etc. The remaing values are missing (because I copied a column created in excel).
I'm trying to write a mini program that'll compute real earnings (in 2003 dollars) for all individuals the following way:

gen j=0
. program define real
1. local i=1951
2. while (`i'<=2003) {
3. replace j=`i'-1950
4. gen realearnings`i'=earnings`i'/cpi[`j',1]
5. local i=`i'+1
6. }
7. end

But the results I get are incorrect. To check why, I try:

gen realearnings1951=earnings1951/cpi[1,1]

and get an error message saying:

cpi not found
r(111);

What is the correct way of doing this computation?
Thanks.

Nick Cox has already answered this, but I would add that you have the choice of loading the CPI values in a matrix or in data, but you need to decide that clearly, and then code accordingly.

But the real reason I am writing is that I have created a cpi-adjustment program that does what you want (using a matrix). It also has the capability of specifying the "from" year as well as the "to" year, along with a few other options. The disadvantage in your case, is that it only goes back to 1967, though that could be fixed. It also allows several types of cpi's in addition to the general one -- food, shelter, housing, etc.. Another nice feature is that it allows the "from" year to be a variable.

I could let you have it, and if other users show interest, I might publish it; I just need to write a .hlp file and possibly extend the year range.

--David
P.S., in case some of you are not familiar with it, the cpi is the (U.S.) Consumer Price Index, from the Bureau of Labor Statistics.

*
* 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/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index