寻找累积积

时间:2019-12-30 11:09:25

标签: stata

我的面板数据如下:

:tags="some json" :previous-tags="some json"

如何为input str1 id float date byte month float sales "A" 480 1 8.160477 "A" 481 2 6.704718 "A" 482 3 4.867198 "A" 483 4 11.413195 "A" 484 5 5.267023 "A" 485 6 4.6908617 "A" 486 7 .7432101 "A" 487 8 9.340007 "A" 488 9 7.996202 "A" 489 10 6.167258 "A" 490 11 5.870387 "A" 491 12 2.7423105 end sales3个月的6的累积积生成三个变量?

R 中,使用9功能很容易。但是,我还没有在Stata中弄清楚该怎么做。

1 个答案:

答案 0 :(得分:0)

以下对我有用:

encode id, generate(id2)
xtset id2 date

generate product = .
bysort id2 (date): replace product = cond(_n == 1, sales, sales * L.product)

forvalues i = 3(3)9 {
    bysort id2 (date): generate wanted`i' = cond(_n == `i', product, product / L`i'.product) - 1
}