Stata year-quarter for loop
<p>I am trying to create a loop in Stata. I run a model for the data &lt;= year and &lt;= quarter. Then predict one year look ahead. That is the model is run all time points upto the loop, while the prediction happens in the next quarter out of sample. So my question is how do I handle so that when yridx = 2000, and qtr = 4, the next quarter inside the loop look ahead would be year = 2005, and year = 1.</p>

<pre><code>foreach yridx of numlist 2000/2012 {
forvalues qtridx = 1/4 {

regress Y X if year &lt;= yridx and qtr &lt;= qtridx
predict
}
}
</code></pre>