Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Generation of Variables with reference to values in the same column


From   Arnold Patrick Behrer <statalist1@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Generation of Variables with reference to values in the same column
Date   Thu, 13 Sep 2012 23:40:00 -0600

Hello,

Is there an easy way to generate a variable that measures the change in a given column? Specifically I want to create a variable that is equal to:

 log(CPIt) - log(CPIt-1)

I tried using the following code:

generate log(CPI[2])-log(CPI[1])

But that simply filled the column with the results of the function using the values of CPI in rows 1 & 2. Short of doing that manually for each row, is there a way to write something like:

generate log(CPI[X]) - log(CPI[X-1])

That just goes down the column and calculates for each new row? Or should I just export into Excel?

Best,

Patrick


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index