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
Chamara Anuranga <[email protected]>
To
[email protected]
Subject
Re: st: Generation of Variables with reference to values in the same column
Date
Fri, 14 Sep 2012 12:10:28 +0530
Hi,
you can store the change using log value
gen change1=var1-var1[_n-1]
gen change2=var1-var1[_n+1]
Also you can calculate the change by group using bys option.
bys groupvar: gen change1=var1-var1[_n-1]
Chamara
On Fri, Sep 14, 2012 at 11:30 AM, Nick Cox <[email protected]> wrote:
> 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/
*
* 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/