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   Chamara Anuranga <kcanuranga@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <njcoxstata@gmail.com> 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 <statalist1@gmail.com>
> 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/


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