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]

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


From   Christopher Baum <kit.baum@bc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
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/


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