Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Generation of Variables with reference to values in the same column
Date   Fri, 14 Sep 2012 07:00:37 +0100

None of your commands is legal, but it is possible to guess at what you did. As you evidently have time series data you should read up about -tsset- and time series operators.

Nick

On 14 Sep 2012, at 06:40, Arnold Patrick Behrer <[email protected]> wrote:

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?
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index