https://www.lianxh.cn/news/2916ae8363459.html https://www.xiaohongshu.com/explore/62fc6f8c00000000140361fa use cfps2018famecon_202101,clear keep fid18 fid16 provcd18 countyid18 cid18 urban18 /// resp1pid fk1l ft200 fincome1_per total_asset familysize18 sum sort urban18 label list label list urban18 . label list urban18 // urban18: // -10 无法判断 // -9 缺失 // -8 不适用 // -2 拒绝回答 // -1 不知道 // 0 乡村 // 1 城镇 for var _all: replace X =. if inlist(X, -10, -9, -8, -2, -1) // . for var _all: replace X =. if inlist(X, -10, -9, -8, -2, -1) // // -> replace fid18 =. if inlist(fid18, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace fid16 =. if inlist(fid16, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace provcd18 =. if inlist(provcd18, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace countyid18 =. if inlist(countyid18, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace cid18 =. if inlist(cid18, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace urban18 =. if inlist(urban18, -10, -9, -8, -2, -1) // (220 real changes made, 220 to missing) // // -> replace resp1pid =. if inlist(resp1pid, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace fk1l =. if inlist(fk1l, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace ft200 =. if inlist(ft200, -10, -9, -8, -2, -1) // (55 real changes made, 55 to missing) // // -> replace fincome1_per =. if inlist(fincome1_per, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace total_asset =. if inlist(total_asset, -10, -9, -8, -2, -1) // (0 real changes made) // // -> replace familysize18 =. if inlist(familysize18, -10, -9, -8, -2, -1) // (0 real changes made) . *- 重新赋值 . recode fk1l (1 = 1 "是")(5 = 0 "否"), gen(agri) // // . . recode fk1l (1 = 1 "是")(5 = 0 "否"), gen(agri) // (7966 differences between fk1l and agri) . recode ft200 (1 = 1 "是")(5 = 0 "否"), gen(finp) . drop fk1l ft200 . save "$temp_data/family_2018.dta", replace . use cfps2018person_202012.dta, clear . keep pid fid18 fid16 provcd18 countyid18 cid18 urban18 gender age /// qa301 qea0 qp605_s_* cfps2018edu . for var _all: replace X =. if inlist(X, -10, -9, -8, -2, -1) . recode qa301 (1 = 1 "农业户口")(3 = 0 "非农户口")(5 79 =.), gen(hukou) . recode qea0 (2 3 = 1 "有配偶")(1 4 5 = 0 "无配偶"), gen(spouse) . recode cfps2018edu /// (1 = 0 "文盲/半文盲") /// (2 = 1 "小学") /// (3 = 2 "初中") /// (4 = 3 "高中") /// (5 6 7 8 = 4 "大学以以上"), gen(edu) for var _all: replace X =. if inlist(X, -10, -9, -8, -2, -1) drop if missing()==0 for var _all: gen aaa=1 if missing(X)==0 for var _all: drop if missing(X)==0
标签:real,10,made,stata,replace,举例,应用,inlist,changes From: https://www.cnblogs.com/xkdn/p/17201420.html