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
Christopher Baum <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Generation of Variables with reference to values in the same column
Date
Sat, 15 Sep 2012 08:42:11 +0000
<>
On Sep 14, 2012, at 7:33 AM, Arnold wrote:
> 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?
(I presume that you have tsset the data)
g lcpi = log(CPI)
g inflation = D.lcpi
Kit
PS> What is "Excel"?
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
*
* 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/