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: generate the level series from the growth rate series


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: generate the level series from the growth rate series
Date   Fri, 4 Jan 2013 11:36:33 +0000

In your code -change- is ambiguous as between -change2- and -change3-.

Evidently, levels can be reconstructed from changes given an initial value:

. sysuse sp500
(S&P 500)

. gen close2 = close[1] + sum(change)

. assert close == close2

If in your real data you have _percent_ changes (assuming equally
spaced times and no missings or omissions)

gen double level = 100
replace level = level[_n-1] * (1 + pcchange / 100) if _n > 1

This generalises to panels:

bysort panelid (time) : replace level = level[_n-1] * (1 + pcchange /
100) if _n > 1

Nick

Patrick Toche <[email protected]> wrote:

(2)

> I will take 100 as a starting value to create an index.
>
> In the sp500 example, I used the value from the dataset so I could quickly
> check that my calculations were correct, hence:
>
>
>   replace close2 = 1283.27 in 1
>
> where 1283.27 is the value of "close[_n]" in the dataset.

(1)

>>> This must be a very simple question...
>>>
>>> I have data for percentage changes and would like to reconstruct the
>>> levels of the variables.
>>>
>>> Taking the sp500 dataset, I show below that I can generate the one-period
>>> difference series for the level variable "close", with and without tsset.
>>> Then I try to reverse-engineer to recover the level variable "close" from
>>> the difference series named "change", but I get stuck.
>>>
>>> sysuse sp500
>>> gen change2 = close-close[_n-1] /// method without tsset
>>>
>>> gen t=_n
>>> tsset t
>>> gen change3 = close-L.close /// method with tsset
>>>
>>> gen close2 = .
>>> replace close2 = 1283.27 in 1 /// assign the first value
>>> replace close2 = close2[_n-1]+change /// try to recover the level
>>>
>>> This last step fails.
>>>
>>> I'd appreciate your help very much.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index