如何使用gen
或egen
命令生成Stata中不同年份的观察值之间的百分比变化?例如,我有1990年到2010年的观察结果,每个都有不同的支出价值,我试图用1990-1991,1991-1992等的百分比变化产生一个新的观察结果。
答案 0 :(得分:3)
//这是另一个增长衡量标准的例子:
clear
set obs 100
gen year = _n + 1959
gen expenditure = _n^(1/3) + runiform()
line expenditure year, yti("Synthetic data example")
// From Statalist:
bys year: g expendituregrowth=100*(expenditure[_n]-expenditure[_n-1])/expenditure[_n-1]
//还:
gen expenditure_gr = (expenditure/expenditure[_n-1] - 1)*100 // growth rate for expenditure
gen expenditure_bl = 100*expenditure/expenditure[1] // baseline growth rate for expenditure; base 100 = 1960
line expenditure_gr year, yti("Growth rate")
line expenditure_bl year, yti("Growth rate (base 100 = 1960)")
// expenditure_gr
的计算是我认为你正在寻找的。 p>
//如果您的数据格式正确,请使用带有时间序列的Stata并轻松获得增长率:
tsset year, delta(1)
cap drop expenditure_gr
gen expenditure_gr = D.expenditure / 100*L.expenditure