STATA在统计与计量分析中的应用Ch1-5程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
cd d:\stata10\AOSISAE
set more off
sjlog using part1, replace
* example 1.1
use consume, clear
*(1)
summ income consume
*(2)
summarize income consume if income>8000
*(3)
sort income , stable
summarize income consume in f/5
summarize income consume in -5/l
*(4)
by area, sort: summarize income consume
* example 2.1
use hbp, clear
*(1)
encode sex2, generate(gender) label(sexlb)
*(2)
decode sex, generate(sexstr)
* example 2.2
use destring1, clear
destring, generate(id2 num2 code2 total2 income2) destring, replace
* example 2.3
use destring2, clear
destring date, ignore(" ") replace
* example 2.4
use mdy, clear
tostring year day, replace
* example 2.5
use hdi, clear
list GDP HDI if LMH_income==3 // hdi -> HDI
* example 2.6
use xposexmpl
list
xpose, clear varname
list
xpose, clear varname
list
* example 2.7
use mdy, clear
list month day year mydate mydate2 mydate3
generate edate=mdy(month, day, year)
gen eate2=date(mydate, "MDY")
gen eate3=date(mydate, "MDY", 2020)
gen edate4=monthly(mydate3,"YM",2010)
* example 2.8
use hdi, clear
*(1)
label data "Source: World Development Report(2005)"
*(2)
label variable GDPPER "GDP Percapita: PPP $"
label variable HDI "Human development Index"
* (3) dropped
* label define sexlabel 0 "male" 1 "female"
* label values sex sexlabel
* example 2.9
use category, clear
generate incomecat=recode(income, 10000,20000) generate educat=(educindex>70) // eduindex -> educindex xi c
* example 3.1
use auto, clear
matrix accum A=price weight mpg
matrix XX=A[2...,2...]
matrix Xy=A[2 (1)
matrix b=invsym(XX)*Xy
* example 3.2
use auto, clear
mkmat price
mkmat weight mpg, matrix(X)
matrix b = invsym(X'*X)*X'*price // mpg -> price
* example 3.3
use auto, clear
regress price weight mpg
matrix c = e(b)'
svmat double c, name(bvector)
list bvector1 in 1/5
* example 3.4
use consume, clear
*(1)
summ consume // new command
gen mdev=consume-r(mean) // modified
*(2)
egen stdcons=std(consume), mean(0) std(1) // add the comma *(3)
summ consume
local m=r(mean) // new command
local sd=r(sd) // new command
egen stdinc=std(income), mean(`m') std(`sd') // modified
*(4)
egen consrank=rank(consume),unique
sjlog close, replace