Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: moving averages question


From   Rufus Peabody <rufus.peabody@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: moving averages question
Date   Sun, 24 Aug 2008 04:16:50 -0700

I'm trying to create a moving average for a number of variables within a panel. I set the data as time series (tsset panelvar timevar) and used the appropriate -tssmooth ma- syntax. However, I got the error message:

_TS_p_delta_getnumb(): 3499 strtoreal() not found
_TS_p_delta_increment(): - function returned error
_TS_p_delta(): - function returned error
<istmt>: - function returned error
r(3499);

I then tried using the lag function (L. ) as follows in hopes of creating a lag for each day.

foreach v of local var {
tsset panelvar timevar
egen lweek_`v'=mean(L(1/7).`v'), by(panelvar datevar)
}

Output was:

panel variable: panelvar (unbalanced)
time variable: timevar, 161 to 1459
delta: 1 unit
Unknown function L()
r(133);

I should note that I used the tssmooth fcn. within a loop like the one above.

Anybody have any idea what I can do for this? Any help is appreciated.

I ended up doing the following, which I don't think is the easiest way to do this:

foreach v of local var {
tsset panelvar timevar
gen lweek_`v'=L1.`v'+L2.`v'+L3.`v'+L4.`v'+L5.`v'+L6.`v'+L7.`v' if L7.year==year
}


I also had a question about fitting a decay function using panel data for a specific variable which I posted previously twice but nobody ever responded. If that isn't possible or nobody knows how, I completely understand, but if I'm doing something wrong and offending people on the list, please let me know!

Thanks very much,

Rufus
*
* 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