Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: calculating the mean of x til X[_n+t]


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: calculating the mean of x til X[_n+t]
Date   Thu, 27 Nov 2008 20:42:35 -0500

< >
Linn said

I have problems in generating a variable I
need in my calculations:
I need to generate a variable X2 as a mean
of the variable X1 and the next
x1[_n+1] til X1[_n+8]. Thus the value of X2
is going to change for each observation in
the samlpe
Can this be done using egen?
As this variable X2 will be changed it is
 not very practical to calculate the mean
by typing X2=(X1 + X1[_n+1] etc..)/n.


tssmooth ma x2 = x1, window(0 1 8)

You could apply this with an -if- condition if you only want to update a certain part of the x2 sequence. If that is the case, the easiest thing would be to use a -tempvar- to hold the smoothed fragment, and then move the resulting observations back into the x2 series.

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.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   |   What's new   |   Site index