Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: rolling and ts operators


From   Nuno Soares <ndsoares@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: rolling and ts operators
Date   Mon, 24 Oct 2011 13:52:06 +0100

Hi everyone,

I'm having a problem with the - rolling - command the the use of time
series operators. I need to estimate a model for several firms (id)
and several years in a rolling regression with a window of at least 7
years and the recursive option.

The code I'm using is the following:

use "test.dta", clear
keep if id==2 * just a test firm
xtset id year
gen end=year
tempfile stats
levelsof id, local(ids)
foreach id of local ids {
	cap rolling , window(7) recursive saving(`stats', replace): reg
depvar indepvar1 l.indepvar1 f.indepvar1 indepvar2 indepvar3 if
id==`id'
	cap merge 1:1 id end using "`stats'", update replace
	cap drop _merge
}
sort id year
xtset id year
* calculating error term *
gen e=depvar-(_b_cons+_b_indepvar1*indepvar1+_b_stat2*l.indepvar1+_b_stat3*f.indepvar1+_b_indepvar2*indepvar2+_b_indepvar3*indepvar3)


Given the l. operator I was expecting that Stata would use 8
observations given that the first l.indepvar1 would be missing an thus
it wouldn't have enough observations to estimate the first model with
only six observations (while the window option is set at 7,
restricting the sample to the first 7 observations would lead to have
only 6 eligible observations, and thus not enough data to estimate the
regression). This however isn't happening with Stata reporting
estimated coefficient starting from the first 7 observations. Any
clues on why this is happening?

Best wishes,

Nuno
*
*   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   |   Site index