SHAZAM Questions and Answers (Q&A) - RSS feedhttp://community.econometrics.com/questions/SHAZAM Econometrics, Statistics and Analytics Communityen<font color="white">Copyright <b>SHAZAM Analytics, 2018</b></font>Wed, 27 Jun 2012 01:55:56 +0000Generating - transformation of a time series variablehttp://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/Hi all,
I have the following problem: I want to generate a new time series variable which measures the **accumulated** (the sum) of an existing variable "X". The new variable is a sum inside a given **moving** time **window** with a **constant** width of let say 40 years. More precisely - the new variable is generating in the following way: Let the sum of the first 40 observations from time point t = 1 to t = 40 represents the *first* observation, the *second* observation is the sum of the observations from t = 2 to time point t = 41, the *third* observation is the sum of observations from t = 3 to t = 42 etc. The constant time window of 40 years is moving by one step at the time. It's like a moving average but **WITHOUT** dividing by the number of observations. I hope one of you Shazam experts could look into the problem - it would be of great help.
Regards,
P.Tue, 26 Jun 2012 05:02:16 +0000http://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/Answer by ken for <p>Hi all,</p>
<p>I have the following problem: I want to generate a new time series variable which measures the <strong>accumulated</strong> (the sum) of an existing variable "X". The new variable is a sum inside a given <strong>moving</strong> time <strong>window</strong> with a <strong>constant</strong> width of let say 40 years. More precisely - the new variable is generating in the following way: Let the sum of the first 40 observations from time point t = 1 to t = 40 represents the <em>first</em> observation, the <em>second</em> observation is the sum of the observations from t = 2 to time point t = 41, the <em>third</em> observation is the sum of observations from t = 3 to t = 42 etc. The constant time window of 40 years is moving by one step at the time. It's like a moving average but <strong>WITHOUT</strong> dividing by the number of observations. I hope one of you Shazam experts could look into the problem - it would be of great help.</p>
<p>Regards,
P.</p>
http://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/?answer=273#post-id-273 * Program to create moving sums of a variable
sample 1 10
* generate some simple data to make it easy to check
genr x=time(0)
* initialize the moving sum variable
genr msum=0
* add up the number of lags (this example does current plus last 2)
* if you dont like output, you can SET NODOECHO after it works
do #=0,2
genr msum=msum+lag(x,#)
endo
* print it out, the first few observation will be garbage
print x msum
stopTue, 26 Jun 2012 16:45:42 +0000http://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/?answer=273#post-id-273Comment by Pantera for <pre><code>* Program to create moving sums of a variable
sample 1 10
* generate some simple data to make it easy to check
genr x=time(0)
* initialize the moving sum variable
genr msum=0
* add up the number of lags (this example does current plus last 2)
* if you dont like output, you can SET NODOECHO after it works
do #=0,2
genr msum=msum+lag(x,#)
endo
* print it out, the first few observation will be garbage
print x msum
stop
</code></pre>
http://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/?comment=361#post-id-361Ken - Thanks a lot for your help - it function perfectly! :)Wed, 27 Jun 2012 01:55:56 +0000http://community.econometrics.com/question/242/generating-transformation-of-a-time-series-variable/?comment=361#post-id-361