Statalist


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

st: AW: It's too time-consuming for a simple cumulation


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: It's too time-consuming for a simple cumulation
Date   Thu, 3 Dec 2009 09:10:06 +0100

<> 

For qualifiers with regard to time series, the functions in

*************
help time_series_functions
*************

come in handy.

I do not quite see how you process the result from your -count- operation
further. In its current form, it would simply give you the result on screen
every time through the loop. If that is what you want, leave it...

The -sum()- function gives you a running sum, make sure thos is what you
want for your "temp", otherwise use -egen, total()-.

It would be helpful if you could post a small example dataset.


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Christina Lu
Gesendet: Donnerstag, 3. Dezember 2009 08:01
An: [email protected]
Betreff: st: It's too time-consuming for a simple cumulation

I have the stocks' daily turn-over ratio, and I want to know that, on each 
day for each stock, the sum of its daily turn-over ratio for the 12 monthes 
before that day.

I used loop like this:

gen temp=sum(turn_over_ratio)
sort stkcd fye             
forvalue h=1(1)1315    {
                                   #h indicate the stock code
       forvalue i=13118(1)18079   {
                                   #i indicate the date, formed in %td
           count if fye>=`i'-365 &fye<`i' & n==`h'
           replace To_ratio=temp[_n-1]-temp[_n-r(N)-1] if fye==`i' & n==`h'
           }           
}

This would do the trick, but it took me forever to obtain the result. So I 
would like to ask, is there any approach simpler & much quicker to do the 
cumulation?

Thx~
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index