10.4 stata
今日练习代码:
. log using log_20141004
. sysuse dir
auto.dta covresults.dta mywide.dta surface.dta
autornd.dta educ99gdp.dta network1.dta telomerase.dta
bcg.dta fleiss.dta network1a.dta tsline1.dta
bplong.dta fscstage1.dta nlsw88.dta tsline2.dta
bpwide.dta gnp96.dta nlswide1.dta uslifeexp.dta
cancer.dta haloperidol.dta pop2000.dta uslifeexp2.dta
census.dta lifeexp.dta qualires.dta voter.dta
cholesterol.dta lubin97.dta sandstone.dta wage1.dta
citytemp.dta magnes.dta sp500.dta xrcise4deprsn.dta
citytemp4.dta mylong.dta strepto.dta xtline1.dta
. sysuse wage1
. label data"1968年国家调查"
. label variable educ "受教育年限"
. label define marry 0"married"1"single"
. label values married marry
class1.
数据拆分
. use chengji,clear
. drop economy math
. save student ,replace
(note: file student.dta not found)
file student.dta saved
. use chengji,clear
. drop economy math
. save student ,replace
(note: file student.dta not found)
file student.dta saved
. use chengji,clear
. keep id economy
. save economy
file economy.dta saved
. use chengji,clear
. keep id math
. save math
file math.dta saved
数据结合
sort id
. save math,replace
file math.dta saved
. use economy
. use economy,clear
. sort id
. merge id using math
(note: you are using old merge syntax; see [D] merge for new syntax)
(merge 后的3 表示两个文件里有共同的观测值,表示对接成功)
数据拆分 纵向
use chengji ,clear
save female, replace
keep if gender==0
save female , replace
use chengji ,clear
drop if gender ==0
save male ,replace
append using female
sort id
数据重整 长款转换
. use mywide, clear
. reshape long math economy, i (id name) j (year)
(note: j = 2003 2004)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 8 -> 16
Number of variables 6 -> 5
j variable (2 values) -> year
xij variables:
math2003 math2004 -> math
economy2003 economy2004 -> economy
-----------------------------------------------------------------------------
. reshape wide math economy, i (id name) j (year)
(note: j = 2003 2004)
Data long -> wide
-----------------------------------------------------------------------------
Number of obs. 16 -> 8
Number of variables 5 -> 6
j variable (2 values) year -> (dropped)
xij variables:
math -> math2003 math2004
economy -> economy2003 economy2004
---------------------------------------------------------------------
数据抽取
. log using log_20141004
. sysuse dir
auto.dta covresults.dta mywide.dta surface.dta
autornd.dta educ99gdp.dta network1.dta telomerase.dta
bcg.dta fleiss.dta network1a.dta tsline1.dta
bplong.dta fscstage1.dta nlsw88.dta tsline2.dta
bpwide.dta gnp96.dta nlswide1.dta uslifeexp.dta
cancer.dta haloperidol.dta pop2000.dta uslifeexp2.dta
census.dta lifeexp.dta qualires.dta voter.dta
cholesterol.dta lubin97.dta sandstone.dta wage1.dta
citytemp.dta magnes.dta sp500.dta xrcise4deprsn.dta
citytemp4.dta mylong.dta strepto.dta xtline1.dta
. sysuse wage1
. label data"1968年国家调查"
. label variable educ "受教育年限"
. label define marry 0"married"1"single"
. label values married marry
class1.
数据拆分
. use chengji,clear
. drop economy math
. save student ,replace
(note: file student.dta not found)
file student.dta saved
. use chengji,clear
. drop economy math
. save student ,replace
(note: file student.dta not found)
file student.dta saved
. use chengji,clear
. keep id economy
. save economy
file economy.dta saved
. use chengji,clear
. keep id math
. save math
file math.dta saved
数据结合
sort id
. save math,replace
file math.dta saved
. use economy
. use economy,clear
. sort id
. merge id using math
(note: you are using old merge syntax; see [D] merge for new syntax)
(merge 后的3 表示两个文件里有共同的观测值,表示对接成功)
数据拆分 纵向
use chengji ,clear
save female, replace
keep if gender==0
save female , replace
use chengji ,clear
drop if gender ==0
save male ,replace
append using female
sort id
数据重整 长款转换
. use mywide, clear
. reshape long math economy, i (id name) j (year)
(note: j = 2003 2004)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 8 -> 16
Number of variables 6 -> 5
j variable (2 values) -> year
xij variables:
math2003 math2004 -> math
economy2003 economy2004 -> economy
-----------------------------------------------------------------------------
. reshape wide math economy, i (id name) j (year)
(note: j = 2003 2004)
Data long -> wide
-----------------------------------------------------------------------------
Number of obs. 16 -> 8
Number of variables 5 -> 6
j variable (2 values) year -> (dropped)
xij variables:
math -> math2003 math2004
economy -> economy2003 economy2004
---------------------------------------------------------------------
数据抽取
还没人转发这篇日记