Stata旧笔记整理(七)

Stata旧笔记整理(七)

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

batplot—绘制两个变量的差值和均值之间的关系

1
2
3
4
* batplot: 绘制两个变量的差值和均值之间的关系
* ssc install batplot
sysuse auto, clear
batplot mpg turn, info valabel(make) notrend xlab(26(4)38) moptions(mlabpos(9)) ti(Agreement between mpg and turn)

bcal命令——创建交易日日期

  • bcal check: creates a business calendar file from the current dataset and describes the new calendar.

  • bcal create: creates a business calendar file from the current dataset and describes the new calendar.

  • bcal dir: List filenames and directories of available business calendars.

  • bcal describe: Describe the specified business calendar.

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
. sysuse sp500, clear
(S&P 500)

. * bcal create creates a business calendar file from the current dataset and describes the new calendar.

. bcal create sp500, from(date) purpose(S&P500 for 2001) gen(bizdate) replace

Business calendar sp500 (format %tbsp500):

purpose: S&P500 for 2001

range: 02jan2001 31dec2001
14977 15340 in %td units
0 247 in %tbsp500 units

center: 02jan2001
14977 in %td units
0 in %tbsp500 units

omitted: 116 days
116.4 approx. days/year

included: 248 days
248.9 approx. days/year

Notes:

business calendar file sp500.stbcal saved

variable bizdate created; it contains business dates in %tbsp500 format

. bcal check

%tbsp500: defined, used by variable
bizdate

. * bcal describe: Describe the specified business calendar.

. bcal describe %tbsp500

Business calendar sp500 (format %tbsp500):

purpose: S&P500 for 2001

range: 02jan2001 31dec2001
14977 15340 in %td units
0 247 in %tbsp500 units

center: 02jan2001
14977 in %td units
0 in %tbsp500 units

omitted: 116 days
116.4 approx. days/year

included: 248 days
248.9 approx. days/year

. * bcal dir: List filenames and directories of available business calendars.

. bcal dir
2 calendar files found:
simple: /Applications/Stata 14/ado/base/s/simple.stbcal
sp500: ./sp500.stbcal

. sysuse sp500, clear
(S&P 500)

. * bcal check: List business calendars used by the data in memory.

. bcal check
(no variables use %tb formats)
  • sp500.stbcal的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
* Business calendar "sp500" created by -bcal create-
* Created/replaced on 23 Jan 2018

version 14
purpose "S&P500 for 2001"
dateformat ymd

range 2001jan02 2001dec31
centerdate 2001jan02

omit dayofweek (Sa Su)
omit date 2001jan15
omit date 2001feb19
omit date 2001apr13
omit date 2001may28
omit date 2001jul04
omit date 2001sep03
omit date 2001sep11
omit date 2001sep12
omit date 2001sep13
omit date 2001sep14
omit date 2001nov22
omit date 2001dec25

beamplot:支撑图

1
2
3
4
5
6
* 梁图
* Install
* ssc install beamplot
sysuse auto, clear
beamplot mpg, by(foreign) over(rep78)
gre beamplot

bihist:双分组柱形图

1
2
3
4
5
* 双分组柱形图
* Install
* ssc install bihist
sysuse auto, clear
bihist mpg, by(foreign)

bootstrap:自助法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
. use bpress, clear
(fictional blood-pressure data)

. set seed 6789

. ttest bp, by(sex)

Two-sample t test with equal variances
------------------------------------------------------------------------------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
Male | 120 157.3917 1.236031 13.54004 154.9442 159.8391
Female | 120 150.4167 1.064357 11.65944 148.3091 152.5242
---------+--------------------------------------------------------------------
combined | 240 153.9042 .8445493 13.0837 152.2405 155.5679
---------+--------------------------------------------------------------------
diff | 6.975 1.631143 3.761679 10.18832
------------------------------------------------------------------------------
diff = mean(Male) - mean(Female) t = 4.2761
Ho: diff = 0 degrees of freedom = 238

Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
Pr(T < t) = 1.0000 Pr(|T| > |t|) = 0.0000 Pr(T > t) = 0.0000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
. bootstrap diff = (r(mu_1) - r(mu_2)), nodots: ttest bp, by(sex)

Warning: Because ttest is not an estimation command or does not set e(sample),
bootstrap has no way to determine which observations are used in
calculating the statistics and so assumes that all observations are
used. This means that no observations will be excluded from the
resampling because of missing values or other reasons.

If the assumption is not true, press Break, save the data, and drop
the observations that are to be excluded. Be sure that the dataset in
memory contains only the relevant data.

Bootstrap results Number of obs = 240
Replications = 50

command: ttest bp, by(sex)
diff: r(mu_1) - r(mu_2)

------------------------------------------------------------------------------
| Observed Bootstrap Normal-based
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
diff | 6.975 1.607248 4.34 0.000 3.824851 10.12515
------------------------------------------------------------------------------

by/bysort

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
. use bpress, clear
(fictional blood-pressure data)

. bysort sex agegrp: sum bp

----------------------------------------------------------------------------------
-> sex = Male, agegrp = 30-45

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 149.95 12.53498 125 176

----------------------------------------------------------------------------------
-> sex = Male, agegrp = 46-59

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 158.15 13.90914 132 185

----------------------------------------------------------------------------------
-> sex = Male, agegrp = 60+

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 164.075 10.27665 146 185

----------------------------------------------------------------------------------
-> sex = Female, agegrp = 30-45

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 146.05 9.483995 131 168

----------------------------------------------------------------------------------
-> sex = Female, agegrp = 46-59

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 147.725 10.10201 127 170

----------------------------------------------------------------------------------
-> sex = Female, agegrp = 60+

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 157.475 12.02985 138 185


.
. * To create groups by gender and age group, we could use:

. egen group = group(sex agegrp), label

. by group, sort: sum bp

----------------------------------------------------------------------------------
-> group = Male 30-45

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 149.95 12.53498 125 176

----------------------------------------------------------------------------------
-> group = Male 46-59

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 158.15 13.90914 132 185

----------------------------------------------------------------------------------
-> group = Male 60+

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 164.075 10.27665 146 185

----------------------------------------------------------------------------------
-> group = Female 30-45

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 146.05 9.483995 131 168

----------------------------------------------------------------------------------
-> group = Female 46-59

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 147.725 10.10201 127 170

----------------------------------------------------------------------------------
-> group = Female 60+

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
bp | 40 157.475 12.02985 138 185

by()选项与独立坐标轴

1
vguse allstates, clear
1
tw sc ownhome borninstate, by(north)

1
tw sc ownhome borninstate, by(north, total)

1
2
tw sc ownhome borninstate, ///
by(north, total ixtitle ixaxes iyaxes iytitle)

cap命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cap noi{
di "cap命令会一直运行直到遇见错误"
di "在那时,结果窗口就会显示错误并停止运行"
a_error!
di "这条命令不会被执行,因为一旦报错,cap命令就直接跳到了括号外边,结束运行"
}
set seed 1020
clear all
set obs 100
local num_var = rpoission(50)
cap forvalues i = 1 (1) `num_var' {
gen var_`i' = `i'*rnormal()
}
di _rc
cap //这是为了把_rc设定为0

cdout——打开当前工作目录

1
2
. cdout
/Users/mr.cheng/Desktop

center命令(标准化和中心化处理)

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
. * ssc install center

. clear all

. sysuse auto, clear
(1978 Automobile Data)

. * 中心化

. center mpg, gen(centered_mpg)
(generated variables: centered_mpg)

. center mpg price weight
(generated variables: c_mpg c_price c_weight)

. * 按照特定要求中心化

. bysort rep78: center mpg price weight, replace
(generated variables: c_mpg c_price c_weight)

. * 标准化

. center mpg price weight, prefix(z_) standardize
(generated variables: z_mpg z_price z_weight)

. sum *mpg

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
mpg | 74 21.2973 5.785503 12 41
centered_mpg | 74 7.73e-07 5.785503 -9.297297 19.7027
c_mpg | 74 5.93e-07 5.093626 -10.36364 13.63636
z_mpg | 74 1.30e-07 1 -1.606999 3.40553

cf&cf2比较内存数据集和工作目录中的数据集的差异

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* Setup
sysuse auto, clear
drop gear_ratio
replace mpg = 20 in 1/2
replace rep78 = 6 in 3
save mycf, replace
sysuse auto, clear
* 比较内存数据集和工作目录中的数据集的差异
cf _all using mycf

* 比较并列示具体的差异
cf _all using mycf, verbose
* 比较两个变量
cf mpg foreign using mycf
cf mpg foreign using mycf, verbose
* Same as above, but list all specified variables, even if there are no differences
cf mpg foreign using mycf, verbose all
cf2 _all using mycf, sortvars(mpg)

char——产生副变量名

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
. sysuse auto, clear
(1978 Automobile Data)

. char make[varname] "变量1"

. char price[varname] "变量2"

. char weight[varname] "变量3"

. list make price weight in 1/10, sep(0)

+---------------------------------+
| make price weight |
|---------------------------------|
1. | AMC Concord 4,099 2,930 |
2. | AMC Pacer 4,749 3,350 |
3. | AMC Spirit 3,799 2,640 |
4. | Buick Century 4,816 3,250 |
5. | Buick Electra 7,827 4,080 |
6. | Buick LeSabre 5,788 3,670 |
7. | Buick Opel 4,453 2,230 |
8. | Buick Regal 5,189 3,280 |
9. | Buick Riviera 10,372 3,880 |
10. | Buick Skylark 4,082 3,400 |
+---------------------------------+

. list make price weight in 1/10, sep(0) subvarname

+--------------------------------+
| 变量1 变量2 变量3 |
|--------------------------------|
1. | AMC Concord 4,099 2,930 |
2. | AMC Pacer 4,749 3,350 |
3. | AMC Spirit 3,799 2,640 |
4. | Buick Century 4,816 3,250 |
5. | Buick Electra 7,827 4,080 |
6. | Buick LeSabre 5,788 3,670 |
7. | Buick Opel 4,453 2,230 |
8. | Buick Regal 5,189 3,280 |
9. | Buick Riviera 10,372 3,880 |
10. | Buick Skylark 4,082 3,400 |
+--------------------------------+

charlist——列出某个变量包含的全部字符

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
. sysuse auto, clear
(1978 Automobile Data)

. charlist make
-.0123456789ABCDEFGHILMNOPRSTVWXZabcdefghiklmnopqrstuvwxyz

. charlist make if foreign
01234568ABCDFGHLMPRSTVWabcdeghilnorstuvxyz

. return list

macros:
r(chars) : "01234568ABCDFGHLMPRSTVWabcdeghilnorstuvxyz"
r(sepchars) : "0 1 2 3 4 5 6 8 A B C D F G H L M P R S T V W a .."
r(ascii) : "32 48 49 50 51 52 53 54 56 65 66 67 68 70 71 72 .."

chernoff:脸谱图

  • 安装

    net install gr0038.pkg, from(“http://www.stata-journal.com/software/sj9-3/")

  • 面部特征

  • isize(exp) 眼睛的大小
  • iangle(exp) 眼睛的角度
  • ihor(exp) 眼睛的水平位置
  • ivert(exp) 眼睛的竖直位置
  • psize(exp) 瞳孔大小
  • ppos(exp) 瞳孔的位置
  • bcurv(exp) 眉毛的弯曲度
  • bdens(exp) 眉毛的密度
  • bhor(exp) 眉毛的水平位置
  • bvert(exp) 眉毛的竖直位置
  • fline(exp) 面部线
  • hupper(exp) 头发上界线
  • hlower(exp) 头发下界线
  • hdark(exp) 头发黑度
  • hslant(exp) 头发遮阳斜度
  • nose(exp) 鼻线
  • msize(exp) 鼻子的大小
  • mcurv(exp) 嘴巴弯曲度
1
2
3
4
5
6
7
sysuse auto, clear
drop if rep78 == .
drop if mpg == .
drop if weight == .
keep in 41/45
chernoff, isize(rep78) hdark(mpg) hslant(mpg) fline(weight) ///
order(foreign price) saving(face1, replace)

1
2
3
4
* rhalf: 只绘制右半边脸
* nolabel: 不显示标签
chernoff, isize(rep78, 0) hdark(mpg) hslant(mpg) fline(weight) ///
nose(price) legend(2 nolabel) cols(3) rhalf saving(face2, replace)

1
2
3
4
5
6
gen s = 1 + runiform()
* inote(varname): 指定每个脸谱图的注记
* _null_ prevents a "logical" set of features from being drawn. For example, specifying any eye feature as _null_ will result in eyes not being drawn.
* bvert(_null_):不绘制眉毛
chernoff, isize(rep78, 0) hdark(mpg) hslant(mpg) fline(weight) ///
bvert(_null_) inote(make) iscale(s) saving(mygraph, replace)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
clear
set obs 20
set seed 123245
forval i = 1/18 {
gen x`i' = int(runiform()*100)
local rand = runiform()
if `rand' > .50 label var x`i' "Howdy, I am x`i'!"
}
sort x1 // check sortpreserve
gen mylabel = round(runiform()*1000)

chernoff, isize(x1) iangle(x2) ihor(x3) ivert(x4) psize(x5) ///
ppos(x6) bcurv(x7) bdens(x8) bhor(x9) bvert(x10) ///
hupper(x11) hlower(x12) hdark(x13) hslant(x14) ///
fline(x15) nose(x16) msize(x17) mcurv(x18)ilabel(mylabel) ///
order(mylabel) legend(3) xcomb(12) ycomb(14)

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
cuse utility, clear
tostring id, gen(ids)
gen lbl = state + " / " + ids
chernoff, bdens(kwcost) fline(nuclear) hdark(cover) iangle(load) isize(growth) mcurv(sales) ///
hslant(return) nose(fuel) ilabel(lbl) saveall nocombine
* 下面的这些是添加文本的
twoway pci 0 0 0 0, text(0 0 "Cluster 1", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c1", replace) nodraw xsize(5) ysize(6) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Cluster 2", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c2", replace) nodraw xsize(5) ysize(6) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Cluster 3", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c3", replace) nodraw xsize(5) ysize(6) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Cluster 5", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c5", replace) nodraw xsize(5) ysize(6) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Cluster 7", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c7", replace) nodraw xsize(5) ysize(6) fysize(10)

twoway pci 0 0 0 0, text(-1 0 "Cluster 4", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c4", replace) nodraw xsize(5) ysize(6)
twoway pci 0 0 0 0, text(-1 0 "Cluster 6", size(huge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("c6", replace) nodraw xsize(5) ysize(6)

gr combine ///
c1.gph c2.gph c3.gph c5.gph c7.gph ///
FACE4.gph FACE1.gph FACE6.gph FACE5.gph FACE7.gph ///
FACE10.gph FACE3.gph FACE22.gph FACE21.gph FACE15.gph ///
FACE13.gph FACE9.gph c4.gph c6.gph FACE0.gph ///
FACE20.gph FACE14.gph FACE8.gph FACE2.gph FACE0.gph ///
FACE0.gph FACE18.gph FACE11.gph FACE12.gph FACE0.gph ///
FACE0.gph FACE19.gph FACE16.gph FACE17.gph FACE0.gph ///
, rows(8) scheme(s1mono) xsize(10) ysize(16)

1
2
3
4
5
6
cuse flu, clear
replace flu = 100-flu // invert the scale
drop in L
gen byte enlarge = 2
chernoff, is(flu) ia(flu) ih(flu) iv(flu) ps(flu) pp(flu) bc(flu) bd(flu) bh(flu) bv(flu) fl(flu) ///
hu(flu) hl(flu) no(flu) ms(flu) mc(flu) hd(flu) hs(flu) ilab(lbl) isc(enlarge) rh rows(1) hspace(.5)

1
2
3
4
5
6
cuse flu, clear
replace flu = 100-flu // invert the scale
drop in 1
gen byte enlarge = 2
chernoff, is(flu) ia(flu) ih(flu) iv(flu) ps(flu) pp(flu) bc(flu) bd(flu) bh(flu) bv(flu) fl(flu) ///
hu(flu) hl(flu) no(flu) ms(flu) mc(flu) hd(flu) hs(flu) ilab(lbl) isc(enlarge) rh rows(1) hspace(.5)

1
2
3
4
5
6
7
8
9
10
11
12
13
cuse flu, clear
replace flu = 100-flu // invert the scale
drop in L
gen byte enlarge = 2
chernoff, is(flu) ia(flu) ih(flu) iv(flu) ps(flu) pp(flu) bc(flu) bd(flu) bh(flu) bv(flu) fl(flu) ///
hu(flu) hl(flu) no(flu) ms(flu) mc(flu) hd(flu) hs(flu) ilab(lbl) isc(enlarge) rh rows(1) hspace(.5) gmin(0) gmax(100)

cuse flu, clear
replace flu = 100-flu // invert the scale
drop in 1
gen byte enlarge = 2
chernoff, is(flu) ia(flu) ih(flu) iv(flu) ps(flu) pp(flu) bc(flu) bd(flu) bh(flu) bv(flu) fl(flu) ///
hu(flu) hl(flu) no(flu) ms(flu) mc(flu) hd(flu) hs(flu) ilab(lbl) isc(enlarge) rh rows(1) hspace(.5) gmin(0) gmax(100)

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
/***** clean up *****/
fs *.gph
foreach f in `r(files)' {
erase `f'
}
clear
set obs 24
set seed 5432123
* generate data points
forval i = 1/17 {
if `i' > 15 gen x`i' = round(runiform()*20 + 30) // [20, 50]
else gen x`i' = round(runiform()*40 + 30) // [40, 70]
}
gen x18 = rnormal(1000000,200000)

gen market = "San Francisco"
replace market = "Houston" in 7/12
replace market = "Atlanta" in 13/18
replace market = "Seattle" in 19/L

* generate title
gen str13 mytitle = ""
replace mytitle = "San Francisco" in 1
replace mytitle = "Houston" in 7
replace mytitle = "Atlanta" in 13
replace mytitle = "Seattle" in 19

gen byte year = 7
egen month = seq(), from(1) to(6)
replace year = 8 if month > 4
replace month = 1 if month==5
replace month = 2 if month==6
tostring month, gen(quarter)
replace quarter = "Q" + quarter

* generate note
tostring year, gen(yr)
gen time = quarter + "/0" + yr

************ add and plot min and max faces

set obs 26
summ x1
local min = r(min) // temp minimum score
forval i = 1/17 {
summ x`i'
if r(min) < `min' local min = r(min)
}
forval i = 1/17 {
replace x`i' = `min' in 25
replace x`i' = 75 in 26
}
summ x18
replace x18 = r(min) in 25
replace x18 = r(max) in 26

* use a new label variable, do not use the time variable as label
gen str7 mylbl = ""
qui replace mylbl = "min" in 25
qui replace mylbl = "max" in 26

* save all faces
chernoff, isize(x1) psize(x2) ppos(x3) iangle(x4) ihor(x5) ivert(x6) bcurv(x7) bdens(x8) bhor(x9) ///
bvert(x10) nose(x11) msize(x12) mcurv(x13) hupper(x14) hlower(x15) hdark(x16) hslant(x17) fline(x18) ///
ilabel(mylbl) order(market year quarter) rows(4) nocombine saveall

* generate market name graphs
twoway pci 0 0 0 0, text(0 0 "Atlanta market", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("atl", replace) nodraw xsize(5) ysize(6.8) fxsize(100) fysize(100)
twoway pci 0 0 0 0, text(0 0 "Houston market", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("hou", replace) nodraw xsize(5) ysize(6.8) fxsize(100) fysize(100)
twoway pci 0 0 0 0, text(0 0 "San Francisco" "market", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("san", replace) nodraw xsize(5) ysize(6.8) fxsize(100) fysize(100)
twoway pci 0 0 0 0, text(0 0 "Seattle market", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("sea", replace) nodraw xsize(5) ysize(6.8) fxsize(100) fysize(100)

* generate time graphs, shrink the y-axis
twoway pci 0 0 0 0, text(0 0 "Q3/2007", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("q307", replace) nodraw xsize(5) ysize(6.8) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Q4/2007", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("q407", replace) nodraw xsize(5) ysize(6.8) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Q1/2008", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("q108", replace) nodraw xsize(5) ysize(6.8) fysize(10)
twoway pci 0 0 0 0, text(0 0 "Q2/2008", size(vlarge)) lcolor(white) xscale(off) yscale(off) ///
plotregion(color(white)) scheme(s1mono) saving("q208", replace) nodraw xsize(5) ysize(6.8) fysize(10)

* combine all the graphs, can use either FACE0.gph or holes()
graph combine ///
q307.gph q407.gph q108.gph q208.gph ///
/* FACE0.gph */ atl.gph FACE5.gph FACE6.gph FACE7.gph FACE8.gph ///
FACE2.gph hou.gph FACE11.gph FACE12.gph FACE13.gph FACE14.gph ///
FACE1.gph san.gph FACE17.gph FACE18.gph FACE19.gph FACE20.gph ///
/* FACE0.gph */ sea.gph FACE23.gph FACE24.gph FACE25.gph FACE26.gph, ///
holes(1 2 7 25) rows(5) plotregion(color(white)) scheme(s1mono) xsize(5) ysize(4.1)

1
2
3
4
5
/***************************** clean up *****/
fs *.gph
foreach f in `r(files)' {
erase `f'
}
# Stata

评论

程振兴

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

Your browser is out-of-date!

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

×