Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: rolling and ts operators

From   Nuno Soares <>
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
	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,

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index