- // https://www.statalist.org/forums/forum/general-stata-discussion/general/1474659-construct-a-complete-list-of-index-components-over-different-periods
- // https://bbs.pinggu.org/thread-6816710-1-1.html
- clear
- input str22 Indexcd str13 Chgsmp01 str19(Chgsmp02 Chgsmp03) str13 Chgsmp04
- "000016" "2004-01-02" "600000" "浦发银行" "1"
- "000016" "2004-01-02" "600004" "白云机场" "1"
- "000016" "2004-01-02" "600006" "东风汽车" "1"
- "000016" "2004-01-02" "600008" "首创股份" "1"
- "000016" "2004-01-02" "600009" "上海机场" "1"
- "000016" "2004-01-02" "600011" "华能国际" "1"
- "000016" "2004-01-02" "600015" "华夏银行" "1"
- "000016" "2004-01-02" "600016" "民生银行" "1"
- "000016" "2004-01-02" "600018" "上港集箱" "1"
- "000016" "2004-01-02" "600019" "宝钢股份" "1"
- "000016" "2004-01-02" "600026" "中海发展" "1"
- "000016" "2004-01-02" "600028" "中国石化" "1"
- "000016" "2004-01-02" "600029" "南方航空" "1"
- "000016" "2004-01-02" "600030" "中信证券" "1"
- "000016" "2004-01-02" "600033" "福建高速" "1"
- "000016" "2004-01-02" "600036" "招商银行" "1"
- "000016" "2004-01-02" "600038" "哈飞股份" "1"
- "000016" "2004-01-02" "600050" "中国联通" "1"
- "000016" "2004-01-02" "600098" "广州控股" "1"
- "000016" "2004-01-02" "600100" "清华同方" "1"
- "000016" "2004-01-02" "600104" "上海汽车" "1"
- "000016" "2004-01-02" "600171" "上海贝岭" "1"
- "000016" "2004-01-02" "600221" "海南航空" "1"
- "000016" "2004-01-02" "600350" "山东基建" "1"
- "000016" "2004-01-02" "600569" "安阳钢铁" "1"
- "000016" "2004-01-02" "600591" "上海航空" "1"
- "000016" "2004-01-02" "600597" "光明乳业" "1"
- "000016" "2004-01-02" "600601" "方正科技" "1"
- "000016" "2004-01-02" "600602" "广电电子" "1"
- "000016" "2004-01-02" "600609" "金杯汽车" "1"
- "000016" "2004-01-02" "600637" "广电信息" "1"
- "000016" "2004-01-02" "600642" "申能股份" "1"
- "000016" "2004-01-02" "600643" "爱建股份" "1"
- "000016" "2004-01-02" "600649" "原水股份" "1"
- "000016" "2004-01-02" "600652" "爱使股份" "1"
- "000016" "2004-01-02" "600664" "哈药集团" "1"
- "000016" "2004-01-02" "600705" "北亚集团" "1"
- "000016" "2004-01-02" "600717" "天津港" "1"
- "000016" "2004-01-02" "600795" "国电电力" "1"
- "000016" "2004-01-02" "600805" "悦达投资" "1"
- "000016" "2004-01-02" "600808" "马钢股份" "1"
- "000016" "2004-01-02" "600811" "东方集团" "1"
- "000016" "2004-01-02" "600812" "华北制药" "1"
- "000016" "2004-01-02" "600832" "东方明珠" "1"
- "000016" "2004-01-02" "600839" "四川长虹" "1"
- "000016" "2004-01-02" "600863" "内蒙华电" "1"
- "000016" "2004-01-02" "600887" "伊利股份" "1"
- "000016" "2004-01-02" "600895" "张江高科" "1"
- "000016" "2004-01-02" "600900" "长江电力" "1"
- "000016" "2004-01-02" "600688" "上海石化" "1"
- "000016" "2004-07-01" "600002" "齐鲁石化" "1"
- "000016" "2004-07-01" "600005" "武钢股份" "1"
- "000016" "2004-07-01" "600020" "中原高速" "1"
- "000016" "2004-07-01" "600021" "上海电力" "1"
- "000016" "2004-07-01" "600038" "哈飞股份" "2"
- "000016" "2004-07-01" "600098" "广州控股" "2"
- "000016" "2004-07-01" "600205" "山东铝业" "1"
- "000016" "2004-07-01" "600221" "海南航空" "2"
- "000016" "2004-07-01" "600597" "光明乳业" "2"
- "000016" "2004-07-01" "600863" "内蒙华电" "2"
- "000016" "2005-01-03" "600210" "紫江企业" "1"
- "000016" "2005-01-03" "600500" "中化国际" "1"
- "000016" "2005-01-03" "600637" "广电信息" "2"
- "000016" "2005-01-03" "600652" "爱使股份" "2"
- "000016" "2005-01-03" "600660" "福耀玻璃" "1"
- "000016" "2005-01-03" "600664" "哈药集团" "2"
- "000016" "2005-01-03" "600780" "通宝能源" "1"
- "000016" "2005-01-03" "600805" "悦达投资" "2"
- "000016" "2005-01-03" "600811" "东方集团" "2"
- "000016" "2005-01-03" "600879" "火箭股份" "1"
- "000016" "2005-07-01" "600006" "东风汽车" "2"
- "000016" "2005-07-01" "600008" "首创股份" "2"
- "000016" "2005-07-01" "600098" "广州控股" "1"
- "000016" "2005-07-01" "600188" "兖州煤业" "1"
- "000016" "2005-07-01" "600320" "振华港机" "1"
- "000016" "2005-07-01" "600350" "山东基建" "2"
- "000016" "2005-07-01" "600519" "贵州茅台" "1"
- "000016" "2005-07-01" "600609" "金杯汽车" "2"
- "000016" "2005-07-01" "600705" "北亚集团" "2"
- "000016" "2005-07-01" "600797" "浙大网新" "1"
- "000016" "2006-01-04" "600021" "上海电力" "2"
- "000016" "2006-01-04" "600027" "华电国际" "1"
- "000016" "2006-01-04" "600058" "五矿发展" "1"
- "000016" "2006-01-04" "600177" "雅戈尔" "1"
- "000016" "2006-01-04" "600309" "烟台万华" "1"
- "000016" "2006-01-04" "600428" "中远航运" "1"
- "000016" "2006-01-04" "600569" "安阳钢铁" "2"
- "000016" "2006-01-04" "600591" "上海航空" "2"
- "000016" "2006-01-04" "600643" "爱建股份" "2"
- "000016" "2006-01-04" "600812" "华北制药" "2"
- "000016" "2006-04-24" "600002" "齐鲁石化" "2"
- "000016" "2006-04-24" "600269" "赣粤高速" "1"
- end
- * dataex
- // Clyde Schechter
- // SAVE A SEPARATE FILE FOR EACH CHGMSP01
- capture program drop one_date
- program define one_date
- local date = Chgsmp01[1]
- save `date', replace
- exit
- end
- runby one_date, by(Chgsmp01) status
- // NOW UPDATE EACH FILE ONE DATE AT A TIME
- levelsof Chgsmp01, local(dates)
- local n_files: word count `dates'
- forvalues i = 2/`n_files' {
- local change_file: word `i' of `dates'
- local last_file: word `=`i'-1' of `dates'
- use `last_file', clear
- append using `change_file'
- by Chgsmp02 (Chgsmp04), sort: assert (_N == 2) == (Chgsmp04[_N] == "2")
- by Chgsmp02 (Chgsmp04): drop if _N == 2
- replace Chgsmp01 = `"`change_file'"'
- assert _N == 50
- save `"`change_file'"', replace
- }
- // NOW APPEND THEM ALL
- clear
- foreach d of local dates {
- append using `d'
- }
- assert _N == 50*`n_files' & Chgsmp04 == "1"