直接从键盘输入 两种方法:edit和input . input y x
y x 1. 3232 343 2. 43324 45634 3. 32423 45343 4. end
其他输入方式,参考help import
*StatTransfer软件可以进行不同格式数据转换
2.3 画图
1. 散点图
[twoway] scatter varlist [if] [in] [weight] [, options] graph matrix varlist [if] [in] [weight] [, options]
sc mpg weight
sc mpg weight || lfit mpg weight
twoway (lfitci mpg weight,lwidth(medthick))(sc mpg weight)
scatter lwage educ, msize(small) || lfit lwage educ, lwidth(medthick)
graph twoway (scatter lwage educ, msize(small) )( lfit lwage educ, lwidth(medthick)), title(\OLS fitted line\
加置信区间:lfitci, qfit, qfitci, fpfitci
graph save [graphname] filename [, asis replace] 或直接用选项
saving(filename[, asis replace])
21
保存的图可以组合起来graph combine,打开盘中的图用graph use graph save save graph to disk
graph use redisplay graph stored on disk graph display redisplay graph stored in memory graph combine combine multiple graphs 2. 直方图
histogram varname [if] [in] [weight] [, [continuous_opts | discrete_opts] options] 3. 核密度图(Kernel density plot)
kdensity varname [if] [in] [weight] [, options] twoway kdensity varname [if] [in] [weight] [, options]
twoway kdensity lwage ,by(male) //显示在两张独立的图上
twoway (kdensity lwage if male==1)(kdensity lwage if male==0) , legend(label(1 “Male”) label(2 “Female”)//同一图中
2.4 更多资源
参考[U] Users Guide 和 [D] Data Management Reference Manual。有用的在线帮助命令包括:1) double, string, format; 2) clear, use, insheet, infile, outsheet; 3) summarize, list, label, tabulate, generate, egen, keep drop, recode, sort, gsort, merge, append, collapse; 4) graph, scatter, histogram, kdensity, twoway, graph matrix。
第3章 线性回归基础
3.1 数据和数据描述
比如我们研究收入决定模型,使用2002年的中国城镇居民收入调查数据ind02.dta。首先,将数据调入系统,对变量进行描述。 3.1.1 变量描述 use inc02.dta, clear
22
describe wage lwage male age educ exper expersq ownership industry occupation [,detail]
. describe wage lwage male age educ exper expersq ownership industry occupation storage display valuevariable name type format label variable label wage float %9.0g lwage float %9.0g log wagemale int %9.0g male 1 male 0 femaleage float %9.0g ageeduc float %9.0g years of schoolingexper float %9.0g experienceexpersq float %9.0g ownership int %9.0g ownership ownershipindustry int %9.0g industryoccupation int %9.0g occupation
3.1.2 简单统计
summarize wage lwage male age educ exper expersq ownership industry occupation
. summarize wage lwage male age educ exper expersq ownership industry occupation Variable Obs Mean Std. Dev. Min Max wage 9581 11537.45 7974.335 5 144530 lwage 9581 9.121752 .7590605 1.609438 11.88124 male 10105 .5555666 .4969274 0 1 age 10105 40.32855 8.865457 20 60 educ 10105 11.42415 2.985517 0 23 exper 10031 20.11295 9.568137 0 43 expersq 10031 496.0709 382.8571 0 1849 ownership 9781 1.832737 1.271858 1 4 industry 9754 6.160344 3.38035 1 12 occupation 9754 3.684847 1.47195 1 6
tabulate 可以用来对变量列表 3.1.3 二维表
tabulate male [, nolabel] 23
. tabulate male 1 male 0 female Freq. Percent Cum. female 4,491 44.44 44.44 male 5,614 55.56 100.00 Total 10,105 100.00. tabulate male, nolabel 1 male 0 female Freq. Percent Cum. 0 4,491 44.44 44.44 1 5,614 55.56 100.00 Total 10,105 100.00. tabulate industry male
. tab industry male 1 male 0 female industry female male Total 1 50 73 123 2 1,039 1,475 2,514 3 76 164 240 4 99 230 329 5 227 567 794 6 683 547 1,230 7 790 684 1,474 8 297 215 512 9 434 465 899 10 62 114 176 11 134 136 270 12 433 760 1,193 Total 4,324 5,430 9,754
24
. tabulate male ownership, row column Key frequency row percentage column percentage 1 male 0 ownership female SOE COE FOE POE Total female 2,737 389 90 1,102 4,318 63.39 9.01 2.08 25.52 100.00 41.92 55.97 40.72 47.17 44.15 male 3,792 306 131 1,234 5,463 69.41 5.60 2.40 22.59 100.00 58.08 44.03 59.28 52.83 55.85 Total 6,529 695 221 2,336 9,781 66.75 7.11 2.26 23.88 100.00 100.00 100.00 100.00 100.00 100.00
三维表
table male ownership occupation
. table male own occ occupation and ownership 1 male 0 1 2 3 female SOE COE FOE POE SOE COE FOE POE SOE COE FOE POE female 35 3 2 2 804 62 19 108 926 69 28 151 male 182 13 7 871 42 35 150 1,334 72 29 162 occupation and ownership 1 male 0 4 5 6 female SOE COE FOE POE SOE COE FOE POE SOE COE FOE POE female 310 88 21 539 269 85 11 117 356 71 9 110 male 146 34 14 453 304 49 10 107 909 87 41 289
25