这是教对象Stata系列视频的配套代码。对应视频与笔记链接请见下方链接,配套代码请见分割线下方。
视频合集
bilibili视频链接
配套笔记链接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
cd "C:/Users/wugan/Desktop/教对象Stata系列/第4课:数据管理-长宽数据转换/示范数据"
use "wide_data", clear reshape long x, i(id) j(list) drop if x==. save "long_data", replace
use "long_data", clear reshape wide x, i(id) j(list) save "wide_data", replace
use "中国综合社会调查/CGSS2018", clear
keep id token provinces type a00 a0102* a0103* a0104* a0105* a0106* a010601* drop a0106022-a01061414
reshape long a0102 a0103 a0104 a0105 a0106 a010601, i(id) j(PID)
label var a0102 "性别" label var a0103 "年龄" label var a0104 "是否同吃同住" label var a0105 "是否经济独立" label var a0106 "婚姻状况" label var a010601 "与受访人关系"
drop if a0102==.
save "中国综合社会调查/CGSS_person_2018", replace
use "中国劳动力动态调查/2018个体问卷", clear keep FID2018 I1_20_*
egen PID=seq(),to(1000) by(FID2018)
tostring PID, replace replace PID="_"+PID
reshape wide *, i(FID2018) j(PID) reshape wide *, i(FID2018) j(PID) string reshape wide I1_20_1 I1_20_2 I1_20_3 I1_20_4 I1_20_50 I1_20_5 I1_20_6 I1_20_7, i(FID2018) j(PID) string
save "中国劳动力动态调查/2018个体养老保险(wide)", replace
ssc install tidy, replace
sysuse educ99gdp.dta, clear gather public private, variable(sector) value(edu)
spread sector edu
|