簡體   English   中英

在Stata中循環

[英]Looping in Stata

我正在嘗試對每個ID進行回歸。 我還需要按特定ID逐年將其范圍縮小到回歸。

tsset id date

forvalues i=1/3 {

eststo:quietly arch rtr mon tue wed thu fri lag1r lag2r if id == `i' & Year==`i', noconstant arch(1/1) tarch(1/1) garch(1/1) distribution(t)
}


esttab using d:\Return_reg.csv, append cells("b(fmt(8))") 

它返回以下錯誤:

沒有意見。

我懷疑是因為每個ID的年份不同。

我需要如何改進代碼才能實現自己的目標?

如評論中所述,這是一個錯字(除非您的year變量實際上僅取值1、2和3)。 此外,tsset僅接受一個參數。 如果要聲明面板數據,則需要使用xtset。 請嘗試以下操作:

xtset id date
levelsof Year, local(years) //create list containing all values of year
levelsof id, local(ids)     //create list containing all values of id
foreach id in `ids'{
    foreach yr in `years'{
        eststo: quietly arch rtr mon tue wed thu fri lag1r lag2r if id == `id' & Year==`yr', noconstant arch(1/1) tarch(1/1) garch(1/1) distribution(t)
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM