1
我有一些面板數據。對於這些數據,我想計算每個小組每年的差異,如果小組在兩年內都有觀察結果的話。計算面板差異
這裏的數據:
> head(statistics)
persnr year NOBS value
1: 61961225 1993 1 0.5777598
2: 62037645 1993 1 0.5777598
3: 62181514 1993 1 0.5777598
4: 62499451 1993 1 0.5777598
5: 62649247 1993 1 0.5777598
6: 62744472 1993 1 0.5777598
哪裏persnr
是面板的GROUPID。而我目前的做法是沿着
dataTable = data.table(cast(statistics, persnr ~ year, value='totalWage'))
# y is the second year. Iterate over that
for (y in tail(unique(statistics[, jahr]), n=-1)):
# get the first year
x <- y - 1
dataTable[!is.na(`x`) & !is.na(`y`), `y`-`x`]
}
不過線的東西,我不能使用\
x``方案來訪問列。什麼是解決這個問題的「R-ISH」方法?
你不在'data.table'中使用'order'。無論是使用'setkey'還是'setorder' – 2014-11-02 08:59:36
@DavidArenburg,你都可以,當你不想改變原始data.table的順序。 – Arun 2014-11-02 13:01:03