Stata四分之一循环 [英] Stata year-quarter for loop
本文介绍了Stata四分之一循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foreach yridx numlist 2000/2012 {
forvalues qtridx = 1/4 {
如果year <= yridx和qtr < = qtridx
predict
}
}
解决方案
听起来好像在季度日期上工作要容易得多。这是几种方法之一。
gen qdate = yq(year,qtridx)
forval m =`= yq(2000,1)'/ `= yq(2012,4)'{
如果qdate< ='m'则退步YX
预测<无论>
}
I am trying to create a loop in Stata. I run a model for the data <= year and <= 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.
foreach yridx of numlist 2000/2012 {
forvalues qtridx = 1/4 {
regress Y X if year <= yridx and qtr <= qtridx
predict
}
}
解决方案
It sounds as if it would be much easier to work in terms of quarterly dates. Here is one of several ways to do it.
gen qdate = yq(year, qtridx)
forval m = `=yq(2000,1)'/`=yq(2012, 4)' {
regress Y X if qdate <= `m'
predict <whatever>
}
这篇关于Stata四分之一循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文