作者porfu (一个人)
看板Statistics
标题Re: [问题] STATA 资料处理的问题
时间Sat Jul 18 17:06:50 2015
可能有更简单的办法,不过试试这个吧。
clear
set more off
input code year1996 year1997 year1998 year1999 year2000
8401 0.32 0.45 0 0.75 0
8402 0 0.35 0.24 0.45 0
8403 0.45 0.33 0.45 0.22 0.23
8404 0 0 0 0 0.33
8405 0 0.28 0 0.32 0.29
end
list
reshape long year, i(code) j(count)
gen dropout=0
bysort code: replace dropout=1 if (year[_n-1]!=0 & year[_n]==0) // mark
dropout year
bysort code: replace dropout=0 if dropout==1 & _n==1 // correct for the first
year
bysort code: replace dropout=1 if dropout[_n-1]==1 // mark all years
following dropout year
replace year=0 if dropout==1
drop dropout
reshape wide
list
※ 引述《linhoho (庆应魂)》之铭言:
: 各位前辈好
: 我正在利用STATA处理资料,但有不懂处理的地方跟commamd请大家多多指教
: 我有一系列的资料,举例如下
: code year1996 year1997 year1998 year1999 year2000
: 8401 0.32 0.45 0 0.75 0
: 8402 0 0.35 0.24 0.45 0
: 8403 0.45 0.33 0.45 0.22 0.23
: 8404 0 0 0 0 0.33
: 8405 0 0.28 0 0.32 0.29
: 想要转变成
: code year1996 year1997 year1998 year1999 year2000
: 8401 0.32 0.45 0 0 0
: 8402 0 0.35 0.24 0.45 0
: 8403 0.45 0.33 0.45 0.22 0.23
: 8404 0 0 0 0 0.33
: 8405 0 0.28 0 0 0
: 如上 第一组资料跟第二组的资料差别就是有些code的资料是0之後又重新有资料
: 如code 8401和8405,但现在只想留第一次的资料
: 这部分想了很多的code都不知道如何解决,希望前辈们能帮忙或提供一些暗示
: 感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 75.72.185.250
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1437210413.A.EB4.html