Re: [程式] STATA 資料處理的問題

看板Statistics作者 (一個人)時間8年前 (2015/07/18 17:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
可能有更簡單的辦法,不過試試這個吧。 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://www.ptt.cc/bbs/Statistics/M.1437210413.A.EB4.html
文章代碼(AID): #1LgXSjwq (Statistics)
文章代碼(AID): #1LgXSjwq (Statistics)