0
を前年のテストのスコアを作成するときに、私はこのようになりますと、私が作成しようとしている変数がMath_score
あるいくつかのデータを持っているコードの削減:反対の対象に
Year ID Subject Score Math_score
2011 1 m 30 30
2011 1 r 40 30
2012 2 m 50 50
2012 2 r 60 50
私の同僚と私は出ていますこれを行うには、次の方法:
bys id year: egen math = mode(score) if subject=="m"
by id year: egen math_score = max(math)
または:
bys id year: gen math_score = score[_n-1]
replace math_score = math_score[_n+1] if math_score==.
Ultimこれは、被験者とその反対の被験者の前年度のテストスコアを示すために、遅れた変数で使用されます。より少ないコードでこれを行うもっとエレガントな方法があると確信していますが、私たちはそれを考えることはできません。何か案は?