Re: [問題] stata 資料處理一問
※ 引述《letoff (最溫暖的陽光)》之銘言:
: 請問一下 stata 中有無指令可以由v1產出v2
: v2 為 v1 之累加,可是碰到0,即設為1,且以下再從1重新累加, 感謝
: v1 v2
: 1 1
: 1 2
: 1 3
: 1 4
: 1 5
: 0 1
: 1 1
: 1 2
: 0 1
: 1 1
: 1 2
: 1 3
: 1 4
: 0 1
If you can add in one observation at the beginning like the following
example, the syntax should give you what you want.
clear
input v1 v2
0 0
1 1
1 2
1 3
1 4
1 5
0 1
1 1
1 2
0 1
1 1
1 2
1 3
1 4
0 1
end
gen z=0
replace z=cond(v1[_n-1]==0, 1, 0)
replace z=cond(v1!=0, z[_n-1]+1, 0)
replace z=1 if v1==0
list
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 128.101.79.137
→
05/30 23:09, , 1F
05/30 23:09, 1F
→
05/30 23:09, , 2F
05/30 23:09, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):