admin 管理员组文章数量: 1086019
2024年3月26日发(作者:互站网是干嘛的)
Stata作图简介
1.直方图
命令:histogram varname(变量名), (options),这里的options是可选择的,如果不写,
则按照默认作图。
例如,举一个收入,受教育程度与工作经验以及种族的例子。
. cd e:/data
e:data
. use ,clear
Describe
Summary
. histogram educ (这里我们不加选项,默认做直方图),得到如下图形
.
1
5
D
e
n
s
i
t
y
.
0
5
0
.
1
0510
educ
1520
默认时,stata将数据确定为连续型,如果我们需要stata做离散直方图的话,加上选项discrete
.histogram educ,discrete (选项用英文逗号隔开)
.
2
5
D
e
n
s
i
t
y
.
0
5
0
0
.
1
.
1
5
.
2
510
educ
1520
还可以给直方图加上密度图像。
.histogram educ,normal (这个选项就可以做正态分布密度图像)
.
1
5
D
e
n
s
i
t
y
.
0
5
0
.
1
0510
educ
1520
用stata 做 kernel density estimation
kernel density estimation is a non-parametric way of estimating the probability density function
of a random variable. As an illustration, given some data about a sample of a population, kernel
density estimation makes it possible to extrapolate the data to the entire population.
在stata中kernel density estimation的命令是,
. kdensity educ
Kernel density estimate
educ
kernel = epanechnikov, bandwidth = 2.1987
. kdensity educ,normal (加上这个选项后,添加数据的正态密度函数做比较)
0
.
1
D
e
n
s
i
t
y
.
0
2
.
0
4
.
0
6
.
0
8
Kernel density estimate
.
0
8
D
e
n
s
i
t
y
.
0
2
0
0
.
0
4
.
0
6
.
1
510
educ
152025
Kernel density estimate
Normal density
kernel = epanechnikov, bandwidth = 2.1987
Stata 散点图简介
最标准写法 graph twoway scatter varlist,(option)
例如,我们想做income和educ的散点关系图
.graph twoway scatter income educ
5
0
i
n
c
o
m
e
1
0
0
0
2
0
3
0
4
0
510
educ
1520
也可以简写成
.scatter income educ
当然我们为了作图需要可以改变图标的形状,大小,颜色等等,这些都通过选项来完成
.scatter income educ,m(d) mc(red) msize(vlarge)
5
0
i
n
c
o
m
e
1
0
0
2
0
3
0
4
0
0510
educ
1520
利用stata作图命令显示fit values
.twoway (scatter income educ)(lfit income educ) (注意这里的命令lfit,就是用直线的方式画
出fit values。Line fit values)
5
0
0
1
0
2
0
3
0
4
0
05
income
10
educ
15
Fitted values
20
当然我们也可以做曲线的fit values,
Twoway (scatter income educ)(qfit income educ)
0
1
0
2
0
3
0
4
0
5
0
05
income
10
educ
15
Fitted values
20
Twoway (scatter income educ)(lfitci income educ)
5
0
0
0
1
0
2
0
3
0
4
0
510
educ
income
Fitted values
15
95% CI
20
Twoway (scatter income educ)(qfitci income educ)
6
0
0
2
0
4
0
0510
educ
income
Fitted values
15
95% CI
20
就是在lfit和qfit后面加ci —— confidence interval(的简写)
版权声明:本文标题:stata-做图 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1711445270a594475.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论