【发布时间】:2014-06-11 17:21:59
【问题描述】:
我在 Stata 中有一个面板数据集(国家年)。例如,我有许多国家在 1990、1991、..2010 年的 GDP。
我想定义一个变量“2006 年的 GDP”,它存在于所有年份并包含 2006 年的 GDP 值。
我现在这样做的方式可行,但有点笨拙,所以我希望有人会有更好的主意:
qui gen gdp2006=.
replace gdp2006=gdp if year==2006
forval t=2007/2010 {
sort country year
qui replace gdp2006=gdp2006[_n-1] if year==`t'&country[_n-1]==country
}
forval t=2005(-1)1990 {
sort country year
qui replace gdp2006=gdp2006[_n+1] if year==`t'&country[_n+1]==country
}
谢谢!
【问题讨论】: