Stata旧笔记整理(十二)

Stata旧笔记整理(十二)

之前老网站上有很多没有很好整理的笔记。之前也整理过一些,但是还有两百多篇,所以就简单汇总一下,便于检索。

sssplot

1
2
3
4
5
6
7
8
stkpv 1, c f(19900101) t(20180101)
gen year = yofd(date)
gen month = mofd(date)
collapse clsprc opnprc, by(year month)
egen month1 = seq(), to(12)
set scheme plottig, permanently
keep in 1/25
sssplot clsprc month1 year

1
sssplot clsprc month1 year, c(L)

1
sssplot clsprc month1 year, c(L) sy(i) st(7)

1
sssplot clsprc month year, sf(mean) gbym

1
sssplot clsprc month year, sf(mean) gbym c(L)

st_data()函数

st_data()函数主要是提取Stata当前内存中的数值型变量,而函数st_sdata()函数主要是提取Stata当前内存中的字符型变量。

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
sysuse auto, clear
keep in 1/10
mata
A1 = st_data(1,2) //提取第一个观测值的第二个变量值
A1
A2 = st_data(.,2)
A2
A3 = st_data((1\2\5),2) //提取第1,2,5个观测值的第二个变量值
A3
A4 = st_data((1,5),2) //提取第1到第5个观测值的第二个变量值
A4
A8 = st_data(.,("mpg","weight"))
A8
end
// 除此之外,st_data()还可以直接提取变量的滞后变量和虚拟变量,例如:
gen year = 2000 + _n
tsset year
mata
A10 = st_data(.,("price","L.price"))
A10
A11 = st_data(.,"mpg i.rep78") //提取变量mpg和虚拟变量rep78的所有观测值,含缺失值
A11
end
tab rep78, gen(r)
mata
A13 = st_data(.,"mpg weight")
A13
A14 = st_data(.,"mpg weight","r2") //虚拟变量r2取值非零的时候提取变量对应的观测值
A14
A15 = st_data(.,"mpg weight",15) //15表示r2在变量中的编号
A15
A16 = st_data(.,"mpg weight",) //all
A16
A18 = st_data(.,"mpg i.rep78",0) //提取变量mpg和虚拟变量rep78非缺失的观测值
A18
A19 = st_data(.,1)
A19
A20 = st_sdata(.,1)
A20
end

stack——堆叠数据

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
. webuse stackxmpl, clear

. list

+---------------+
| a b c d |
|---------------|
1. | 1 2 3 4 |
2. | 5 6 7 8 |
+---------------+

. * 堆叠 abcd

. stack a b c d, into(e f) clear

. list

+----------------+
| _stack e f |
|----------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 3 4 |
4. | 2 7 8 |
+----------------+

. * _stack = 1 表示是第一组ab堆叠成的数据集

. * _stack = 2 表示是第二组cd堆叠成的数据集

.
. * 下面的命令格式作用与上面的是等效的

. webuse stackxmpl, clear

. stack a b c d, into(v1-v2)
Warning: data in memory will be lost.
Press any key to continue, Ctrl-Break to abort.

. list

+------------------+
| _stack v1 v2 |
|------------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 3 4 |
4. | 2 7 8 |
+------------------+

.
. webuse stackxmpl, clear

. stack a-d, into(v1-v2)
Warning: data in memory will be lost.
Press any key to continue, Ctrl-Break to abort.

. list

+------------------+
| _stack v1 v2 |
|------------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 3 4 |
4. | 2 7 8 |
+------------------+

.
. webuse stackxmpl, clear

. stack a b c d, into(a b) clear

. list

+----------------+
| _stack a b |
|----------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 3 4 |
4. | 2 7 8 |
+----------------+

.
. webuse stackxmpl, clear

. stack a b c d, group(2)
Warning: data in memory will be lost.
Press any key to continue, Ctrl-Break to abort.

. list

+----------------+
| _stack a b |
|----------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 3 4 |
4. | 2 7 8 |
+----------------+

.
. webuse stackxmpl, clear

. stack a b a c, into(a bc) clear

. list

+-----------------+
| _stack a bc |
|-----------------|
1. | 1 1 2 |
2. | 1 5 6 |
3. | 2 1 3 |
4. | 2 5 7 |
+-----------------+

.
. * Stack a on a and call it a, stack b on c and call it bc, and retain original v
> ariables (a will contain stacked values because a is specified in into())。

. webuse stackxmpl, clear

. stack a b a c, into(a bc) clear wide

. list

+-------------------------+
| _stack a bc b c |
|-------------------------|
1. | 1 1 2 2 . |
2. | 1 5 6 6 . |
3. | 2 1 3 . 3 |
4. | 2 5 7 . 7 |
+-------------------------+

Stata绘图选项

1
2
net from “http://www.stata-press.com/data/vgsg3/”
net install vgsg3
1
vguse allstates, clear
  • title
1
2
3
4
5
6
7
set scheme vg_rose
tw sc propval100 rent700 popden, ///
ti("Title", box size(medlarge)) ///
ms(S) ///
xla(0(1000)10000, alt labsize(medlarge)) ///
leg(c(2) label(1 "Property Value") label(2 "Rent"))
gr export title.png, replace

  • line-pattern
1
2
3
4
5
tw sc propval100 popden, ///
ms(S) || ///
lfit propval100 popden, ///
lw(vthick) ||, ///
leg(pos(1))

  • legend
1
2
3
vguse allstates, clear
set scheme vg_rose
sc married pov, ti(title) subtitle(subtitle) note(note) caption(caption) leg(on title(leg title) subtitle(leg subtitle) note(leg note) caption(leg caption))

ms()

1
2
vguse allstates, clear
tw sc ownhome propval100, ms(S)

mla()

1
tw sc ownhome propval100, mla(stateab) msize(small) mlabsize(small)

connect

1
tw sc fv ownhome propval100, connect(l .) sort

ysc(alt)

1
tw sc fv ownhome propval100, connect(l .) sort ysc(alt)

by()

1
tw sc fv ownhome propval100, connect(l .) sort by(north)

Stata绘图中使用特殊符号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
clear all
tw ///
scatteri 6.5 0 "其他符号", mlabsize(small) pstyle(p1) || ///
scatteri 6.5 0.3 "{&trade} {&copyright} {&loz} {&reg} {&ellipsis} {&diamond} {&spades} {&diams} {&degree} {&hArr} {&uArr}", mlabsize(huge) pstyle(p1) || ///
scatteri 5.5 0 "粗体", mlabsize(small) pstyle(p1) || ///
scatteri 5.5 0.5 "{bf: Bold Font} {&crarr} {&prime}", mlabsize(huge) pstyle(p1) || ///
scatteri 4.5 0 "{it: 斜体}", mlabsize(small) pstyle(p1) || ///
scatteri 4.5 0.5 "{it: Italics}", mlabsize(huge) pstyle(p1) || ///
scatteri 3.5 0 "上标", mlabsize(small) pstyle(p1) || ///
scatteri 3.0 0.5 "{superscript: Superscript}", mlabsize(huge) pstyle(p1) || ///
scatteri 2.5 0 "下标", mlabsize(small) pstyle(p1) || ///
scatteri 2.5 0.5 "{subscript: subscript}", mlabsize(huge) pstyle(p1) || ///
scatteri 1.5 0 "默认字体样式", mlabsize(small) pstyle(p1) || ///
scatteri 1.5 0.5 "{stSymbol: adcv} {stSerif:serif} {stSans:sans serif}", mlabsize(huge) pstyle(p1) || ///
scatteri 0.5 0 "希腊字母", mlabsize(small) pstyle(p1) || ///
scatteri 0.5 0.5 "{&Alpha} {&pi} {&Sigma} {&Beta} {&beta}", mlabsize(huge) pstyle(p1) title("可以在Stata中使用的特殊字体", color(red)) xla(-0.05 1) yla(-1 7) xsc(off) ysc(off) leg(off) note("Stata中的特殊字体" "还有很多其他选项,查看{bf: help graph text}", ring(0))
graph export Stata绘图中使用特殊符号.png, replace

Stata中的日期和时间

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
	type dates.txt //显示数据
infix str name 1-4 str bday 6-17 using dates.txt //导入数据
gen birthday = date(bday, "DMY")
list
format birthday % d
//这个命令只是强制birthday按照用户喜欢的日期表达方式显示,
//并不改变其具体数值
//% d表示birthday 的显示格式为简单的日期格式,即用两位数字
//表示日期,用三位字母表示月份以及用四位数字表示年份
list
//我们可以用不同的日期格式来显示日期数据
clear
set more off
set obs 4
gen int bday = uniform()*1000 - 200
gen bday1 = bday
gen bday2 = bday
gen bday3 = bday
gen bday4 = bday
gen bday5 = bday
gen bday6 = bday
format bday1 % d
format bday2 % dCYND
format bday3 % dCY_N_D
format bday4 % dCY_m_D
format bday5 % dM_D_Y
format bday6 % dm_D_Y
list
outsheet using birthday.txt, replace
insheet using birthday.txt, clear
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	gen bday7 = string(bday2,"%8.0f")  //bday2是数值型的
list
drop bday2
rename bday7 bday2
gen birthday1 = date(bday1, "DMY")
gen birthday2 = date(bday2, "YMD")
gen birthday3 = date(bday3, "YMD")
gen birthday4 = date(bday4, "YMD")
gen birthday5 = date(bday5, "MD19Y")
gen birthday6 = date(bday6, "MD19Y")
drop bday bday1 - bday6 bday2
list
//mdy()函数:调用三个整数型自变量:月日年,并输出与该日期对应的Stata
//整数型日期编码
clear all
set more off
set obs 4
set seed 101010
gen int bday = uniform()*1000 - 200
gen bday1 = bday
gen bday2 = bday
gen bday3 = bday
gen bday4 = bday
gen bday5 = bday
gen bday6 = bday
format bday1 % d
format bday2 % dCYND
format bday3 % dCY_N_D
format bday4 % dCY_m_D
format bday5 % dM_D_Y
format bday6 % dm_D_Y
outsheet using birthday.txt, replace
insheet using birthday.txt, clear
gen int year = bday2/10000
gen int month = mod(bday2, year)/100
gen int day = mod(bday2, 100)
gen birthday2 = mdy(month, day, year)
format birthday2 % dm_D_CY
list birthday2

di mdy(1, 2, 1960)
di % dCY_N_D mdy(12, 25, 2001)

di date("$S_DATE", "DMY")-mdy(2,27,1974)
/*$S_DATE是一个系统变量,该变量以一个global的形式存在,它返回
//一个字符串格式
的当前日期,字符串的形式为21 Sep 2017.
类似的变量还有$S_TIME
*/
di "$S_TIME $S_DATE"
//c()类系统参数
di c(current_time) c(current_date) //显示当前时间与日期
di c(pi) //圆周率的表示
di c(alpha) //c(alpha)表示26个小写字母

//td()函数:将输入的日期字符串直接转换成Stata的日期数据
di td(21sep2017)
di td(21 sep 2017)
di td(21 Sep 2017)
di td("21 9 2017")

//从日期到年月日
global d td("21sep2017")
di $d
di year($d)
di month($d)
di day($d)
di doy($d) //该年的第几天
di halfyear($d) //第几个半年
di quarter($d) //第几个季度
di week($d) //第几周
di dow($d) //星期几(0代表星期日)

//月度与季节数据
//Stata以1960年1月为第0月
clear
set more off
set obs 10
gen d = _n*500
gen date = d
format date % dCY_N_D
gen ym = ym(year(date), month(date)) //月
format ym % tmCY_N
gen yq = yq(year(date), quarter(date)) //季度
format yq % tq
gen yw = yw(year(date), week(date)) //周
format yw % tw
list

//clock()函数:它以1960年1月1日00:00:00为0时刻,
//每增加1毫秒,对应的时间加1
//clock("时间字符串","字符串格式")
/*字符串格式编码
DMYhms
DM20Yhms
字符串中无用的部分(例如星期)可用#表示,提醒Stata忽略该部分字符
*/
di % tc clock("00:00", "hm")
di % tc clock("2017 21 9 15:38 Thursday", "20YDMhm#")
//时间成分的提取
local time = clock(c(current_date) + " " + ///
c(current_time), "DMYhms")
disp `time'
disp % tc `time'
disp dofc(`time') //21083
disp year(dofc(`time'))
disp month(dofc(`time'))
disp day(dofc(`time'))
disp week(dofc(`time'))
disp dow(dofc(`time'))
disp hh(`time')
disp mm(`time')
disp ss(`time')

Stata中调用系统文件夹

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* 显示几个系统文件夹的位置
* personal文件夹
di c(sysdir_personal)
* plus文件夹
di c(sysdir_plus)
* base文件夹
di c(sysdir_base)
* Stata文件夹
di c(sysdir_stata)
* site文件夹
di c(sysdir_site)
* oldplace文件夹
di c(sysdir_oldplace)

* 检查上面的文件夹是否存在
mata: parse_personal(`"`c(sysdir_personal)'"')
if ("`personal_rc'" == "0") {
di as err "PERSONAL directory does not exist"
exit 198
}
* 198为某个文件夹不存在的错误返回值。

Stata中的图

1
2
net from “http://www.stata-press.com/data/vgsg3/”
net install vgsg3
  • 平滑方法
1
2
3
4
5
6
7
8
9
vguse allstates.dta, clear
* 平滑方法
tw sc propval100 popden || ///
mspline propval100 popden || ///
fpfit propval100 popden || ///
mband propval100 popden || ///
lowess propval100 popden ||, ///
scheme(vg_s2c)
gr export pic1.png, replace

  • mspline: median spline
  • fpfit: fractional polynomial fit
  • mband: median band
  • lowess: lowess smoothing

  • 带区间的方法

1
2
3
tw lfitci propval100 popden || ///
sc propval100 popden, scheme(vg_s2c)
gr export pic2.png, replace

  • dropline方法
1
2
3
sysuse sp500, clear
tw dropline close date, msize(vsmall) scheme(vg_s2c)
gr export pic3.png, replace

  • spike方法
1
2
tw spike close date, scheme(vg_s2c)
gr export pic4.png, replace

  • dot方法
1
2
tw dot close date, msize(vsmall) scheme(vg_s2c)
gr export pic5.png, replace

  • connect方法
1
2
tw connect close date, msize(vsmall) scheme(vg_s2c)
gr export pic6.png, replace

  • tsline方法
1
2
3
tsset date
tw tsline close, scheme(vg_s2c)
gr export pic7.png, replace

  • tsrline方法: time-series-range-line
1
2
tw tsrline high low, sort scheme(vg_s2c)
gr export pic8.png, replace

  • area方法
1
2
tw area close date, sort scheme(vg_s2c)
gr export pic9.png, replace

  • bar方法
1
2
tw bar close date, sort scheme(vg_s2c)
gr export pic10.png, replace

  • rarea方法
1
2
tw rarea high low date, sort scheme(vg_s2c)
gr export pic11.png, replace

  • rconnected方法
1
2
tw rconnected high low date, sort msize(vsmall) scheme(vg_s2c)
gr export pic12.png, replace

  • rcap方法
1
2
tw rcap high low date, msize(vsmall) sort scheme(vg_s2c)
gr export pic13.png, replace

  • rbar方法
1
2
tw rbar high low date, sort scheme(vg_s2c)
gr export pic14.png, replace

  • matrix方法
1
2
3
vguse allstates.dta, clear
gr matrix propval100 rent700 popden, scheme(vg_s2c)
gr export pic15.png, replace

  • hbar方法
  • 下面两句命令时等效的
1
2
gr hbar popk, over(division) scheme(vg_s2c)
gr export pic16.png, replace

1
2
gr bar popk, over(division) horiz scheme(vg_s2c)
gr export pic17.png, replace

  • hbox方法
1
2
gr hbox popk, over(division) scheme(vg_s2c)
gr export pic18.png, replace

  • gr dot方法
1
2
gr dot popk, over(division) scheme(vg_s2c)
gr export pic19.png, replace

  • gr pie方法
1
2
gr pie popk, over(region) scheme(vg_s2c)
gr export pic20.png, replace

statplot

  • statplot plots summary statistics for varlist.
1
2
sysuse citytemp, clear
statplot heatdd cooldd

1
statplot heatdd cooldd, over(region)

1
statplot temp*, over(region, sort(1) descending) s(sd) blabel(bar, format(%2.1f)) ysc(r(. 17.5))

1
2
sysuse census, clear
statplot marriage divorce, over(region) s(sum)

1
statplot marriage divorce, over(region) s(sum) xpose

1
statplot marriage divorce, over(region) s(sum) xpose varnames

1
2
sysuse nlsw88, clear
statplot wage, over(race) over(union)

1
2
separate wage, by(race) veryshortlabel
statplot wage?, over(union)

statsby_从Stata命令中搜集统计量

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
. * Collect statistics for a command across a by list.

. use bpress, clear
(fictional blood-pressure data)

. statsby mean = r(mean) sd = r(sd) n = r(N), by(agegrp sex) saving(bpstats, repl
> ace): sum bp
(running summarize on estimation sample)

command: summarize bp
mean: r(mean)
sd: r(sd)
n: r(N)
by: agegrp sex

Statsby groups
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

.
. use bpstats, clear
(statsby: summarize)

. list

+-------------------------------------------+
| agegrp sex mean sd n |
|-------------------------------------------|
1. | 30-45 Male 149.95 12.53498 40 |
2. | 30-45 Female 146.05 9.483994 40 |
3. | 46-59 Male 158.15 13.90914 40 |
4. | 46-59 Female 147.725 10.10201 40 |
5. | 60+ Male 164.075 10.27665 40 |
|-------------------------------------------|
6. | 60+ Female 157.475 12.02985 40 |
+-------------------------------------------+

stripplot

1
2
3
4
sysuse census, clear
set scheme s1color
stripplot medage, stack ms(Sh) msize(*3.5) width(0.5) ///
mla(state2) mlabpos(0) mlabsize(*.9) ysc(off) plotregion(lstyle(none))

1
2
sysuse auto, clear
stripplot mpg

1
stripplot mpg, aspect(0.05)

1
stripplot mpg, over(rep78)

1
stripplot mpg, over(rep78) by(foreign)

1
stripplot mpg, over(rep78) vertical

1
stripplot mpg, over(rep78) vertical stack

1
stripplot mpg, over(rep78) vertical stack h(0.4)

1
2
gen pipe = "|"
stripplot mpg, ms(none) mlabpos(0) mlabel(pipe) mlabsize(*2) stack

1
stripplot price, over(rep78) ms(none) mla(pipe) mlabpos(0)

1
stripplot price, over(rep78) w(200) stack h(0.4)

1
2
3
gen price1 = price - 5
gen price2 = price + 5
stripplot price, over(rep78) box ms(none) addplot(rbar price1 price2 rep78, horizontal barw(0.2) bcolor(gs6))

1
stripplot mpg, over(rep78) stack h(0.5) bar(lcolor(red))

1
stripplot mpg, over(rep78) box

1
stripplot mpg, over(rep78) box boffset(-0.3)

1
stripplot mpg, over(rep78) box(bfcolor(eltgreen)) boffset(-0.3)

1
stripplot mpg, over(rep78) box(bfcolor(eltgreen) barw(0.2)) boffset(-0.2) stack h(0.5)

1
stripplot mpg, over(rep78) box(bfcolor(black) blcolor(white) barw(0.2)) boffset(-0.2) stack h(0.5)

1
stripplot mpg, over(rep78) box(bfcolor(black) blcolor(white) barw(0.2)) iqr boffset(-0.2) stack h(0.5)

1
stripplot mpg, over(rep78) box(bfcolor(black) blcolor(white) barw(0.2)) pctile(10) whiskers(recast(rbar) bcolor(black) barw(0.02)) boffset(-0.2) stack h(0.5)

1
2
gen digit = mod(mpg, 10)
stripplot mpg, stack vertical mla(digit) mlabpos(0) ms(i) over(foreign) height(0.2) yla(, ang(h)) xla(, noticks)

1
stripplot mpg, stack vertical mla(digit) mlabpos(0) ms(i) by(foreign) yla(, ang(h))

1
stripplot mpg, over(rep78) separate(foreign) stack

1
stripplot mpg, by(rep78) separate(foreign) stack

1
2
3
gen rep78_1 = rep78 - 0.1
egen mean = mean(mpg), by(foreign rep78)
stripplot mpg, over(rep78) by(foreign, compact) addplot(scatter rep78_1 mean, ms(T)) stack

1
2
3
4
egen mean_2 = mean(mpg), by(rep78)
gen rep78_L = rep78 - 0.1
gen rep78_U = rep78 - 0.02
stripplot mpg, over(rep78) stack addplot(pcarrow rep78_L mean_2 rep78_U mean_2, msize(medlarge) barbsize(medlarge)) yla(, grid)

1
2
3
clonevar rep78_2 = rep78
replace rep78_2 = cond(foreign, rep78 + 0.15, rep78 - 0.15)
stripplot mpg, over(rep78_2) separate(foreign) yla(1/5) jitter(1 1)

1
2
3
logit foreign mpg
predict pre
stripplot mpg, over(foreign) stack ms(sh) height(0.15) addplot(mspline pre mpg, bands(20))

1
2
3
4
5
egen group = group(foreign rep78)
replace group = cond(group <= 5, group, group + 1)
label def group 7 "3" 8 "4" 9 "5", modify
lab val group group
stripplot mpg, over(group) vertical cumul cumprob refline box centre mcolor(blue) xmla(3 "Domestic" 8 "Foreign", tlength(*7) tlc(none) labsize(medium)) xtitle("") xli(6, lc(gs12) lw(vthin))

1
2
3
4
5
6
7
8
9
10
11
12
sysuse auto, clear
egen median = median(mpg), by(foreign)
egen loq = pctile(mpg), by(foreign) p(25)
egen upq = pctile(mpg) , by(foreign) p(75)
egen mean = mean(mpg), by(foreign)
egen min = min(mpg)
egen n = count(mpg), by(foreign)
gen shown = "n = " + string(n)
gen foreign2 = foreign + 0.15
gen foreign3 = foreign - 0.15
gen showmean = string(mean, "%2.1f")
stripplot mpg, over(foreign) box(barw(0.2)) centre cumul cumprob vertical height(0.4) addplot(scatter median loq upq foreign2, ms(none ..) mla(median loq upq) mlabc(blue ..) mlabsize(*1.2 ..) || scatter mean foreign3, ms(none) mla(showmean) mlabc(orange) mlabsize(*1.2) mlabpos(9) || scatter min foreign, ms(none) mla(shown) mlabc(black) mlabsize(*1.2) mlabpos(6)) xsc(r(. 1.2)) xla(, noticks)

1
2
3
sysuse bplong, clear
egen group = group(age sex), label
stripplot bp*, bar over(when) by(group, compact col(1) note("")) ysc(reverse) subtitle(, pos(9) ring(1) nobexpand bcolor(none) placement(e)) ytitle("") xtitle(Blood pressure (mm Hg))

1
2
3
sysuse citytemp, clear
label var tempjan "Mean January temperature ({&degree}F)"
stripplot tempjan, over(region) cumul vertical yla(14 32 50 68 86, ang(h)) refline centre

1
stripplot tempjan, over(region) cumul vertical yla(14 32 50 68 86, ang(h) grid) refline(lc(red) lw(medium)) centre

1
2
3
4
5
gen id = _n
reshape long temp, i(id) j(month) string
replace month = cond(month == "jan", "January", "July")
label var temp "Mean temperature ({&degree}F)"
stripplot temp, over(region) by(month) cumul vertical yla(14 32 50 68 86, ang(h)) bar centre

1
stripplot temp, over(region) by(month) cumul cumpr vertical yla(14 32 50 68 86, ang(h)) box(barw(0.5) blcolor(gs12)) height(0.4) centre

1
2
3
gen tempC = (5/9) * temp - 32
label var tempC "Mean temperature ({&degree}C)"
stripplot tempC, over(division) by(month, xrescale note("whiskers to 5 and 95% points")) xla(, ang(h)) box pctile(5) outside(ms(oh) mcolor(red)) ms(none)

# Stata

评论

程振兴

程振兴 @czxa.top
截止今天,我已经在本博客上写了607.9k个字了!

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×