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]

st: Extracting results from -rolling- in one file per window


From   Micha Schildmann <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Extracting results from -rolling- in one file per window
Date   Thu, 13 Mar 2014 16:52:50 +0000 (GMT)

Dear statalist,

I am currently building a sentiment index and need to do the following analysis.

- regress a number of time series (weekly google search queries) on a market return for a window expanding by 1 month per loop
- rank the results of every window by t-statistics and keep only the top 30 queries
- use the average of the value of the 30 queries to create the sentiment for the following month.

For anyone interested in the excact procedure an example is at the bottom of this mail. I am mentioning this as it might be necessary to understand what I need to achieve, but it is also possible that the solution to my issue is within a general approach.

So currently I am struggling to extract the results of each window to a seperate file. I want to create a single file per window as in the next step I want to try to capture the 30 queries within each file and use each list to create the sentiment index in the mainfile (details in the example below the code).

My code looks like this (created with the help of two statalist-users, thanks for that!)

capture program drop rollingwindow
program rollingwindow


global tflist ""

foreach var of varlist *SA{
reg Mid `var'
tempfile tfcur
parmest, idstr("`var'") saving(`"`tfcur'"', replace) flis(tflist) 
}
preserve
clear
append using $tflist
sencode idstr, gene(xvar)
lab var xvar "X-variable"
keybygen xvar, gene(parmseq)
drop if parmseq==2
egen rank = rank (-t)
drop if rank>30
save test, replace
restore
end


rolling, window(4) stepsize (4) recursive: rollingwindow

In generell this approach works fine, the only flaw is that it does not generate a file per window but obviously just replaces the most recent with the current window (-save test, replace- is basically a placeholder to check if the comand itself works or not). Is there a counting mechanism within the -rolling- comand that indicates which window is currently executed? This I could use to create a macro which in turn would be used as the name of the file. 

Example of the Approach:

Lets say I need to construct the sentiment for January 2010. In this case I would regress the market return on the search queries over the period (start date) to December 2009. After ranking by t-statistic and dropping the queries higher than rank 30 I would have the queries which constitute my sentiment for January 2010. To generate the weekly value of the sentiment, I would average the value of the respective queries for the respective week 1,2,3 and 4 in January 2010. For February 2011 I would then do the same procedure again, only difference is that the window now includes January as well.

Any help is much appreciated!

Best regards
Micha

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