Commit
·
aef4ebe
1
Parent(s):
3403298
add 40
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- 40/paper.pdf +3 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/4_1_Allocation_Attention.do +147 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/4_1_Passive_Behavior.do +183 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/4_2_Cognitive_Spillover.do +246 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/4_2_Interventions_targeted_domain.do +237 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/4_3_Payoffs_And_Efficiency.do +224 -0
- 40/replication_package/EmpiricalAnalysis/dofiles/Supplementary_Material_Randomization_Check_table.do +143 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_eststo.ado +28 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_eststo.hlp +1 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_gpp.ado +24 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_oaxaca.ado +1505 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/b/binscatter.ado +1048 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/b/binscatter.sthlp +332 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/backup.trk +447 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/cdfplot.ado +156 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/cdfplot.hlp +139 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/coefplot.ado +0 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/coefplot.sthlp +1751 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estadd.ado +2463 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estadd.hlp +935 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estout.ado +0 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estout.hlp +0 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estpost.ado +1839 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estpost.hlp +1322 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/eststo.ado +343 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/eststo.hlp +347 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/esttab.ado +1209 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/esttab.hlp +918 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/figout.ado +97 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/figout.hlp +119 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm.ado +589 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm.hlp +240 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_gamma_lf.ado +243 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_gamma_p.ado +93 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_lognormal_lf.ado +243 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_lognormal_p.ado +89 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin1_lf.ado +255 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin1_p.ado +104 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin2_lf.ado +253 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin2_p.ado +104 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_normal_lf.ado +244 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_normal_p.ado +92 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_poisson_lf.ado +174 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_poisson_p.ado +91 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_postestimation.hlp +149 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_studentt_lf.ado +255 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_studentt_p.ado +91 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/gammareg_lf.ado +41 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/glcurve.ado +203 -0
- 40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/glcurve.hlp +242 -0
40/paper.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:af0ab0d5bc0ac7aa3bfaff2d3526d4c13baa20f05d3afa3f01a936d169d5f483
|
3 |
+
size 651096
|
40/replication_package/EmpiricalAnalysis/dofiles/4_1_Allocation_Attention.do
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Do file creates Tables and Figures for first part of Section 4.1 of the paper and tables and figures referenced therein*/
|
2 |
+
|
3 |
+
log using `"${PATH_OUT}/4_1_Allocation_Attention.log"', replace
|
4 |
+
|
5 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
6 |
+
|
7 |
+
|
8 |
+
********* Descriptive Figues Attention Allocation
|
9 |
+
|
10 |
+
*Individual Decision level
|
11 |
+
cdfplot Attention if Treatment_Environment==1 ,by(Treatment_Incentives) opt1(lwidth(medthick medthick medthick medthick) lc(gs0 gs7 gs11 gs13) ///
|
12 |
+
xtitle("attention (in sec.)") ///
|
13 |
+
legend(label(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10") ///
|
14 |
+
label(2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20") ///
|
15 |
+
label(3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40") ///
|
16 |
+
label(4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'") )) ///
|
17 |
+
ytitle("Cumulative Frequency", margin(medium) height(3) size(medium)) xtitle("Attention (in sec.)", margin(medium) height(3) size(medium))
|
18 |
+
graph export `"${PATH_OUT}/figure2.png"', as(png) replace
|
19 |
+
|
20 |
+
* Individual average level
|
21 |
+
cdfplot attention_mean if Treatment_Environment==1 ,by(Treatment_Incentives) opt1(lwidth(medthick medthick medthick medthick) lc(gs0 gs7 gs11 gs13) ///
|
22 |
+
xtitle("Attention (in sec.)") ///
|
23 |
+
legend(label(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10") ///
|
24 |
+
label(2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20") ///
|
25 |
+
label(3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40") ///
|
26 |
+
label(4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'") )) ///
|
27 |
+
ytitle("Cumulative Frequency", margin(medium) height(3) size(medium)) xtitle("Attention (in sec.)", margin(medium) height(3) size(medium))
|
28 |
+
graph export `"${PATH_OUT}/figureO_1.png"', as(png) replace
|
29 |
+
|
30 |
+
*Individual Decision level; Low Raven Score
|
31 |
+
cdfplot Attention if Treatment_Environment==1 & raven_score_median==1,by(Treatment_Incentives) opt1(lwidth(medthick medthick medthick medthick) lc(gs0 gs7 gs11 gs13) ///
|
32 |
+
xtitle("Attention (in sec.)") ///
|
33 |
+
legend(label(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10") ///
|
34 |
+
label(2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20") ///
|
35 |
+
label(3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40") ///
|
36 |
+
label(4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'") )) ///
|
37 |
+
ytitle("Cumulative Frequency", margin(medium) height(3) size(medlarge)) xtitle("Attention (in sec.)", margin(medium) height(3) size(medlarge))
|
38 |
+
graph export `"${PATH_OUT}/figureB_1a.png"', as(png) replace
|
39 |
+
|
40 |
+
*Individual Decision level; High Raven Score
|
41 |
+
cdfplot Attention if Treatment_Environment==1 & raven_score_median==2,by(Treatment_Incentives) opt1(lwidth(medthick medthick medthick medthick) lc(gs0 gs7 gs11 gs13) ///
|
42 |
+
xtitle("Attention (in sec.)") ///
|
43 |
+
legend(label(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10") ///
|
44 |
+
label(2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20") ///
|
45 |
+
label(3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40") ///
|
46 |
+
label(4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'") )) ///
|
47 |
+
ytitle("Cumulative Frequency", margin(medium) height(3) size(medlarge)) xtitle("Attention (in sec.)", margin(medium) height(3) size(medlarge))
|
48 |
+
graph export `"${PATH_OUT}/figureB_1b.png"', as(png) replace
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
* Summary statistics and non-parametric tests for numbers reported in the text
|
53 |
+
tabstat Attention if Treatment_Environment ==1 , by(Treatment_Incentives) stats(mean n)
|
54 |
+
|
55 |
+
ksmirnov Attention if Treatment_Environment==1 & Treatment_Incentives==1 | Treatment_Incentives==4, by(Treatment_Incentives)
|
56 |
+
|
57 |
+
spearman attention_mean Treatment_Incentives if round==1 & Treatment_Environment==1
|
58 |
+
|
59 |
+
tabstat no_attention if Treatment_Environment ==1 , by(Treatment_Incentives) stats(mean n)
|
60 |
+
|
61 |
+
spearman attention_positive_mean Treatment_Incentives if round==1 & Treatment_Environment==1
|
62 |
+
|
63 |
+
|
64 |
+
************Regression Table Average Attention, Extensive Margin + Choice Quality
|
65 |
+
reg Attention i.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 , cluster(subject_id) robust
|
66 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
67 |
+
estadd scalar p_2_3 = r(p)
|
68 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
69 |
+
estadd scalar p_2_4 = r(p)
|
70 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
71 |
+
estadd scalar p_3_4 = r(p)
|
72 |
+
eststo plain_attention
|
73 |
+
|
74 |
+
|
75 |
+
reg Attention i.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 , cluster(subject_id) robust
|
76 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
77 |
+
estadd scalar p_2_3 = r(p)
|
78 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
79 |
+
estadd scalar p_2_4 = r(p)
|
80 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
81 |
+
estadd scalar p_3_4 = r(p)
|
82 |
+
eststo all_control_attention
|
83 |
+
|
84 |
+
reg no_attention i.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 , cluster(subject_id) robust
|
85 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
86 |
+
estadd scalar p_2_3 = r(p)
|
87 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
88 |
+
estadd scalar p_2_4 = r(p)
|
89 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
90 |
+
estadd scalar p_3_4 = r(p)
|
91 |
+
eststo plain_attention_pos
|
92 |
+
|
93 |
+
reg no_attention i.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 , cluster(subject_id) robust
|
94 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
95 |
+
estadd scalar p_2_3 = r(p)
|
96 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
97 |
+
estadd scalar p_2_4 = r(p)
|
98 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
99 |
+
estadd scalar p_3_4 = r(p)
|
100 |
+
eststo all_control_attention_pos
|
101 |
+
|
102 |
+
|
103 |
+
*Regressions Decision Quality
|
104 |
+
reg summation_correct i.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 , cluster(subject_id) robust
|
105 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
106 |
+
estadd scalar p_2_3 = r(p)
|
107 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
108 |
+
estadd scalar p_2_4 = r(p)
|
109 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
110 |
+
estadd scalar p_3_4 = r(p)
|
111 |
+
eststo plain_sum
|
112 |
+
|
113 |
+
reg summation_correct i.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 , cluster(subject_id) robust
|
114 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
115 |
+
estadd scalar p_2_3 = r(p)
|
116 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
117 |
+
estadd scalar p_2_4 = r(p)
|
118 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
119 |
+
estadd scalar p_3_4 = r(p)
|
120 |
+
eststo all_control_sum
|
121 |
+
|
122 |
+
|
123 |
+
esttab plain_attention all_control_attention ///
|
124 |
+
plain_attention_pos all_control_attention_pos ///
|
125 |
+
plain_sum all_control_sum ///
|
126 |
+
using `"${PATH_OUT}/tableB_1.tex"', replace ///
|
127 |
+
b(%5.3f) se(%5.3f) ///
|
128 |
+
order() ///
|
129 |
+
star(* .1 ** .05 *** .01) ///
|
130 |
+
label booktabs nonotes ///
|
131 |
+
noomit nobase ///
|
132 |
+
nomtitles ///
|
133 |
+
mgroups("Avg. Attention" "Attention\,$=$\,0" "Choice Quality", ///
|
134 |
+
pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
135 |
+
stats(N N_clust r2 p_2_3 p_2_4 p_3_4, fmt(%18.0g %18.0g %5.3f %5.3f) labels(`"N"' "No. Subjects" "\(R^2\)" "\textsc{Baseline-20}=\textsc{Baseline-40}" "\textsc{Baseline-20}=\textsc{Baseline-A.}" "\textsc{Baseline-40}=\textsc{Baseline-A.}")) ///
|
136 |
+
indicate("Controls = *original* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
* Summary statistics and non-parametric tests for reported in the text
|
141 |
+
|
142 |
+
tabstat summation_correct_mean if Treatment_Environment ==1 , by(Treatment_Incentives) stats(mean n)
|
143 |
+
|
144 |
+
spearman summation_correct_mean Treatment_Incentives_Baseline_sc if round==1 & Treatment_Environment==1
|
145 |
+
|
146 |
+
|
147 |
+
log close
|
40/replication_package/EmpiricalAnalysis/dofiles/4_1_Passive_Behavior.do
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Do file creates Tables and Figures for second part of Section 4.2 of the paper and tables and figures referenced therein*/
|
2 |
+
|
3 |
+
|
4 |
+
log using `"${PATH_OUT}/4_1_Passive_Behavior.log"', replace
|
5 |
+
|
6 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
tabstat default_followed if Treatment_Environment==1, by(Treatment_Incentives) stats(N mean)
|
12 |
+
|
13 |
+
spearman default_followed_mean Treatment_Incentives if round==1 & Treatment_Environment==1
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
* Overall Barchart Figure 3 (a)
|
18 |
+
forvalues i=1(1)4{
|
19 |
+
reg default_followed i.Treatment_Incentives if Treatment_Environment==1 , cluster(subject_id) robust
|
20 |
+
margins i.Treatment_Incentives if Treatment_Incentives==`i', post
|
21 |
+
eststo plain_att_`i'
|
22 |
+
}
|
23 |
+
|
24 |
+
coefplot (plain_att_1, bcolor(gs0)) (plain_att_2, bcolor(gs7)) (plain_att_3, bcolor(gs11)) (plain_att_4, bcolor(gs13)) , vertical recast(bar) noci ///
|
25 |
+
xlabel(1 "Baseline-10" 2 "Baseline-20" 3 "Baseline-40" 4 "Baseline- A.", labgap(3) labsize(medlarge)) ytitle("Default Adherence", margin(medium) height(3) size(medlarge)) ylabel(0(0.1)1,glcolor(gs13)) ///
|
26 |
+
barwidth(0.75) graphregion(color(white)) bgcolor(white) ///
|
27 |
+
offset(0) ///
|
28 |
+
coeflabels(,nolabels notick) ///
|
29 |
+
legend(label(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10") ///
|
30 |
+
label(2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20") ///
|
31 |
+
label(3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40") ///
|
32 |
+
label(4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'") ) ///
|
33 |
+
groups(*Treatment_Incentives* = `"Default incorrect"', labcolor(white) labsize(medlarge))
|
34 |
+
|
35 |
+
graph export `"${PATH_OUT}/figure3a.png"', as(png) replace
|
36 |
+
|
37 |
+
|
38 |
+
* By Default correct Barchart Figure 3 (b)
|
39 |
+
forvalues j=1(1)4{
|
40 |
+
forvalues i=0(1)1{
|
41 |
+
reg default_followed i.Treatment_Incentives#i.default_correct_choice if Treatment_Environment==1 , cluster(subject_id) robust
|
42 |
+
margins i.Treatment_Incentives#i.default_correct_choice if default_correct_choice==`i' & Treatment_Incentives==`j', post
|
43 |
+
eststo plain_att_`i'_`j'
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
coefplot (plain_att_0_1, bcolor(gs0)) (plain_att_0_2, bcolor(gs7)) (plain_att_0_3, bcolor(gs11)) (plain_att_0_4, bcolor(gs13)) ///
|
48 |
+
(plain_att_1_1, bcolor(gs0)) (plain_att_1_2, bcolor(gs7)) (plain_att_1_3, bcolor(gs11)) (plain_att_1_4, bcolor(gs13)) ///
|
49 |
+
, offset(0) vertical recast(bar) noci ///
|
50 |
+
coeflabels(,nolabels notick) ///
|
51 |
+
ytitle("Default Adherence", margin(medium) height(3) size(medlarge)) ylabel(0(0.1)1,glcolor(gs13)) ///
|
52 |
+
barwidth(0.75) graphregion(color(white)) bgcolor(white) ///
|
53 |
+
legend(order(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-10" ///
|
54 |
+
2 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-20" ///
|
55 |
+
3 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-40" ///
|
56 |
+
4 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'-A`=ustrunescape("\u1D0D")'`=ustrunescape("\u1D18")'`=ustrunescape("\u029F")'`=ustrunescape("\u1D07")'")) ///
|
57 |
+
nooffset groups(*0.default_correct_choice* = `"Default incorrect"' *1.default_correct_choice* = "Default correct", labsize(medlarge))
|
58 |
+
|
59 |
+
graph export `"${PATH_OUT}/figure3b.png"', as(png) replace
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
*********************************************
|
65 |
+
*By default correct
|
66 |
+
*********************************************
|
67 |
+
tabstat default_followed if Treatment_Environment==1 & default_correct_choice==0, by(Treatment_Incentives) stats(N mean)
|
68 |
+
tabstat default_followed if Treatment_Environment==1 & default_correct_choice==1, by(Treatment_Incentives) stats(N mean)
|
69 |
+
|
70 |
+
|
71 |
+
*Default_followed_correct_mean is calculated using "bysort subject_id default_correct_choice:"; Round 1 Default is correct and therefore use mean from that round
|
72 |
+
spearman default_followed_correct_mean Treatment_Incentives if round==1 & Treatment_Environment==1
|
73 |
+
*Explanation see above, round 2 default happens to be false.
|
74 |
+
spearman default_followed_correct_mean Treatment_Incentives if round==2 & Treatment_Environment==1
|
75 |
+
|
76 |
+
|
77 |
+
******************************************************************************************
|
78 |
+
*By Raven
|
79 |
+
******************************************************************************************
|
80 |
+
tabstat default_followed if Treatment_Environment==1 & raven_score_median==1, by(Treatment_Incentives) stats(N mean)
|
81 |
+
tabstat default_followed if Treatment_Environment==1 & raven_score_median==2, by(Treatment_Incentives) stats(N mean)
|
82 |
+
|
83 |
+
spearman default_followed_mean Treatment_Incentives if round==1 &raven_score_median==1 & Treatment_Environment==1
|
84 |
+
spearman default_followed_mean Treatment_Incentives if round==1 &raven_score_median==2 & Treatment_Environment==1
|
85 |
+
spearman default_followed_mean Treatment_Incentives if round==1 &raven_score_quartiles==4 & Treatment_Environment==1
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
*Regression Table
|
100 |
+
reg default_followed i.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 , cluster(subject_id) robust
|
101 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
102 |
+
estadd scalar p_2_3 = r(p)
|
103 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
104 |
+
estadd scalar p_2_4 = r(p)
|
105 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
106 |
+
estadd scalar p_3_4 = r(p)
|
107 |
+
eststo plain_default
|
108 |
+
|
109 |
+
reg default_followed i.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 , cluster(subject_id) robust
|
110 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
111 |
+
estadd scalar p_2_3 = r(p)
|
112 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
113 |
+
estadd scalar p_2_4 = r(p)
|
114 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
115 |
+
estadd scalar p_3_4 = r(p)
|
116 |
+
eststo all_control_default
|
117 |
+
|
118 |
+
forvalues i=0(1)1{
|
119 |
+
|
120 |
+
reg default_followed i.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 & default_correct_choice==`i', cluster(subject_id) robust
|
121 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
122 |
+
estadd scalar p_2_3 = r(p)
|
123 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
124 |
+
estadd scalar p_2_4 = r(p)
|
125 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
126 |
+
estadd scalar p_3_4 = r(p)
|
127 |
+
eststo plain_default_`i'
|
128 |
+
|
129 |
+
reg default_followed i.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 & default_correct_choice==`i' , cluster(subject_id) robust
|
130 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
131 |
+
estadd scalar p_2_3 = r(p)
|
132 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
133 |
+
estadd scalar p_2_4 = r(p)
|
134 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
135 |
+
estadd scalar p_3_4 = r(p)
|
136 |
+
eststo all_control_default_`i'
|
137 |
+
}
|
138 |
+
|
139 |
+
|
140 |
+
************Raven
|
141 |
+
forvalues i=1(1)2 {
|
142 |
+
reg default_followed i.b1.raven_score_median i.b1.Treatment_Incentives_Baseline_sc if Treatment_Environment==1 & raven_score_median==`i' , cluster(subject_id) robust
|
143 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
144 |
+
estadd scalar p_2_3 = r(p)
|
145 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
146 |
+
estadd scalar p_2_4 = r(p)
|
147 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
148 |
+
estadd scalar p_3_4 = r(p)
|
149 |
+
eststo raven_plain_default_`i'
|
150 |
+
|
151 |
+
reg default_followed i.b1.raven_score_median i.b1.Treatment_Incentives_Baseline_sc ${Wave_control} ${Ability_control} ${Controls} if Treatment_Environment==1 & raven_score_median==`i' , cluster(subject_id) robust
|
152 |
+
test 2.Treatment_Incentives_Baseline_sc=3.Treatment_Incentives_Baseline_sc
|
153 |
+
estadd scalar p_2_3 = r(p)
|
154 |
+
test 2.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
155 |
+
estadd scalar p_2_4 = r(p)
|
156 |
+
test 3.Treatment_Incentives_Baseline_sc=4.Treatment_Incentives_Baseline_sc
|
157 |
+
estadd scalar p_3_4 = r(p)
|
158 |
+
eststo raven_all_control_default_`i'
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
|
163 |
+
esttab plain_default all_control_default ///
|
164 |
+
plain_default_0 all_control_default_0 ///
|
165 |
+
plain_default_1 all_control_default_1 ///
|
166 |
+
raven_plain_default_1 raven_all_control_default_1 ///
|
167 |
+
raven_plain_default_2 raven_all_control_default_2 ///
|
168 |
+
using `"${PATH_OUT}/tableB_2.tex"', replace ///
|
169 |
+
b(%5.3f) se(%5.3f) ///
|
170 |
+
order() star(* .1 ** .05 *** .01) ///
|
171 |
+
label booktabs nonotes noomit nobase nomtitles ///
|
172 |
+
mgroups("Overall" "Default incorrect" "Default correct" "Raven Low" "Raven High", ///
|
173 |
+
pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
174 |
+
stats(N N_clust r2 p_2_3 p_2_4 p_3_4, fmt(%18.0g %18.0g %5.3f %5.3f) labels("N" "No. Subjects" "\(R^2\)" "\textsc{Baseline-20}=\textsc{Baseline-40}" "\textsc{Baseline-20}=\textsc{Baseline-A.}" "\textsc{Baseline-40}=\textsc{Baseline-A.}")) ///
|
175 |
+
indicate("Controls = *original* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
176 |
+
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
+
log close
|
40/replication_package/EmpiricalAnalysis/dofiles/4_2_Cognitive_Spillover.do
ADDED
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*/
|
3 |
+
|
4 |
+
log using `"${PATH_OUT}/4_2_Cognitive_Spillover.log"', replace
|
5 |
+
|
6 |
+
|
7 |
+
*************** FIRST ESTIMATION RESULTS FORM ONLINE EXPEIRMENT! ******************
|
8 |
+
use "${PATH_IN_DATA}/formatted_data_long_mturk.dta", clear
|
9 |
+
|
10 |
+
eststo clear
|
11 |
+
foreach var of varlist math_time math_task_correct passive_choice memory payoff_share {
|
12 |
+
|
13 |
+
reg `var' i.Treatment_intervention, cluster(subject_id)
|
14 |
+
eststo p_`var'
|
15 |
+
|
16 |
+
reg `var' i.Treatment_intervention window_height1 window_width1 age i.gender, cluster(subject_id)
|
17 |
+
eststo c_`var'
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
esttab * ///
|
22 |
+
using `"${PATH_OUT}/tableO_10.tex"', replace ///
|
23 |
+
b(%5.3f) se(%5.3f) ///
|
24 |
+
star(* .1 ** .05 *** .01) ///
|
25 |
+
label booktabs nonotes ///
|
26 |
+
nodepvars nobase ///
|
27 |
+
nomtitles ///
|
28 |
+
mgroups("Avg. Attention" "\shortstack{Choice Quality \\ (Decision Task)}" "Default Adherence" "\shortstack{Choice Quality \\ (Background Task)}" "Payoff Share" , ///
|
29 |
+
pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
30 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %9.2g) labels("N" "No. Subjects" "\(R^2\)")) ///
|
31 |
+
indicate("Controls = *age* *gender* *window*")
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
cdfplot math_time ,by(Treatment_intervention) opt1(lwidth(medthick)) ///
|
36 |
+
legend(label(1 "Baseline") label(2 "Intervention")) ///
|
37 |
+
ytitle("Cumulative Frequency", margin(medium) height(3) size(medium)) ///
|
38 |
+
xtitle("Attention (in sec.)", margin(medium) height(3) size(medium)) ///
|
39 |
+
legend(order(1 "B`=ustrunescape("\u1D00")'`=ustrunescape("\uA731")'`=ustrunescape("\u1D07")'`=ustrunescape("\u029F")'`=ustrunescape("\u026A")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D07")'" ///
|
40 |
+
2 "`=ustrunescape("\u0049")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0280")'`=ustrunescape("\u1D20")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u026A")'`=ustrunescape("\u1D0F")'`=ustrunescape("\u0274")'"))
|
41 |
+
|
42 |
+
graph export `"${PATH_OUT}/figureO_3.png"', as(png) replace
|
43 |
+
|
44 |
+
|
45 |
+
eststo clear
|
46 |
+
|
47 |
+
|
48 |
+
* Generate Estimation results for Table 3 in the main text
|
49 |
+
reg memory i.Treatment_intervention, cluster(subject_id)
|
50 |
+
eststo p_memory
|
51 |
+
|
52 |
+
reg memory i.Treatment_intervention window_height1 window_width1 age i.gender, cluster(subject_id)
|
53 |
+
eststo c_memory
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
*************** MAIN LAB EXPEIRMENT **************
|
58 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
59 |
+
|
60 |
+
* Drop Ample Observations, which are not analyzed in this section.
|
61 |
+
drop if Treatment_Incentives==4
|
62 |
+
|
63 |
+
tabstat load_correct , by(Treatment_intervention)
|
64 |
+
tabstat load_correct , by(Treatment_Environment)
|
65 |
+
|
66 |
+
************************************************************************************
|
67 |
+
************ Background Task Quality
|
68 |
+
************************************************************************
|
69 |
+
|
70 |
+
reg load_correct i.Treatment_intervention , robust cluster(subject_id)
|
71 |
+
eststo force_plain
|
72 |
+
reg load_correct i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , robust cluster(subject_id)
|
73 |
+
eststo force_all_controls_ability
|
74 |
+
|
75 |
+
reg load_correct i.Treatment_Environment , robust cluster(subject_id)
|
76 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
77 |
+
estadd scalar p_treatments = r(p)
|
78 |
+
eststo plain
|
79 |
+
|
80 |
+
reg load_correct i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , robust cluster(subject_id)
|
81 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
82 |
+
estadd scalar p_treatments = r(p)
|
83 |
+
eststo all_controls_ability
|
84 |
+
|
85 |
+
|
86 |
+
esttab force_plain force_all_controls_ability ///
|
87 |
+
plain all_controls_ability ///
|
88 |
+
p_memory c_memory ///
|
89 |
+
using `"${PATH_OUT}/table3.tex"', replace ///
|
90 |
+
b(%5.3f) se(%5.3f) ///
|
91 |
+
star(* .1 ** .05 *** .01) ///
|
92 |
+
label booktabs nonotes ///
|
93 |
+
nodepvars nobase ///
|
94 |
+
nomtitles ///
|
95 |
+
mgroups("Lab Experiment" "Online Experiment" , ///
|
96 |
+
pattern(1 0 0 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
97 |
+
stats(N N_clust r2 p_treatments, fmt(%18.0g %18.0g %5.3f %5.3f) labels(`"N"' "No. Subjects" "\(R^2\)" "\textsc{Directed}=\textsc{Forced}")) ///
|
98 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat* *age* *gender* *window* ")
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
************************************************************************************
|
108 |
+
************ Background Task Quality: HETEROGENEITIES
|
109 |
+
************************************************************************
|
110 |
+
|
111 |
+
***************************
|
112 |
+
******** RAVEN ************
|
113 |
+
***************************
|
114 |
+
|
115 |
+
reg load_correct i.b0.Treatment_intervention#i.bn.raven_score_median i.bn.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust nocons
|
116 |
+
eststo incentives_heterogeneity
|
117 |
+
|
118 |
+
coefplot (incentives_heterogeneity , fcolor(gs8) mcolor(gs8) lcolor(gs8)) , ///
|
119 |
+
vertical lwidth(*1) keep(*Treatment_intervention*) ///
|
120 |
+
ciopts(recast(rcap)lpattern(dash)lwidth(*.6) lcolor(gs0) ) citop ci(95) ///
|
121 |
+
xlabel(, labgap(3) labsize(medium)) ytitle ("Spillover", margin(medium) height(3) size(medium)) ylabel(-.1(0.05).1) ///
|
122 |
+
graphregion(color(white)) yline(0, lcolor(black)) xlabel(1 "Raven Score {&le} Median" 2 "Raven Score {>} Median " )
|
123 |
+
|
124 |
+
graph export `"${PATH_OUT}/figure4.png"', as(png) replace
|
125 |
+
|
126 |
+
|
127 |
+
reg load_correct i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median , cluster(subject_id) robust
|
128 |
+
eststo hetero_force_both_raw
|
129 |
+
|
130 |
+
reg load_correct i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
131 |
+
eststo hetero_force_all
|
132 |
+
|
133 |
+
reg load_correct i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median , cluster(subject_id) robust
|
134 |
+
eststo hetero_both_raw
|
135 |
+
|
136 |
+
reg load_correct i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
137 |
+
eststo hetero_all
|
138 |
+
|
139 |
+
esttab hetero_force_both_raw hetero_force_all ///
|
140 |
+
hetero_both_raw hetero_all ///
|
141 |
+
using `"${PATH_OUT}/tableO_4.tex"', replace ///
|
142 |
+
b(%5.3f) se(%5.3f) ///
|
143 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
144 |
+
star(* .1 ** .05 *** .01) ///
|
145 |
+
label booktabs nonotes ///
|
146 |
+
nodepvars nobase ///
|
147 |
+
nomtitles ///
|
148 |
+
mgroups("Spillover" , ///
|
149 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
150 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f) labels("N" "No. Subjects" "\(R^2\)")) ///
|
151 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat* *age* *gender* ")
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
***************************
|
156 |
+
******** Task Difficulty **
|
157 |
+
***************************
|
158 |
+
|
159 |
+
reg load_correct i.b0.Treatment_intervention#i.bn.high_task_difficulty i.bn.high_task_difficulty ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust nocons
|
160 |
+
eststo incentives_heterogeneity
|
161 |
+
|
162 |
+
coefplot (incentives_heterogeneity , fcolor(gs8) mcolor(gs8) lcolor(gs8)) , ///
|
163 |
+
vertical lwidth(*1) keep(*Treatment_intervention*) ///
|
164 |
+
ciopts(recast(rcap)lpattern(dash)lwidth(*.6) lcolor(gs0) ) citop ci(95) ///
|
165 |
+
xlabel(, labgap(3) labsize(medium)) ytitle ("Spillover", margin(medium) height(3) size(medium)) ///
|
166 |
+
graphregion(color(white)) yline(0, lcolor(black)) xlabel(1 "Difficulty {&le} Median" 2 "Difficulty {>} Median" ) ylabel(-.1(0.05).1)
|
167 |
+
graph export `"${PATH_OUT}/figure5.png"', as(png) replace
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
reg load_correct i.high_task_difficulty i.Treatment_intervention i.Treatment_intervention#i.high_task_difficulty , cluster(subject_id) robust
|
172 |
+
eststo hetero_force_both_raw
|
173 |
+
|
174 |
+
reg load_correct i.high_task_difficulty i.Treatment_intervention i.Treatment_intervention#i.high_task_difficulty ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
175 |
+
eststo hetero_force_all
|
176 |
+
|
177 |
+
reg load_correct i.high_task_difficulty i.Treatment_Environment i.Treatment_Environment#i.high_task_difficulty , cluster(subject_id) robust
|
178 |
+
eststo hetero_both_raw
|
179 |
+
|
180 |
+
reg load_correct i.high_task_difficulty i.Treatment_Environment i.Treatment_Environment#i.high_task_difficulty ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
181 |
+
eststo hetero_all
|
182 |
+
|
183 |
+
esttab hetero_force_both_raw hetero_force_all ///
|
184 |
+
hetero_both_raw hetero_all ///
|
185 |
+
using `"${PATH_OUT}/tableO_5.tex"', replace ///
|
186 |
+
b(%5.3f) se(%5.3f) ///
|
187 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
188 |
+
star(* .1 ** .05 *** .01) ///
|
189 |
+
label booktabs nonotes ///
|
190 |
+
nodepvars nobase ///
|
191 |
+
nomtitles ///
|
192 |
+
mgroups("Spillover" , ///
|
193 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
194 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f) labels("N" "No. Subjects" "\(R^2\)")) ///
|
195 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat* *age* *gender* ")
|
196 |
+
|
197 |
+
|
198 |
+
***************************
|
199 |
+
******** Incentives **
|
200 |
+
***************************
|
201 |
+
|
202 |
+
|
203 |
+
reg load_correct i.b0.Treatment_intervention#i.bn.Treatment_Incentives i.bn.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust nocons
|
204 |
+
eststo incentives_heterogeneity
|
205 |
+
|
206 |
+
coefplot (incentives_heterogeneity , fcolor(gs8) mcolor(gs8) lcolor(gs8)) , ///
|
207 |
+
vertical lwidth(*1) keep(*Treatment_intervention*) ///
|
208 |
+
ciopts(recast(rcap)lpattern(dash)lwidth(*.6) lcolor(gs0) ) citop ci(95) ///
|
209 |
+
xlabel(, labgap(3) labsize(medium)) ytitle ("Spillover", margin(medium) height(3) size(medium)) ///
|
210 |
+
graphregion(color(white)) yline(0, lcolor(black)) ///
|
211 |
+
xlabel( 1 " `=ustrunescape("\u0049")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0280")'`=ustrunescape("\u1D20")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u026A")'`=ustrunescape("\u1D0F")'`=ustrunescape("\u0274")'-10" ///
|
212 |
+
2" `=ustrunescape("\u0049")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0280")'`=ustrunescape("\u1D20")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u026A")'`=ustrunescape("\u1D0F")'`=ustrunescape("\u0274")'-20" ///
|
213 |
+
3" `=ustrunescape("\u0049")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0280")'`=ustrunescape("\u1D20")'`=ustrunescape("\u1D07")'`=ustrunescape("\u0274")'`=ustrunescape("\u1D1B")'`=ustrunescape("\u026A")'`=ustrunescape("\u1D0F")'`=ustrunescape("\u0274")'-40") ///
|
214 |
+
ylabel(-.1(0.05).1)
|
215 |
+
graph export `"${PATH_OUT}/figure6.png"', as(png) replace
|
216 |
+
|
217 |
+
|
218 |
+
reg load_correct i.Treatment_Incentives_Int_sc i.Treatment_intervention i.Treatment_intervention#i.Treatment_Incentives_Int_sc , cluster(subject_id) robust
|
219 |
+
eststo hetero_force_both_raw
|
220 |
+
|
221 |
+
|
222 |
+
reg load_correct i.Treatment_Incentives_Int_sc i.Treatment_intervention i.Treatment_intervention#i.Treatment_Incentives_Int_sc ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
223 |
+
eststo hetero_force_all
|
224 |
+
|
225 |
+
reg load_correct i.Treatment_Incentives_Int_sc i.Treatment_Environment i.Treatment_Environment#i.Treatment_Incentives_Int_sc , cluster(subject_id) robust
|
226 |
+
eststo hetero_both_raw
|
227 |
+
|
228 |
+
reg load_correct i.Treatment_Incentives_Int_sc i.Treatment_Environment i.Treatment_Environment#i.Treatment_Incentives_Int_sc ${Wave_control} ${Ability_control} ${Controls} , cluster(subject_id) robust
|
229 |
+
eststo hetero_all
|
230 |
+
|
231 |
+
esttab hetero_force_both_raw hetero_force_all ///
|
232 |
+
hetero_both_raw hetero_all ///
|
233 |
+
using `"${PATH_OUT}/tableO_6.tex"', replace ///
|
234 |
+
b(%5.3f) se(%5.3f) ///
|
235 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
236 |
+
star(* .1 ** .05 *** .01) ///
|
237 |
+
label booktabs nonotes ///
|
238 |
+
nodepvars nobase ///
|
239 |
+
nomtitles ///
|
240 |
+
mgroups("Spillover" , ///
|
241 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
242 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f) labels("N" "No. Subjects" "\(R^2\)")) ///
|
243 |
+
indicate("Controls = *original* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat* *age* *gender* ")
|
244 |
+
|
245 |
+
|
246 |
+
log close
|
40/replication_package/EmpiricalAnalysis/dofiles/4_2_Interventions_targeted_domain.do
ADDED
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*/
|
3 |
+
|
4 |
+
log using `"${PATH_OUT}/4_2_Interventions_targeted_domain.log"', replace
|
5 |
+
|
6 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
tabstat summation_correct_mean if Treatment_Incentives!=4, by(Treatment_Environment) stats(mean n)
|
13 |
+
|
14 |
+
****************************************************************
|
15 |
+
**** Table 2, Decision Task + Default Adherence
|
16 |
+
****************************************************************
|
17 |
+
|
18 |
+
reg summation_correct i.Treatment_intervention if Treatment_Incentives!=4, robust cluster(subject_id)
|
19 |
+
eststo force_plain
|
20 |
+
reg summation_correct i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
21 |
+
eststo force_all_controls_ability
|
22 |
+
|
23 |
+
reg summation_correct i.Treatment_Environment if Treatment_Incentives!=4, robust cluster(subject_id)
|
24 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
25 |
+
estadd scalar p_treatments = r(p)
|
26 |
+
eststo plain
|
27 |
+
|
28 |
+
reg summation_correct i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
29 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
30 |
+
estadd scalar p_treatments = r(p)
|
31 |
+
eststo all_controls_ability
|
32 |
+
|
33 |
+
reg default_followed i.Treatment_intervention if Treatment_Incentives!=4, robust cluster(subject_id)
|
34 |
+
eststo passive_force_plain
|
35 |
+
reg default_followed i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
36 |
+
eststo passive_force_controls
|
37 |
+
|
38 |
+
reg default_followed i.Treatment_Environment if Treatment_Incentives!=4, robust cluster(subject_id)
|
39 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
40 |
+
estadd scalar p_treatments = r(p)
|
41 |
+
eststo passive_plain
|
42 |
+
|
43 |
+
reg default_followed i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
44 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
45 |
+
estadd scalar p_treatments = r(p)
|
46 |
+
eststo passive_controls
|
47 |
+
|
48 |
+
esttab force_plain force_all_controls_ability ///
|
49 |
+
plain all_controls_ability ///
|
50 |
+
passive_force_plain passive_force_controls ///
|
51 |
+
passive_plain passive_controls ///
|
52 |
+
using `"${PATH_OUT}/table2.tex"', replace ///
|
53 |
+
b(%5.3f) se(%5.3f) ///
|
54 |
+
order(*Treatment_intervention* *Treatment_Environment*) ///
|
55 |
+
star(* .1 ** .05 *** .01) ///
|
56 |
+
label booktabs nonotes ///
|
57 |
+
nodepvars nobase ///
|
58 |
+
nomtitles ///
|
59 |
+
mgroups("Panel (a): Choice Quality" "Panel (b): Default Adherence" , ///
|
60 |
+
pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
61 |
+
stats(N N_clust r2 p_treatments, fmt(%18.0g %18.0g %5.3f %5.3f) labels(`"N"' "No. Subjects" "\(R^2\)" "\textsc{Directed}=\textsc{Forced}")) ///
|
62 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
****************************************************************
|
70 |
+
**** Heterogenous Effects: Incentives
|
71 |
+
****************************************************************
|
72 |
+
|
73 |
+
reg summation_correct i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_intervention#i.Treatment_Incentives if Treatment_Incentives!=4, robust cluster(subject_id)
|
74 |
+
eststo force_plain
|
75 |
+
|
76 |
+
reg summation_correct i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_intervention#i.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
77 |
+
eststo force_all_controls_ability
|
78 |
+
|
79 |
+
reg summation_correct i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_Environment#i.Treatment_Incentives if Treatment_Incentives!=4, robust cluster(subject_id)
|
80 |
+
eststo plain
|
81 |
+
|
82 |
+
reg summation_correct i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_Environment#i.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
83 |
+
eststo all_controls_ability
|
84 |
+
|
85 |
+
reg default_followed i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_intervention#i.Treatment_Incentives if Treatment_Incentives!=4, robust cluster(subject_id)
|
86 |
+
eststo passive_force_plain
|
87 |
+
reg default_followed i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_intervention#i.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
88 |
+
eststo passive_force_controls
|
89 |
+
|
90 |
+
reg default_followed i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_Environment#i.Treatment_Incentives if Treatment_Incentives!=4, robust cluster(subject_id)
|
91 |
+
eststo passive_plain
|
92 |
+
|
93 |
+
reg default_followed i.b1.Treatment_Incentives_Int_sc i.bn.Treatment_Incentives i.Treatment_Environment#i.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
94 |
+
eststo passive_controls
|
95 |
+
|
96 |
+
esttab force_plain force_all_controls_ability ///
|
97 |
+
plain all_controls_ability ///
|
98 |
+
passive_force_plain passive_force_controls ///
|
99 |
+
passive_plain passive_controls ///
|
100 |
+
using `"${PATH_OUT}/tableO_2.tex"', replace ///
|
101 |
+
b(%5.3f) se(%5.3f) ///
|
102 |
+
order(*Treatment_intervention* *Treatment_Environment*) ///
|
103 |
+
star(* .1 ** .05 *** .01) ///
|
104 |
+
label booktabs nonotes ///
|
105 |
+
nodepvars nobase noomit ///
|
106 |
+
interaction("-") ///
|
107 |
+
nomtitles ///
|
108 |
+
mgroups("Panel (a): Choice Quality" "Panel (b): Default Adherence" , ///
|
109 |
+
pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
110 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f ) labels(`"N"' "No. Subjects" "\(R^2\)")) ///
|
111 |
+
indicate("Controls = *original* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
****************************************************************
|
117 |
+
* Heterogenous Effects: Raven Score
|
118 |
+
****************************************************************
|
119 |
+
|
120 |
+
reg summation_correct i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median if Treatment_Incentives!=4, robust cluster(subject_id)
|
121 |
+
eststo force_plain
|
122 |
+
|
123 |
+
reg summation_correct i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median i.b3.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
124 |
+
eststo force_all_controls_ability
|
125 |
+
|
126 |
+
reg summation_correct i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median if Treatment_Incentives!=4, robust cluster(subject_id)
|
127 |
+
eststo plain
|
128 |
+
|
129 |
+
reg summation_correct i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
130 |
+
eststo all_controls_ability
|
131 |
+
|
132 |
+
reg default_followed i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median if Treatment_Incentives!=4, robust cluster(subject_id)
|
133 |
+
eststo passive_force_plain
|
134 |
+
|
135 |
+
reg default_followed i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
136 |
+
eststo passive_force_controls
|
137 |
+
|
138 |
+
reg default_followed i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median if Treatment_Incentives!=4, robust cluster(subject_id)
|
139 |
+
eststo passive_plain
|
140 |
+
|
141 |
+
reg default_followed i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
142 |
+
eststo passive_controls
|
143 |
+
|
144 |
+
esttab force_plain force_all_controls_ability ///
|
145 |
+
plain all_controls_ability ///
|
146 |
+
passive_force_plain passive_force_controls ///
|
147 |
+
passive_plain passive_controls ///
|
148 |
+
using `"${PATH_OUT}/tableO_3.tex"', replace ///
|
149 |
+
b(%5.3f) se(%5.3f) ///
|
150 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
151 |
+
star(* .1 ** .05 *** .01) ///
|
152 |
+
label booktabs nonotes ///
|
153 |
+
nodepvars nobase noomit ///
|
154 |
+
nomtitles ///
|
155 |
+
mgroups("Panel (a): Choice Quality" "Panel (b): Default Adherence" , ///
|
156 |
+
pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
157 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f ) labels(`"N"' "No. Subjects" "\(R^2\)")) ///
|
158 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
+
****************************************************************
|
163 |
+
**** AMPLE
|
164 |
+
****************************************************************
|
165 |
+
|
166 |
+
reg default_followed i.Treatment_intervention if Treatment_Incentives==4, robust cluster(subject_id)
|
167 |
+
eststo def_force_plain
|
168 |
+
reg default_followed i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
169 |
+
eststo def_force_all_controls
|
170 |
+
reg default_followed i.Treatment_Environment if Treatment_Incentives==4, robust cluster(subject_id)
|
171 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
172 |
+
estadd scalar p_treatments = r(p)
|
173 |
+
eststo def_plain
|
174 |
+
reg default_followed i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
175 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
176 |
+
estadd scalar p_treatments = r(p)
|
177 |
+
eststo def_all_controls
|
178 |
+
|
179 |
+
|
180 |
+
reg summation_correct i.Treatment_intervention if Treatment_Incentives==4, robust cluster(subject_id)
|
181 |
+
eststo sum_force_plain
|
182 |
+
reg summation_correct i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
183 |
+
eststo sum_force_all_controls
|
184 |
+
reg summation_correct i.Treatment_Environment if Treatment_Incentives==4, robust cluster(subject_id)
|
185 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
186 |
+
estadd scalar p_treatments = r(p)
|
187 |
+
eststo sum_plain
|
188 |
+
reg summation_correct i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
189 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
190 |
+
estadd scalar p_treatments = r(p)
|
191 |
+
eststo sum_all_controls
|
192 |
+
|
193 |
+
|
194 |
+
|
195 |
+
reg load_correct i.Treatment_intervention if Treatment_Incentives==4, robust cluster(subject_id)
|
196 |
+
eststo back_force_plain
|
197 |
+
reg load_correct i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
198 |
+
eststo back_force_all_controls
|
199 |
+
reg load_correct i.Treatment_Environment if Treatment_Incentives==4, robust cluster(subject_id)
|
200 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
201 |
+
estadd scalar p_treatments = r(p)
|
202 |
+
eststo back_plain
|
203 |
+
reg load_correct i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives==4, robust cluster(subject_id)
|
204 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
205 |
+
estadd scalar p_treatments = r(p)
|
206 |
+
eststo back_all_controls
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
|
211 |
+
esttab ///
|
212 |
+
sum_force_plain sum_force_all_controls ///
|
213 |
+
sum_plain sum_all_controls ///
|
214 |
+
def_force_plain def_force_all_controls ///
|
215 |
+
def_plain def_all_controls ///
|
216 |
+
back_force_plain back_force_all_controls ///
|
217 |
+
back_plain back_all_controls ///
|
218 |
+
using `"${PATH_OUT}/tableO_7.tex"', replace ///
|
219 |
+
b(%5.3f) se(%5.3f) ///
|
220 |
+
star(* .1 ** .05 *** .01) ///
|
221 |
+
label booktabs nonotes ///
|
222 |
+
nodepvars nobase ///
|
223 |
+
nomtitles ///
|
224 |
+
mgroups("Choice Quality (Decision Task)" "Default Adherence" "Choice Quality (Background Task)" , ///
|
225 |
+
pattern(1 0 0 0 1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
226 |
+
stats(N N_clust r2 p_treatments, fmt(%18.0g %18.0g %5.3f %5.3f) labels(`"N"' "No. Subjects" "\(R^2\)" "\textsc{Directed}=\textsc{Forced}")) ///
|
227 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat* *age* *gender*")
|
228 |
+
|
229 |
+
|
230 |
+
|
231 |
+
|
232 |
+
|
233 |
+
|
234 |
+
|
235 |
+
|
236 |
+
|
237 |
+
log close
|
40/replication_package/EmpiricalAnalysis/dofiles/4_3_Payoffs_And_Efficiency.do
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
log using `"${PATH_OUT}/4_3_Payoffs_And_Efficiency.log"', replace
|
2 |
+
|
3 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
reg payoff_share i.Treatment_intervention if Treatment_Incentives!=4, robust cluster(subject_id)
|
8 |
+
eststo force_plain
|
9 |
+
|
10 |
+
reg payoff_share i.Treatment_intervention ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
11 |
+
eststo force_all_controls_ability
|
12 |
+
|
13 |
+
|
14 |
+
reg payoff_share i.Treatment_Environment if Treatment_Incentives!=4, robust cluster(subject_id)
|
15 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
16 |
+
estadd scalar p_treatments = r(p)
|
17 |
+
eststo plain
|
18 |
+
|
19 |
+
reg payoff_share i.Treatment_Environment ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, robust cluster(subject_id)
|
20 |
+
test 2.Treatment_Environment=3.Treatment_Environment
|
21 |
+
estadd scalar p_treatments = r(p)
|
22 |
+
eststo all_controls_ability
|
23 |
+
|
24 |
+
esttab force_plain force_all_controls_ability ///
|
25 |
+
plain all_controls_ability ///
|
26 |
+
using `"${PATH_OUT}/table4.tex"', replace ///
|
27 |
+
b(%5.3f) se(%5.3f) ///
|
28 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
29 |
+
star(* .1 ** .05 *** .01) ///
|
30 |
+
label booktabs nonotes ///
|
31 |
+
nodepvars nobase ///
|
32 |
+
nomtitles ///
|
33 |
+
mgroups("Payoff Share" , ///
|
34 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
35 |
+
stats(N N_clust r2 p_treatments, fmt(%18.0g %18.0g %5.3f %5.3f) labels(`"N"' "No. Subjects" "\(R^2\)" "\textsc{Directed}=\textsc{Forced}")) ///
|
36 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
*** Tables heterogeneity:
|
41 |
+
|
42 |
+
reg payoff_share i.b1.Treatment_Incentives_Int_sc i.b1.Treatment_Incentives i.Treatment_intervention i.Treatment_intervention#i.b1.Treatment_Incentives if Treatment_Incentives!=4 , cluster(subject_id) robust
|
43 |
+
eststo hetero_force_both_raw
|
44 |
+
reg payoff_share i.b1.Treatment_Incentives_Int_sc i.b1.Treatment_Incentives i.Treatment_intervention i.Treatment_intervention#i.b1.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4 , cluster(subject_id) robust
|
45 |
+
eststo hetero_force_all
|
46 |
+
|
47 |
+
reg payoff_share i.b1.Treatment_Incentives_Int_sc i.b1.Treatment_Incentives i.Treatment_Environment i.Treatment_Environment#i.b1.Treatment_Incentives if Treatment_Incentives!=4 , cluster(subject_id) robust
|
48 |
+
eststo hetero_both_raw
|
49 |
+
reg payoff_share i.b1.Treatment_Incentives_Int_sc i.b1.Treatment_Incentives i.Treatment_Environment i.Treatment_Environment#i.b1.Treatment_Incentives ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4 , cluster(subject_id) robust
|
50 |
+
eststo hetero_all
|
51 |
+
|
52 |
+
esttab hetero_force_both_raw hetero_force_all ///
|
53 |
+
hetero_both_raw hetero_all ///
|
54 |
+
using `"${PATH_OUT}/tableO_8.tex"', replace ///
|
55 |
+
b(%5.3f) se(%5.3f) ///
|
56 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
57 |
+
star(* .1 ** .05 *** .01) ///
|
58 |
+
label booktabs nonotes ///
|
59 |
+
nodepvars nobase noomit ///
|
60 |
+
nomtitles ///
|
61 |
+
mgroups("Payoff Share" , ///
|
62 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
63 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f) labels("N" "No. Subjects" "\(R^2\)")) ///
|
64 |
+
indicate("Controls = *original* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
****************************** Coefplots Heterogeneity ******************************
|
69 |
+
|
70 |
+
|
71 |
+
reg payoff_share i.b0.Treatment_intervention#i.bn.raven_score_median i.bn.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, cluster(subject_id) nocons
|
72 |
+
eststo incentives_heterogeneity
|
73 |
+
|
74 |
+
coefplot (incentives_heterogeneity , fcolor(gs8) mcolor(gs8) lcolor(gs8)) , ///
|
75 |
+
vertical lwidth(*1) keep(*Treatment_intervention*) ///
|
76 |
+
ciopts(recast(rcap)lpattern(dash)lwidth(*.6) lcolor(gs0) ) citop ci(95) ///
|
77 |
+
xlabel(, labgap(3) labsize(medlarge)) ytitle ("Payoff Share", margin(medium) height(3) size(medlarge)) ylabel(-.1(0.05).1) ///
|
78 |
+
graphregion(color(white)) yline(0, lcolor(black)) xlabel(1 "Raven Score {&le} Median" 2 "Raven Score {>} Median")
|
79 |
+
|
80 |
+
graph export `"${PATH_OUT}/figure7.png"', as(png) replace
|
81 |
+
|
82 |
+
reg payoff_share i.b0.Treatment_intervention#i.bn.raven_score_quartiles i.bn.raven_score_quartiles ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4, cluster(subject_id) nocons
|
83 |
+
eststo incentives_heterogeneity
|
84 |
+
|
85 |
+
coefplot (incentives_heterogeneity , fcolor(gs8) mcolor(gs8) lcolor(gs8)) , ///
|
86 |
+
vertical lwidth(*1) keep(*Treatment_intervention*) ///
|
87 |
+
ciopts(recast(rcap)lpattern(dash)lwidth(*.6) lcolor(gs0) ) citop ci(95) ///
|
88 |
+
xlabel(, labgap(3) labsize(medlarge)) ytitle ("Payoff Share", margin(medium) height(3) size(medlarge)) ylabel(-.1(0.05).1) ///
|
89 |
+
graphregion(color(white)) yline(0, lcolor(black)) xlabel(1 `""Raven score" "1st Quartile""' 2 `""Raven score" "2nd Quartile"' 3 `""Raven score" "3rd Quartile""' 4 `""Raven score" "4th Quartile""')
|
90 |
+
|
91 |
+
graph export `"${PATH_OUT}/figureO_2.png"', as(png) replace
|
92 |
+
|
93 |
+
|
94 |
+
*** Tables heterogeneity:
|
95 |
+
|
96 |
+
reg payoff_share i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median if Treatment_Incentives!=4 , cluster(subject_id) robust
|
97 |
+
eststo hetero_force_both_raw
|
98 |
+
reg payoff_share i.raven_score_median i.Treatment_intervention i.Treatment_intervention#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4 , cluster(subject_id) robust
|
99 |
+
eststo hetero_force_all
|
100 |
+
|
101 |
+
reg payoff_share i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median if Treatment_Incentives!=4 , cluster(subject_id) robust
|
102 |
+
eststo hetero_both_raw
|
103 |
+
reg payoff_share i.raven_score_median i.Treatment_Environment i.Treatment_Environment#i.raven_score_median ${Incentive_control} ${Wave_control} ${Ability_control} ${Controls} if Treatment_Incentives!=4 , cluster(subject_id) robust
|
104 |
+
eststo hetero_all
|
105 |
+
|
106 |
+
esttab hetero_force_both_raw hetero_force_all ///
|
107 |
+
hetero_both_raw hetero_all ///
|
108 |
+
using `"${PATH_OUT}/tableO_9.tex"', replace ///
|
109 |
+
b(%5.3f) se(%5.3f) ///
|
110 |
+
order(*Treatment_intervention* 2.Treatment_Environment* 3.Treatment_Environment*) ///
|
111 |
+
star(* .1 ** .05 *** .01) ///
|
112 |
+
label booktabs nonotes ///
|
113 |
+
nodepvars nobase noomit ///
|
114 |
+
nomtitles ///
|
115 |
+
mgroups("Payoff Share" , ///
|
116 |
+
pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
117 |
+
stats(N N_clust r2, fmt(%18.0g %18.0g %5.3f) labels("N" "No. Subjects" "\(R^2\)")) ///
|
118 |
+
indicate("Controls = *original* *Incentives* *ability* *age* *gender* *perc_multitasking* *subject_cat* *q_abitur_grade_cat* *q_math_grade_cat*")
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
********** Calculate Hypothetical Payoffs for Table 5***************
|
135 |
+
|
136 |
+
cap program drop convert
|
137 |
+
program define convert, eclass
|
138 |
+
matrix list `1'
|
139 |
+
ereturn scalar N=.
|
140 |
+
ereturn matrix mean `1'
|
141 |
+
end
|
142 |
+
|
143 |
+
|
144 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
145 |
+
|
146 |
+
*Restrict dataset to Baseline-Scarce treatments
|
147 |
+
drop if Treatment_Environment!=1
|
148 |
+
drop if Treatment_Incentives==4
|
149 |
+
drop if round!=1
|
150 |
+
|
151 |
+
expand 3
|
152 |
+
|
153 |
+
*Hypo. Treatment ID
|
154 |
+
bysort subject_id: gen Treatment_Incentives_Hypo=_n
|
155 |
+
label var Treatment_Incentives_Hypo "Hypothetical Incentives"
|
156 |
+
label values Treatment_Incentives_Hypo Treatment_Incentives
|
157 |
+
|
158 |
+
|
159 |
+
* Always got 40 cents for load task
|
160 |
+
gen hypo_payoff_load_mean = load_correct_mean * 0.4
|
161 |
+
|
162 |
+
* Get hypo payoff for decision task using real behavior under one of three incentive schemes
|
163 |
+
gen hypo_payoff_summation_mean = .
|
164 |
+
replace hypo_payoff_summation_mean = summation_correct_mean * 0.1 if Treatment_Incentives_Hypo ==1
|
165 |
+
replace hypo_payoff_summation_mean = summation_correct_mean * 0.2 if Treatment_Incentives_Hypo ==2
|
166 |
+
replace hypo_payoff_summation_mean = summation_correct_mean * 0.4 if Treatment_Incentives_Hypo ==3
|
167 |
+
|
168 |
+
** Hypothethical payoff + share
|
169 |
+
gen hypo_payoff_mean = hypo_payoff_load_mean + hypo_payoff_summation_mean
|
170 |
+
gen hypo_payoff_share = .
|
171 |
+
replace hypo_payoff_share = hypo_payoff_mean / 0.5 if Treatment_Incentives_Hypo ==1
|
172 |
+
replace hypo_payoff_share = hypo_payoff_mean / 0.6 if Treatment_Incentives_Hypo ==2
|
173 |
+
replace hypo_payoff_share = hypo_payoff_mean / 0.8 if Treatment_Incentives_Hypo ==3
|
174 |
+
|
175 |
+
gen hypo_payoff_share_table =hypo_payoff_share
|
176 |
+
replace hypo_payoff_share_table =. if Treatment_Incentives == Treatment_Incentives_Hypo
|
177 |
+
|
178 |
+
|
179 |
+
estpost tabstat hypo_payoff_share_table if Treatment_Incentives ==1 , by(Treatment_Incentives_Hypo) statistics(mean sd) columns(statistics) listwise nototal
|
180 |
+
eststo one
|
181 |
+
estpost tabstat hypo_payoff_share_table if Treatment_Incentives ==2 , by(Treatment_Incentives_Hypo) statistics(mean sd) columns(statistics) listwise nototal
|
182 |
+
eststo two
|
183 |
+
estpost tabstat hypo_payoff_share_table if Treatment_Incentives ==3 , by(Treatment_Incentives_Hypo) statistics(mean sd) columns(statistics) listwise nototal
|
184 |
+
eststo three
|
185 |
+
|
186 |
+
estpost tabstat payoff_share_mean if Treatment_Incentives_Hypo==1 , by(Treatment_Incentives) statistics(mean sd) columns(statistics) listwise nototal
|
187 |
+
eststo observed
|
188 |
+
|
189 |
+
matrix diff=e(mean)
|
190 |
+
matrix t=e(mean)
|
191 |
+
estpost ttest hypo_payoff_share if Treatment_Incentives_Hypo ==1 &Treatment_Incentives !=3 , by(Treatment_Incentives )
|
192 |
+
matrix help=e(b)
|
193 |
+
matrix help2=e(p)
|
194 |
+
matrix diff[1,1] = help[1,1]
|
195 |
+
matrix t[1,1] = help2[1,1]
|
196 |
+
estpost ttest hypo_payoff_share if Treatment_Incentives_Hypo ==2 &Treatment_Incentives !=3 , by(Treatment_Incentives )
|
197 |
+
matrix help=e(b)
|
198 |
+
matrix help2=e(p)
|
199 |
+
matrix diff[1,2] = help[1,1]
|
200 |
+
matrix t[1,2] = help2[1,1]
|
201 |
+
estpost ttest hypo_payoff_share if Treatment_Incentives_Hypo ==3 &Treatment_Incentives !=1 , by(Treatment_Incentives )
|
202 |
+
matrix help=e(b)
|
203 |
+
matrix help2=e(p)
|
204 |
+
matrix diff[1,3] = help[1,1]
|
205 |
+
matrix t[1,3] = help2[1,1]
|
206 |
+
|
207 |
+
convert diff
|
208 |
+
eststo diff
|
209 |
+
|
210 |
+
convert t
|
211 |
+
eststo t
|
212 |
+
|
213 |
+
|
214 |
+
* Data for Table 5
|
215 |
+
esttab one two three observed diff t, ///
|
216 |
+
order(10 20 40) ///
|
217 |
+
main(mean %5.3f) aux(sd %5.3f) ///
|
218 |
+
nostar unstack noobs nonote nolabel nonumber ///
|
219 |
+
mtitles("\textsc{40/10}" "\textsc{40/20}" "\textsc{40/40}" "" "diff" "p-values") ///
|
220 |
+
mgroups("Hypothetical behavior in" "Observed" "Diff. to largest benchmark" , pattern(1 0 0 1 1 0) ) ///
|
221 |
+
|
222 |
+
clear
|
223 |
+
|
224 |
+
log close
|
40/replication_package/EmpiricalAnalysis/dofiles/Supplementary_Material_Randomization_Check_table.do
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
log using `"${PATH_OUT}/Randomization_Check.log"', replace
|
2 |
+
|
3 |
+
|
4 |
+
use "${PATH_IN_DATA}/formatted_data_replication.dta", clear
|
5 |
+
keep if round==1
|
6 |
+
|
7 |
+
|
8 |
+
set scheme s1color_black_gray
|
9 |
+
|
10 |
+
**********************************
|
11 |
+
* Little program to convert matrix
|
12 |
+
**********************************
|
13 |
+
|
14 |
+
cap program drop convert
|
15 |
+
program define convert, eclass
|
16 |
+
matrix list `1'
|
17 |
+
ereturn scalar N=.
|
18 |
+
ereturn matrix mean `1'
|
19 |
+
ereturn local estimates_title="p-values"
|
20 |
+
end
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
* Generate variables specifallcy needed for balancing table
|
25 |
+
|
26 |
+
egen ability_load_std_1=std(ability_load) if original_lab==1
|
27 |
+
egen ability_task_std_1=std(ability_task) if original_lab==1
|
28 |
+
|
29 |
+
egen ability_load_std=std(ability_load) if original_lab==0
|
30 |
+
egen ability_task_std=std(ability_task) if original_lab==0
|
31 |
+
|
32 |
+
replace ability_load_std=ability_load_std_1 if original_lab==1
|
33 |
+
replace ability_task_std=ability_task_std_1 if original_lab==1
|
34 |
+
drop ability_load_std_1 ability_task_std_1
|
35 |
+
|
36 |
+
label var ability_task_std "Ability Decision Task (std.)"
|
37 |
+
label var ability_load_std "Ability Background Task (std.)"
|
38 |
+
|
39 |
+
bysort Treatment_Environment Treatment_Incentives: gen obs=_N
|
40 |
+
label var obs "N"
|
41 |
+
|
42 |
+
|
43 |
+
cap drop treatment_id
|
44 |
+
egen treatment_id=group(Treatment_Environment Treatment_Incentives )
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
* Write Balancing table; Different parts are appended after creating results via tabstat
|
49 |
+
|
50 |
+
qui file open table_out using `"${PATH_OUT}/tableO_1.tex"', write replace
|
51 |
+
file write table_out " \begin{tabular}{l*{13}{c}}" _n
|
52 |
+
file write table_out "\toprule" _n
|
53 |
+
file close table_out
|
54 |
+
|
55 |
+
estimates clear
|
56 |
+
|
57 |
+
bysort Treatment_Environment: eststo: estpost tabstat ability_load_std ability_task_std q_age q_gender economist perc_multitasking_2 perc_multitasking_1, by(Treatment_Incentives) nototal statistics(mean sd) columns(statistics) listwise
|
58 |
+
|
59 |
+
* copy mean matrix such that p-values vector has the correct length etc.
|
60 |
+
matrix p_values=e(mean)
|
61 |
+
local i=0
|
62 |
+
foreach var of varlist ability_load_std ability_task_std q_age q_gender economist perc_multitasking_2 perc_multitasking_1 {
|
63 |
+
local i=1+`i'
|
64 |
+
kwallis `var' , by(treatment_id)
|
65 |
+
local p=chi2tail(`r(df)',`r(chi2_adj)')
|
66 |
+
matrix p_values[1,`i']=`p'
|
67 |
+
}
|
68 |
+
|
69 |
+
matrix p_values=p_values[1,1..7]
|
70 |
+
matrix coleq p_values=p-value p-value p-value p-value p-value p-value
|
71 |
+
|
72 |
+
* Convert p-values to estimation result and store it
|
73 |
+
convert p_values
|
74 |
+
eststo p_values
|
75 |
+
|
76 |
+
esttab est* p_values using `"${PATH_OUT}/tableO_1.tex"', ///
|
77 |
+
main(mean %5.2f) aux(sd %5.2f) nostar unstack ///
|
78 |
+
noobs nonote label append booktabs compress ///
|
79 |
+
nonumber nomtitles frag ///
|
80 |
+
mgroups("\textsc{Baseline}" "\textsc{Directed Attention}" "\textsc{Forced Choice}" "Kruskal-Wallis" , ///
|
81 |
+
pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
* As tabstat uses only observation with no missings, perform second part where only data from certain waves are available
|
86 |
+
estimates clear
|
87 |
+
bysort Treatment_Environment: eststo: estpost tabstat raven_score treatment_id, by(Treatment_Incentives) nototal statistics(mean sd) columns(statistics) listwise
|
88 |
+
|
89 |
+
* copy mean matrix such that p-values vector has the correct length etc.
|
90 |
+
matrix p_values=e(mean)
|
91 |
+
local i=0
|
92 |
+
foreach var of varlist raven_score treatment_id{
|
93 |
+
local i=1+`i'
|
94 |
+
kwallis `var' , by(treatment_id)
|
95 |
+
local p=chi2tail(`r(df)',`r(chi2_adj)')
|
96 |
+
matrix p_values[1,`i']=`p'
|
97 |
+
}
|
98 |
+
|
99 |
+
matrix p_values=p_values[1,1..2]
|
100 |
+
matrix coleq p_values=p-value p-value
|
101 |
+
|
102 |
+
* Convert p-values to estimation result and store it
|
103 |
+
convert p_values
|
104 |
+
eststo p_values
|
105 |
+
|
106 |
+
esttab est* p_values using `"${PATH_OUT}/tableO_1.tex"', ///
|
107 |
+
append frag ///
|
108 |
+
drop(treatment_id) /// refcat(raven_score "\emph{2nd Wave only}", nolabel) nobaselevels ///
|
109 |
+
main(mean %5.2f) aux(sd %5.2f) nostar unstack ///
|
110 |
+
eqlabels(none) nolines ///
|
111 |
+
noobs nonote label booktabs compress ///
|
112 |
+
nomtitles nodepvar nonumber
|
113 |
+
|
114 |
+
estimates clear
|
115 |
+
bysort Treatment_Environment: eststo: estpost tabstat original_lab treatment_id, by(Treatment_Incentives) nototal statistics(mean sd) columns(statistics) listwise
|
116 |
+
esttab est* using `"${PATH_OUT}/tableO_1.tex"', ///
|
117 |
+
append frag drop(treatment_id) ///
|
118 |
+
main(mean %4.0g) nostar unstack ///
|
119 |
+
eqlabels(none) ///
|
120 |
+
noobs nonote label booktabs compress ///
|
121 |
+
nomtitles nodepvar nonumber
|
122 |
+
|
123 |
+
estimates clear
|
124 |
+
bysort Treatment_Environment: eststo: estpost tabstat obs treatment_id, by(Treatment_Incentives) nototal statistics(mean sd) columns(statistics) listwise
|
125 |
+
esttab est* using `"${PATH_OUT}/tableO_1.tex"', ///
|
126 |
+
append frag drop(treatment_id) ///
|
127 |
+
main(mean %5.0g) nostar unstack ///
|
128 |
+
eqlabels(none) ///
|
129 |
+
noobs nonote label booktabs compress ///
|
130 |
+
nomtitles nodepvar nonumber
|
131 |
+
|
132 |
+
qui file open table_out using `"${PATH_OUT}/tableO_1.tex"', write append
|
133 |
+
file write table_out "\bottomrule" _n
|
134 |
+
file write table_out "\end{tabular}" _n
|
135 |
+
file close table_out
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
log close
|
140 |
+
|
141 |
+
|
142 |
+
|
143 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_eststo.ado
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 1.0.4 09nov2007 Ben Jann
|
2 |
+
|
3 |
+
program define _eststo, byable(onecall)
|
4 |
+
local caller : di _caller()
|
5 |
+
version 8.2
|
6 |
+
if "`_byvars'"!="" local by "by `_byvars'`_byrc0' : "
|
7 |
+
if inlist(`"`1'"',"clear","dir","drop") {
|
8 |
+
version `caller': `by'eststo `0'
|
9 |
+
}
|
10 |
+
else {
|
11 |
+
capt _on_colon_parse `0'
|
12 |
+
if !_rc {
|
13 |
+
local command `"`s(after)'"'
|
14 |
+
if `"`command'"'!="" {
|
15 |
+
local command `":`command'"'
|
16 |
+
}
|
17 |
+
local 0 `"`s(before)'"'
|
18 |
+
}
|
19 |
+
syntax [anything] [, Esample * ]
|
20 |
+
if `"`esample'"'=="" {
|
21 |
+
local options `"noesample `options'"'
|
22 |
+
}
|
23 |
+
if `"`options'"'!="" {
|
24 |
+
local options `", `options'"'
|
25 |
+
}
|
26 |
+
version `caller': `by'eststo `anything'`options' `command'
|
27 |
+
}
|
28 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_eststo.hlp
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.h eststo
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_gpp.ado
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! 1.0.1 NJC 29 January 1999
|
2 |
+
* 1.0.0 13 March 1998
|
3 |
+
* computes (i - a)/(n - 2a + 1)
|
4 |
+
program define _gpp
|
5 |
+
version 5.0
|
6 |
+
local varlist "req new max(1)"
|
7 |
+
local exp "req nopre"
|
8 |
+
local if "opt"
|
9 |
+
local in "opt"
|
10 |
+
local options "a(real 0.5) BY(string)"
|
11 |
+
parse "`*'"
|
12 |
+
tempvar value i touse
|
13 |
+
if "`by'" != "" { confirm variable `by' }
|
14 |
+
quietly {
|
15 |
+
mark `touse' `if' `in'
|
16 |
+
markout `touse' `exp'
|
17 |
+
gen `value' = `exp' if `touse'
|
18 |
+
sort `touse' `by' `value'
|
19 |
+
by `touse' `by' : gen long `i' = _n if `value' != .
|
20 |
+
by `touse' `by' : replace `varlist' = /*
|
21 |
+
*/ (`i' - `a') / (`i'[_N] - 2 * `a' + 1)
|
22 |
+
label var `varlist' "Fraction of the data"
|
23 |
+
}
|
24 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/_/_oaxaca.ado
ADDED
@@ -0,0 +1,1505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*!version 1.0.7 Ben Jann 18nov2008
|
2 |
+
|
3 |
+
program define _oaxaca, rclass sortpreserve
|
4 |
+
version 9.2
|
5 |
+
capt syntax [, Level(passthru) eform xb noLEgend ]
|
6 |
+
if _rc==0 {
|
7 |
+
Display `0'
|
8 |
+
exit
|
9 |
+
}
|
10 |
+
syntax anything ///
|
11 |
+
[if] [in] [fw aw pw iw] [, ///
|
12 |
+
THREEfold THREEfold2(str) ///
|
13 |
+
Weights(numlist) Reference(name) split ///
|
14 |
+
Adjust(passthru) ///
|
15 |
+
Detail Detail2(passthru) ///
|
16 |
+
CATegorical(string) ///
|
17 |
+
x1(passthru) x2(passthru) ///
|
18 |
+
FIXed FIXed2(string) ///
|
19 |
+
noSE ///
|
20 |
+
SVY SVY2(str asis) ///
|
21 |
+
vce(str) CLuster(passthru) ///
|
22 |
+
NOSUEST SUEST ///
|
23 |
+
eform ///
|
24 |
+
Level(passthru) ///
|
25 |
+
xb ///
|
26 |
+
noLEgend ///
|
27 |
+
NOIsily ///
|
28 |
+
nodisplay ///
|
29 |
+
depname(passthru) /// dependent variable name for returns/display
|
30 |
+
nlcom /// undocumented: use nlcom to derive SE's (slow)
|
31 |
+
]
|
32 |
+
_parse_elist `anything' // returns local elist
|
33 |
+
local se = "`se'"==""
|
34 |
+
if `"`fixed2'"'!="" local fixed
|
35 |
+
if `"`detail2'"'!="" local detail detail
|
36 |
+
if `"`weights'"'=="" & `"`reference'"'=="" local threefold threefold
|
37 |
+
if `"`threefold2'"'!="" {
|
38 |
+
if `"`threefold2'"'!=substr("reverse",1,max(1,strlen(`"`threefold2'"'))) {
|
39 |
+
di as err "invalid threefold() option"
|
40 |
+
exit 198
|
41 |
+
}
|
42 |
+
local threefold threefold
|
43 |
+
local threefold2 reverse
|
44 |
+
}
|
45 |
+
if (`"`weights'"'!="") + (`"`reference'"'!="") + ("`threefold'"!="")>1 {
|
46 |
+
di as err "only one of threefold, weight(), and reference() allowed"
|
47 |
+
exit 198
|
48 |
+
}
|
49 |
+
if "`nosuest'"!="" & "`suest'"!="" {
|
50 |
+
di as err "suest and nosuest not both allowed"
|
51 |
+
exit 198
|
52 |
+
}
|
53 |
+
if `"`svy2'"'!="" local svy "svy"
|
54 |
+
if "`svy'"!="" {
|
55 |
+
local i 0
|
56 |
+
foreach opt in vce cluster weight {
|
57 |
+
local optnm: word `++i' of "vce()" "cluster()" "weights"
|
58 |
+
if `"``opt''"'!="" {
|
59 |
+
di as err "`optnm' not allowed with svy"
|
60 |
+
exit 198
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
local qui = cond("`noisily'"=="","quietly","")
|
65 |
+
|
66 |
+
// reference equal to one of the groups?
|
67 |
+
if "`reference'"!="" {
|
68 |
+
local tmp: list posof "`reference'" in elist
|
69 |
+
if `tmp' {
|
70 |
+
local weights = 2 - `tmp'
|
71 |
+
local reference
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
// use suest?
|
76 |
+
local suest = cond("`suest'"!="",1,0)
|
77 |
+
if `"`reference'`svy'`cluster'"'!="" {
|
78 |
+
local suest 1
|
79 |
+
}
|
80 |
+
if `"`vce'"'!="" {
|
81 |
+
_vce_iscluster `vce'
|
82 |
+
if `vce_iscluster' local suest 1
|
83 |
+
local vce `"vce(`vce')"'
|
84 |
+
}
|
85 |
+
if `se'==0 | "`nosuest'"!="" {
|
86 |
+
local suest 0
|
87 |
+
}
|
88 |
+
|
89 |
+
// get estimates
|
90 |
+
local robreg = (`suest'==0 & `se')
|
91 |
+
nobreak {
|
92 |
+
// preserve last estimates
|
93 |
+
tempname hcurrent
|
94 |
+
tempvar touse1 touse2 subpop1 subpop2
|
95 |
+
_est hold `hcurrent', restore nullok estsystem
|
96 |
+
local g 0
|
97 |
+
foreach est in `elist' `reference' {
|
98 |
+
local ++g
|
99 |
+
qui estimates restore `est'
|
100 |
+
// determine esample (and subpop if svy)
|
101 |
+
if `g'<3 {
|
102 |
+
qui gen byte `touse`g'' = e(sample)==1
|
103 |
+
_marksubpop `e(subpop)', g(`subpop`g'')
|
104 |
+
qui replace `subpop`g'' = 0 if `touse`g''==0
|
105 |
+
if "`svy'"=="" {
|
106 |
+
qui replace `touse`g'' = 0 if `subpop`g''==0
|
107 |
+
}
|
108 |
+
if "`e(cmd)'"=="heckman" | "`e(cmd)'"=="heckprob" {
|
109 |
+
local tmp "`touse`g''"
|
110 |
+
if "`svy'"!="" {
|
111 |
+
local tmp "`subpop`g''"
|
112 |
+
}
|
113 |
+
local depvar: word 1 of `e(depvar)'
|
114 |
+
qui replace `tmp' = 0 if `depvar'>=.
|
115 |
+
local depvar_s: word 2 of `e(depvar)'
|
116 |
+
if "`depvar_s'"!="" {
|
117 |
+
qui replace `tmp' = 0 if `depvar_s'==0
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
// if not suest: get coefficients (and variances if se)
|
122 |
+
if `suest'==0 {
|
123 |
+
tempname b`g'
|
124 |
+
mat `b`g'' = e(b)
|
125 |
+
local firsteq: coleq `b`g'', q
|
126 |
+
local firsteq: word 1 of `firsteq'
|
127 |
+
mat `b`g'' = `b`g''[1,"`firsteq':"]
|
128 |
+
local eqlab = "b`g'"
|
129 |
+
if `g'==3 local eqlab = "b_ref"
|
130 |
+
mat coleq `b`g'' = "`eqlab'"
|
131 |
+
if `se' {
|
132 |
+
tempname V`g'
|
133 |
+
mat `V`g'' = e(V)
|
134 |
+
mat `V`g'' = `V`g''["`firsteq':","`firsteq':"]
|
135 |
+
mat coleq `V`g'' = "`eqlab'"
|
136 |
+
mat roweq `V`g'' = "`eqlab'"
|
137 |
+
if "`e(vce)'"!="robust" local robreg 0
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
if `robreg' {
|
143 |
+
local e_vce "robust"
|
144 |
+
local e_vcetype "Robust"
|
145 |
+
}
|
146 |
+
|
147 |
+
// apply suest
|
148 |
+
tempname b V
|
149 |
+
if `suest' {
|
150 |
+
`qui' suest `elist' `reference', `svy' `vce' `cluster'
|
151 |
+
mat `b' = e(b)
|
152 |
+
mat `V' = e(V)
|
153 |
+
local e_vce "`e(vce)'"
|
154 |
+
local e_vcetype "`e(vcetype)'"
|
155 |
+
ExtractFirstEqs "b1 b2 b_ref" `b' `V'
|
156 |
+
}
|
157 |
+
else {
|
158 |
+
mat `b' = `b1', `b2'
|
159 |
+
mat drop `b1' `b2'
|
160 |
+
if `se' {
|
161 |
+
mat `V' = `V1'
|
162 |
+
MatAppendDiag `V' `V2'
|
163 |
+
mat drop `V1' `V2'
|
164 |
+
}
|
165 |
+
if `g'==3 {
|
166 |
+
mat `b' = `b', `b3'
|
167 |
+
mat drop `b3'
|
168 |
+
if `se' {
|
169 |
+
MatAppendDiag `V' `V3'
|
170 |
+
mat drop `V3'
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
// apply deviation contrast transform to categorical variables
|
176 |
+
if `"`categorical'"'!="" {
|
177 |
+
if `se' {
|
178 |
+
_devcon `b' `V', groups(`categorical')
|
179 |
+
}
|
180 |
+
else {
|
181 |
+
_decvon `b', groups(`categorical')
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
// insert 0's for missing coefficients
|
186 |
+
mata: oaxaca_insertmissingcoefs() // returns coefnames in local coef
|
187 |
+
|
188 |
+
// compute means
|
189 |
+
marksample touse, novarlist zeroweight
|
190 |
+
qui replace `touse' = 0 if `touse1'==0 & `touse2'==0
|
191 |
+
tempname x Vx
|
192 |
+
if "`svy'"!="" {
|
193 |
+
capt _parsesvyopt `svy2'
|
194 |
+
if _rc {
|
195 |
+
di as err "invalid svy() option"
|
196 |
+
exit 198
|
197 |
+
}
|
198 |
+
capt _parsesvysubpop `svy_subpop'
|
199 |
+
if _rc {
|
200 |
+
di as err "invalid subpop() option"
|
201 |
+
exit 198
|
202 |
+
}
|
203 |
+
//=> svy `svy_type', subpop(`svy_subpop') `svy_opts': ...
|
204 |
+
}
|
205 |
+
local cons
|
206 |
+
if `: list posof "_cons" in coefs' {
|
207 |
+
local cons "_cons"
|
208 |
+
}
|
209 |
+
local xvars: list coefs - cons
|
210 |
+
if "`cons'"!="" {
|
211 |
+
tempname xcons
|
212 |
+
qui gen byte `xcons' = 1
|
213 |
+
local xvars: list xvars | xcons
|
214 |
+
}
|
215 |
+
if `suest' {
|
216 |
+
tempname grpvar
|
217 |
+
gen byte `grpvar'= 0
|
218 |
+
qui replace `grpvar' = 1 if `subpop1'
|
219 |
+
capt assert (`grpvar'==0) if `subpop2'
|
220 |
+
if _rc {
|
221 |
+
error "overlapping samples (groups not distinct)"
|
222 |
+
exit 498
|
223 |
+
}
|
224 |
+
qui replace `grpvar' = 2 if `subpop2'
|
225 |
+
if "`svy'"=="" {
|
226 |
+
`qui' mean `xvars' if `touse' [`weight'`exp'], ///
|
227 |
+
over(`grpvar') `vce' `cluster'
|
228 |
+
if e(N_clust)<. {
|
229 |
+
local e_N_clust = e(N_clust)
|
230 |
+
local e_clustvar "`e(clustvar)'"
|
231 |
+
}
|
232 |
+
}
|
233 |
+
else {
|
234 |
+
`qui' svy `svy_type', ///
|
235 |
+
subpop(`svy_subpop' & (`subpop1' | `subpop2')) `svy_opts' : ///
|
236 |
+
mean `xvars' if `touse', over(`grpvar')
|
237 |
+
local e_prefix "`e(prefix)'"
|
238 |
+
local e_N_strata = e(N_strata)
|
239 |
+
local e_N_psu = e(N_psu)
|
240 |
+
local e_N_pop = e(N_pop)
|
241 |
+
local e_df_r = e(df_r)
|
242 |
+
}
|
243 |
+
if "`e(vce)'"!="analytic" {
|
244 |
+
local e_vce "`e(vce)'"
|
245 |
+
local e_vcetype "`e(vcetype)'"
|
246 |
+
}
|
247 |
+
local e_wtype "`e(wtype)'"
|
248 |
+
local e_wexp `"`e(wexp)'"'
|
249 |
+
mat `x' = e(b)
|
250 |
+
mat `Vx' = e(V)
|
251 |
+
local N1 = el(e(_N),1,1)
|
252 |
+
local N2 = el(e(_N),1,2)
|
253 |
+
if "`cons'"!="" {
|
254 |
+
local coleq: coleq `x'
|
255 |
+
local coleq: subinstr local coleq "`xcons'" "_cons", word all
|
256 |
+
mat coleq `x' = `coleq'
|
257 |
+
mat coleq `Vx' = `coleq'
|
258 |
+
mat roweq `Vx' = `coleq'
|
259 |
+
}
|
260 |
+
mata: oaxaca_reorderxandVx()
|
261 |
+
}
|
262 |
+
else {
|
263 |
+
tempname xtmp Vxtmp
|
264 |
+
local tmp
|
265 |
+
forv i = 1/2 {
|
266 |
+
if "`svy'"=="" {
|
267 |
+
`qui' mean `xvars' if `touse' & `touse`i'' [`weight'`exp'], `vce' `cluster'
|
268 |
+
}
|
269 |
+
else {
|
270 |
+
`qui' svy `svy_type', subpop(`svy_subpop' & `subpop`i'') `svy_opts' : ///
|
271 |
+
mean `xvars' if `touse' & `touse`i''
|
272 |
+
}
|
273 |
+
mat `x`tmp'' = e(b)
|
274 |
+
local N`i' = el(e(_N),1,1)
|
275 |
+
local e_wtype "`e(wtype)'"
|
276 |
+
local e_wexp `"`e(wexp)'"'
|
277 |
+
if "`cons'"!="" {
|
278 |
+
local coln: colnames `x`tmp''
|
279 |
+
local coln: subinstr local coln "`xcons'" "_cons", word
|
280 |
+
mat coln `x`tmp'' = `coln'
|
281 |
+
}
|
282 |
+
mat coleq `x`tmp'' = "x`i'"
|
283 |
+
if `se' {
|
284 |
+
mat `Vx`tmp'' = e(V)
|
285 |
+
if "`cons'"!="" {
|
286 |
+
mat coln `Vx`tmp'' = `coln'
|
287 |
+
mat rown `Vx`tmp'' = `coln'
|
288 |
+
}
|
289 |
+
mat coleq `Vx`tmp'' = "x`i'"
|
290 |
+
mat roweq `Vx`tmp'' = "x`i'"
|
291 |
+
}
|
292 |
+
local tmp tmp
|
293 |
+
}
|
294 |
+
mat `x' = `x', `xtmp'
|
295 |
+
mat drop `xtmp'
|
296 |
+
if `se' {
|
297 |
+
MatAppendDiag `Vx' `Vxtmp'
|
298 |
+
mat drop `Vxtmp'
|
299 |
+
}
|
300 |
+
}
|
301 |
+
if `"`x1'`x2'"'!="" {
|
302 |
+
_setXvals `x' `Vx', se(`se') `x1' `x2'
|
303 |
+
}
|
304 |
+
mat `b' = `b', `x'
|
305 |
+
mat drop `x'
|
306 |
+
if `se' {
|
307 |
+
if "`fixed'"!="" {
|
308 |
+
mat `Vx' = `Vx'*0
|
309 |
+
}
|
310 |
+
else if `"`fixed2'"'!=""{
|
311 |
+
local fixedx
|
312 |
+
foreach var of local fixed2 {
|
313 |
+
capt unab temp: `var'
|
314 |
+
if _rc {
|
315 |
+
local temp "`var'"
|
316 |
+
}
|
317 |
+
local temp: list temp & coefs
|
318 |
+
if `"`temp'"'=="" {
|
319 |
+
di as err `"`var' not found"'
|
320 |
+
exit 111
|
321 |
+
}
|
322 |
+
local fixedx: list fixedx | temp
|
323 |
+
}
|
324 |
+
if `"`fixedx'"'!="" {
|
325 |
+
mata: oaxaca_setfixedXtozero(0)
|
326 |
+
}
|
327 |
+
}
|
328 |
+
MatAppendDiag `V' `Vx'
|
329 |
+
mat drop `Vx'
|
330 |
+
}
|
331 |
+
|
332 |
+
// post b and V for use with nlcom
|
333 |
+
if `se' {
|
334 |
+
eret post `b' `V'
|
335 |
+
_eretpostcmd
|
336 |
+
tempname V0
|
337 |
+
mat `V0' = e(V)
|
338 |
+
}
|
339 |
+
else {
|
340 |
+
eret post `b'
|
341 |
+
}
|
342 |
+
tempname b0
|
343 |
+
mat `b0' = e(b)
|
344 |
+
|
345 |
+
// parse adjust() => returns locals adjust and coefsadj
|
346 |
+
_parseadjust, `adjust' coefs(`coefs')
|
347 |
+
|
348 |
+
// parse detail2() option => returns local cgroups
|
349 |
+
_parsedetail2, `detail2' coefs(`coefsadj')
|
350 |
+
|
351 |
+
if "`nlcom'"!="" {
|
352 |
+
// nlcom step 1: detailed decomposition
|
353 |
+
local terms1
|
354 |
+
local terms2
|
355 |
+
local terms3
|
356 |
+
if "`threefold'"!="" {
|
357 |
+
local 1 1
|
358 |
+
local 2 2
|
359 |
+
if "`threefold2'"!="" {
|
360 |
+
local 1 2
|
361 |
+
local 2 1
|
362 |
+
}
|
363 |
+
local i 0
|
364 |
+
foreach coef of local coefsadj {
|
365 |
+
local ++i
|
366 |
+
local term1`i' (E_`coef':([x1]_b[`coef']-[x2]_b[`coef'])*[b`2']_b[`coef'])
|
367 |
+
local terms1 `"`macval(terms1)' \`term1`i''"'
|
368 |
+
local term2`i' (C_`coef':[x`2']_b[`coef']*([b1]_b[`coef']-[b2]_b[`coef']))
|
369 |
+
local terms2 `"`macval(terms2)' \`term2`i''"'
|
370 |
+
local term3`i' (I_`coef':([x1]_b[`coef']-[x2]_b[`coef'])*([b`1']_b[`coef']-[b`2']_b[`coef']))
|
371 |
+
local terms3 `"`macval(terms3)' \`term3`i''"'
|
372 |
+
}
|
373 |
+
local eqnames "E_ C_ I_"
|
374 |
+
}
|
375 |
+
else {
|
376 |
+
if "`reference'"!="" {
|
377 |
+
local i 0
|
378 |
+
foreach coef of local coefsadj {
|
379 |
+
local ++i
|
380 |
+
local term1`i' (E_`coef':([x1]_b[`coef']-[x2]_b[`coef'])*[b_ref]_b[`coef'])
|
381 |
+
local terms1 `"`macval(terms1)' \`term1`i''"'
|
382 |
+
if "`split'"=="" {
|
383 |
+
local term2`i' (U_`coef':[x1]_b[`coef']*([b1]_b[`coef']-[b_ref]_b[`coef']) ///
|
384 |
+
+ [x2]_b[`coef']*([b_ref]_b[`coef']-[b2]_b[`coef']))
|
385 |
+
local terms2 `"`macval(terms2)' \`term2`i''"'
|
386 |
+
}
|
387 |
+
else {
|
388 |
+
local term2`i' (U1_`coef':[x1]_b[`coef']*([b1]_b[`coef']-[b_ref]_b[`coef']))
|
389 |
+
local term3`i' (U2_`coef':[x2]_b[`coef']*([b_ref]_b[`coef']-[b2]_b[`coef']))
|
390 |
+
local terms2 `"`macval(terms2)' \`term2`i''"'
|
391 |
+
local terms3 `"`macval(terms3)' \`term3`i''"'
|
392 |
+
}
|
393 |
+
}
|
394 |
+
}
|
395 |
+
else { // => weights()
|
396 |
+
local i 0
|
397 |
+
local wgt
|
398 |
+
foreach coef of local coefsadj {
|
399 |
+
if `"`wgt'"'=="" { // => recycle
|
400 |
+
local wgt "`weights'"
|
401 |
+
}
|
402 |
+
gettoken w wgt : wgt
|
403 |
+
local m = 1 - `w'
|
404 |
+
local ++i
|
405 |
+
local term1`i' (E_`coef':([x1]_b[`coef']-[x2]_b[`coef']) * ///
|
406 |
+
(`w'*[b1]_b[`coef']+`m'*[b2]_b[`coef']))
|
407 |
+
local terms1 `"`macval(terms1)' \`term1`i''"'
|
408 |
+
if "`split'"=="" {
|
409 |
+
local term2`i' (U_`coef':[x1]_b[`coef']*(`m'*[b1]_b[`coef']-`m'*[b2]_b[`coef']) ///
|
410 |
+
+ [x2]_b[`coef']*(`w'*[b1]_b[`coef']-`w'*[b2]_b[`coef']))
|
411 |
+
local terms2 `"`macval(terms2)' \`term2`i''"'
|
412 |
+
}
|
413 |
+
else {
|
414 |
+
local term2`i' (U1_`coef':[x1]_b[`coef']*(`m'*[b1]_b[`coef']-`m'*[b2]_b[`coef']))
|
415 |
+
local term3`i' (U2_`coef':[x2]_b[`coef']*(`w'*[b1]_b[`coef']-`w'*[b2]_b[`coef']))
|
416 |
+
local terms2 `"`macval(terms2)' \`term2`i''"'
|
417 |
+
local terms3 `"`macval(terms3)' \`term3`i''"'
|
418 |
+
}
|
419 |
+
}
|
420 |
+
}
|
421 |
+
if "`split'"=="" {
|
422 |
+
local eqnames "E_ U_"
|
423 |
+
}
|
424 |
+
else {
|
425 |
+
local eqnames "E_ U1_ U2_"
|
426 |
+
}
|
427 |
+
}
|
428 |
+
local plus
|
429 |
+
local xb1
|
430 |
+
local xb2
|
431 |
+
foreach coef of local coefs {
|
432 |
+
local xb1 `xb1'`plus'[x1]_b[`coef']*[b1]_b[`coef']
|
433 |
+
local xb2 `xb2'`plus'[x2]_b[`coef']*[b2]_b[`coef']
|
434 |
+
local plus "+"
|
435 |
+
}
|
436 |
+
local xb1 (D_xb1:`xb1')
|
437 |
+
local xb2 (D_xb2:`xb2')
|
438 |
+
local plus
|
439 |
+
local adj
|
440 |
+
foreach coef of local adjust {
|
441 |
+
local adj `adj'`plus'[x1]_b[`coef']*[b1]_b[`coef']-[x2]_b[`coef']*[b2]_b[`coef']
|
442 |
+
local plus "+"
|
443 |
+
}
|
444 |
+
if `"`adj'"'!="" {
|
445 |
+
local adj (D_adj:`adj')
|
446 |
+
}
|
447 |
+
if `se' {
|
448 |
+
quietly nlcom `xb1' `xb2' `adj' `terms1' `terms2' `terms3', post
|
449 |
+
}
|
450 |
+
else {
|
451 |
+
nlcom_nose `xb1' `xb2' `adj' `terms1' `terms2' `terms3'
|
452 |
+
mat `b' = r(b)
|
453 |
+
eret post `b'
|
454 |
+
}
|
455 |
+
|
456 |
+
// nlcom step 2: totals
|
457 |
+
local terms1
|
458 |
+
local terms2
|
459 |
+
local terms3
|
460 |
+
local j 0
|
461 |
+
foreach eq of local eqnames {
|
462 |
+
local ++j
|
463 |
+
local i 0
|
464 |
+
local term`j'tot
|
465 |
+
local plus
|
466 |
+
foreach group of local cgroups {
|
467 |
+
local ++i
|
468 |
+
local term`j'`i'
|
469 |
+
local plusplus
|
470 |
+
gettoken gname gcoefs : group
|
471 |
+
if `"`gcoefs'"'=="" {
|
472 |
+
local gcoefs `"`gname'"'
|
473 |
+
}
|
474 |
+
foreach coef of local gcoefs {
|
475 |
+
local term`j'tot `term`j'tot'`plus'_b[`eq'`coef']
|
476 |
+
local plus "+"
|
477 |
+
if "`coef'"=="_cons" & inlist("`eq'","E_","I_") continue
|
478 |
+
if "`detail'"!="" {
|
479 |
+
local term`j'`i' `term`j'`i''`plusplus'_b[`eq'`coef']
|
480 |
+
local plusplus "+"
|
481 |
+
}
|
482 |
+
}
|
483 |
+
if `"`term`j'`i''"'!="" {
|
484 |
+
local term`j'`i' (`eq'`gname':`term`j'`i'')
|
485 |
+
local terms`j' `"`macval(terms`j')' \`term`j'`i''"'
|
486 |
+
}
|
487 |
+
}
|
488 |
+
if "`detail'"!="" {
|
489 |
+
local term`j'tot (`eq'Total:`term`j'tot')
|
490 |
+
}
|
491 |
+
else {
|
492 |
+
local term`j'tot (`eq':`term`j'tot')
|
493 |
+
}
|
494 |
+
local terms`j' `"`macval(terms`j')' \`term`j'tot'"'
|
495 |
+
}
|
496 |
+
if `"`adj'"'!="" {
|
497 |
+
local adj (D_Adjusted:_b[D_xb1]-_b[D_xb2]-_b[D_adj])
|
498 |
+
}
|
499 |
+
if `se' {
|
500 |
+
quietly nlcom (D_Prediction_1:_b[D_xb1]) (D_Prediction_2:_b[D_xb2]) ///
|
501 |
+
(D_Difference:_b[D_xb1]-_b[D_xb2]) `adj' ///
|
502 |
+
`terms1' `terms2' `terms3'
|
503 |
+
mat `b' = r(b)
|
504 |
+
mat `V' = r(V)
|
505 |
+
}
|
506 |
+
else {
|
507 |
+
nlcom_nose (D_Prediction_1:_b[D_xb1]) (D_Prediction_2:_b[D_xb2]) ///
|
508 |
+
(D_Difference:_b[D_xb1]-_b[D_xb2]) `adj' ///
|
509 |
+
`terms1' `terms2' `terms3'
|
510 |
+
mat `b' = r(b)
|
511 |
+
}
|
512 |
+
}
|
513 |
+
else {
|
514 |
+
mata: oaxaca_decomp()
|
515 |
+
}
|
516 |
+
if `se'==0 {
|
517 |
+
mat `V' = `b''*`b'*0
|
518 |
+
}
|
519 |
+
|
520 |
+
// post results
|
521 |
+
local coln: coln `b'
|
522 |
+
local coln `" `coln'"'
|
523 |
+
local coln: subinstr local coln " D_" " Differential:", all
|
524 |
+
local eqcolon = cond("`detail'"!="",":","")
|
525 |
+
local eqname = cond("`detail'"!="","","Decomposition:")
|
526 |
+
if "`threefold'"!="" {
|
527 |
+
local coln: subinstr local coln " E_" " `eqname'Endowments`eqcolon'", all
|
528 |
+
local coln: subinstr local coln " C_" " `eqname'Coefficients`eqcolon'", all
|
529 |
+
local coln: subinstr local coln " I_" " `eqname'Interaction`eqcolon'", all
|
530 |
+
}
|
531 |
+
else {
|
532 |
+
local coln: subinstr local coln " E_" " `eqname'Explained`eqcolon'", all
|
533 |
+
if "`split'"=="" {
|
534 |
+
local coln: subinstr local coln " U_" " `eqname'Unexplained`eqcolon'", all
|
535 |
+
}
|
536 |
+
else {
|
537 |
+
local coln: subinstr local coln " U1_" " `eqname'Unexplained_1`eqcolon'", all
|
538 |
+
local coln: subinstr local coln " U2_" " `eqname'Unexplained_2`eqcolon'", all
|
539 |
+
}
|
540 |
+
}
|
541 |
+
mat coln `b' = `coln'
|
542 |
+
mat coln `V' = `coln'
|
543 |
+
mat rown `V' = `coln'
|
544 |
+
if "`threefold'"!="" local model threefold `threefold2'
|
545 |
+
else local model twofold `split'
|
546 |
+
if "`reference'"!="" local refcoefs "b_ref"
|
547 |
+
if `"`detail2'"'!="" {
|
548 |
+
local dlegend
|
549 |
+
local space
|
550 |
+
foreach cgroup of local cgroups {
|
551 |
+
if `:list sizeof cgroup'>1 {
|
552 |
+
gettoken name vars : cgroup
|
553 |
+
local dlegend `"`dlegend'`space'"`name':`vars'""'
|
554 |
+
local space " "
|
555 |
+
}
|
556 |
+
}
|
557 |
+
}
|
558 |
+
PostResults `b' `V', b0(`b0') v0(`V0') `depname' esample(`touse') ///
|
559 |
+
suest(`suest') model(`model') weights(`weights') ///
|
560 |
+
refcoefs(`refcoefs') detail(`detail') legend(`dlegend') ///
|
561 |
+
adjust(`adjust') fixed(`fixedx') ///
|
562 |
+
n1(`N1') n2(`N2') wtype(`e_wtype') wexp(`e_wexp') ///
|
563 |
+
vce(`e_vce') vcetype(`e_vcetype') n_clust(`e_N_clust') ///
|
564 |
+
clustvar(`e_clustvar') prefix(`e_prefix') n_strata(`e_N_strata') ///
|
565 |
+
n_psu(`e_N_psu') n_pop(`e_N_pop') df_r(`e_df_r')
|
566 |
+
|
567 |
+
// display
|
568 |
+
if "`display'"=="" {
|
569 |
+
Display, `level' `eform' `xb' `legend'
|
570 |
+
}
|
571 |
+
|
572 |
+
// cleanup
|
573 |
+
_est unhold `hcurrent', not
|
574 |
+
end
|
575 |
+
|
576 |
+
prog _parse_elist
|
577 |
+
syntax namelist(name=elist min=2 max=2)
|
578 |
+
if "`:word 1 of `elist''"=="`:word 2 of `elist''" {
|
579 |
+
di as err "namelist: too few specified"
|
580 |
+
exit 102
|
581 |
+
}
|
582 |
+
c_local elist "`elist'"
|
583 |
+
end
|
584 |
+
|
585 |
+
prog Display, eclass
|
586 |
+
syntax [, level(passthru) eform xb noLEgend ]
|
587 |
+
if !inlist("`e(cmd)'","_oaxaca","oaxaca") {
|
588 |
+
error 301
|
589 |
+
}
|
590 |
+
if "`eform'"!="" {
|
591 |
+
local eform "eform(exp(b))"
|
592 |
+
tempname b
|
593 |
+
mat `b' = e(b)
|
594 |
+
local coln: colnames `b'
|
595 |
+
local newcoln: subinstr local coln "_cons" "__cons", word count(local cons)
|
596 |
+
if `cons' {
|
597 |
+
mat coln `b' = `newcoln'
|
598 |
+
ereturn repost b = `b', rename
|
599 |
+
}
|
600 |
+
}
|
601 |
+
_coef_table_header
|
602 |
+
eret display, `level' `eform'
|
603 |
+
if "`eform'"!="" {
|
604 |
+
if `cons' {
|
605 |
+
mat `b' = e(b)
|
606 |
+
mat coln `b' = `coln'
|
607 |
+
ereturn repost b = `b', rename
|
608 |
+
}
|
609 |
+
}
|
610 |
+
if "`legend'"=="" {
|
611 |
+
Display_legend
|
612 |
+
}
|
613 |
+
if `"`xb'"'!="" {
|
614 |
+
Display_b0, `level'
|
615 |
+
}
|
616 |
+
end
|
617 |
+
|
618 |
+
prog Display_legend
|
619 |
+
if `"`e(legend)'"'=="" exit
|
620 |
+
foreach line in `e(legend)' {
|
621 |
+
local i 0
|
622 |
+
local piece: piece `++i' 78 of `"`line'"'
|
623 |
+
di as txt `"`piece'"'
|
624 |
+
while (1) {
|
625 |
+
local piece: piece `++i' 76 of `"`line'"'
|
626 |
+
if `"`piece'"'=="" continue, break
|
627 |
+
di as txt `" `piece'"'
|
628 |
+
}
|
629 |
+
}
|
630 |
+
end
|
631 |
+
|
632 |
+
prog Display_b0
|
633 |
+
syntax [, Level(passthru)]
|
634 |
+
tempname hcurrent b V
|
635 |
+
mat `b' = e(b0)
|
636 |
+
mat `V' = e(V0)
|
637 |
+
_est hold `hcurrent', restore estsystem
|
638 |
+
di _n "Coefficients (b) and means (x)"
|
639 |
+
eret post `b' `V'
|
640 |
+
eret display, `level'
|
641 |
+
end
|
642 |
+
|
643 |
+
prog _marksubpop
|
644 |
+
syntax [varname(default=none)] [if], g(name)
|
645 |
+
marksample touse
|
646 |
+
if "`varlist'"!="" {
|
647 |
+
qui replace `touse' = 0 if `varlist'==0
|
648 |
+
}
|
649 |
+
rename `touse' `g'
|
650 |
+
end
|
651 |
+
|
652 |
+
prog ExtractFirstEqs
|
653 |
+
args eqlab b V
|
654 |
+
local i 0
|
655 |
+
foreach nm in `e(names)' {
|
656 |
+
local ++i
|
657 |
+
local suffix: word 1 of `e(eqnames`i')'
|
658 |
+
if `"`suffix'"'!="_" {
|
659 |
+
local nm `"`nm'_`suffix'"'
|
660 |
+
}
|
661 |
+
local oldeqs `"`oldeqs'`space'`nm'"'
|
662 |
+
local neweqs `"`neweqs'`space'`:word `i' of `eqlab''"'
|
663 |
+
local space " "
|
664 |
+
}
|
665 |
+
mata: oaxaca_extracteqs()
|
666 |
+
end
|
667 |
+
|
668 |
+
prog MatAppendDiag
|
669 |
+
args A D
|
670 |
+
tempname B C
|
671 |
+
mat `B' = J(rowsof(`A'),colsof(`D'),0)
|
672 |
+
mat coln `B' = `:colfullnames `D''
|
673 |
+
mat `C' = J(rowsof(`D'),colsof(`A'),0)
|
674 |
+
mat rown `C' = `:rowfullnames `D''
|
675 |
+
mat `A' = (`A', `B') \ (`C', `D')
|
676 |
+
end
|
677 |
+
|
678 |
+
program _parsesvyopt
|
679 |
+
syntax [anything] [, SUBpop(str asis) * ]
|
680 |
+
|
681 |
+
c_local svy_type `"`anything'"'
|
682 |
+
c_local svy_opts `"`options'"'
|
683 |
+
c_local svy_subpop `"`subpop'"'
|
684 |
+
end
|
685 |
+
|
686 |
+
program _vce_iscluster
|
687 |
+
syntax [anything] [, * ]
|
688 |
+
local vce_type: word 1 of `anything'
|
689 |
+
local iscluster 0
|
690 |
+
if `"`vce_type'"'==substr("cluster",1,max(2,strlen(`"`vce_type'"'))) local iscluster 1
|
691 |
+
c_local vce_iscluster `iscluster'
|
692 |
+
end
|
693 |
+
|
694 |
+
program _parsesvysubpop
|
695 |
+
syntax [varname(default=none)] [if/]
|
696 |
+
if `"`if'"'!="" {
|
697 |
+
local iff `"(`if') & "'
|
698 |
+
}
|
699 |
+
c_local svy_subpop `"`varlist' if `iff'1"'
|
700 |
+
end
|
701 |
+
|
702 |
+
program define _devcon
|
703 |
+
// based on devcon.ado from SSC, version 1.0.9 06dec2005, by Ben Jann
|
704 |
+
version 9.2
|
705 |
+
syntax anything, Groups(passthru)
|
706 |
+
gettoken b: anything
|
707 |
+
|
708 |
+
mat `b' = `b''
|
709 |
+
local eqs: roweq `b', quoted
|
710 |
+
local eqs: list uniq eqs
|
711 |
+
foreach eq of local eqs {
|
712 |
+
__devcon `anything', `groups' eq(`eq':) eqs(`eqs')
|
713 |
+
}
|
714 |
+
mat `b' = `b''
|
715 |
+
end
|
716 |
+
|
717 |
+
program define __devcon, eclass
|
718 |
+
// based on devcon.ado from SSC, version 1.0.9 06dec2005, by Ben Jann
|
719 |
+
syntax anything, Groups(string) [ eq(str asis) eqs(str asis) ]
|
720 |
+
gettoken b V: anything
|
721 |
+
gettoken V : V
|
722 |
+
local hasV = (`"`V'"'!="")
|
723 |
+
|
724 |
+
// get coef names
|
725 |
+
tempname btmp
|
726 |
+
mat `btmp' = `b'[`"`eq'"',1]
|
727 |
+
local vars: rownames `btmp'
|
728 |
+
mat drop `btmp'
|
729 |
+
local rest `vars'
|
730 |
+
|
731 |
+
// parse groups
|
732 |
+
gettoken 1 groups : groups, parse(",")
|
733 |
+
while `"`1'"'!="" {
|
734 |
+
gettoken 1 cons : 1, parse("(")
|
735 |
+
if "`cons'"!="" {
|
736 |
+
unab cons: `cons'
|
737 |
+
}
|
738 |
+
if "`cons'"=="" local cons _cons
|
739 |
+
if !`:list cons in vars' {
|
740 |
+
di as error `"categorical(): `cons' not found"'
|
741 |
+
exit 111
|
742 |
+
}
|
743 |
+
unab 1: `1'
|
744 |
+
local keep `1'
|
745 |
+
local ref: list 1 - vars
|
746 |
+
if `:list sizeof ref'>1 {
|
747 |
+
di as txt "categorical(): several possible reference indicators: `ref'"
|
748 |
+
di as txt "using first indicator; this may cause problems"
|
749 |
+
}
|
750 |
+
local ref: word 1 of `ref'
|
751 |
+
if "`ref'"=="" {
|
752 |
+
di as error "categorical(): no reference indicator found"
|
753 |
+
exit 111
|
754 |
+
}
|
755 |
+
local 1: list vars & 1
|
756 |
+
if "`1'"=="" {
|
757 |
+
di as error "invalid categorical() option"
|
758 |
+
exit 198
|
759 |
+
}
|
760 |
+
if !`:list 1 in rest' {
|
761 |
+
di as error "categorical(): groups must be distinct"
|
762 |
+
exit 198
|
763 |
+
}
|
764 |
+
local rest: list rest - 1
|
765 |
+
local 1: list 1 | ref
|
766 |
+
local 1: list keep & 1
|
767 |
+
local gvars `"`gvars'"`1'" "'
|
768 |
+
if `:list ref in refs' {
|
769 |
+
di as error "categorical(): groups must be distinct"
|
770 |
+
exit 198
|
771 |
+
}
|
772 |
+
else local refs "`refs'`ref' "
|
773 |
+
local conss "`conss'`cons' "
|
774 |
+
gettoken 1 groups : groups, parse(",")
|
775 |
+
gettoken 1 groups : groups, parse(",")
|
776 |
+
}
|
777 |
+
|
778 |
+
// determine order of coefficients
|
779 |
+
local var: word 1 of `vars'
|
780 |
+
while "`var'"!="" {
|
781 |
+
if `:list var in rest' {
|
782 |
+
local master `"`master'`"`eq'`var'"' "'
|
783 |
+
local vars: list vars - var
|
784 |
+
}
|
785 |
+
else {
|
786 |
+
foreach gvar of local gvars {
|
787 |
+
if `:list var in gvar' {
|
788 |
+
foreach temp of local gvar {
|
789 |
+
local master `"`master'`"`eq'`temp'"' "'
|
790 |
+
}
|
791 |
+
local vars: list vars - gvar
|
792 |
+
continue, break
|
793 |
+
}
|
794 |
+
}
|
795 |
+
}
|
796 |
+
local var: word 1 of `vars'
|
797 |
+
}
|
798 |
+
|
799 |
+
// normalize coefficients and compute (co-)variances
|
800 |
+
tempname I Icons Vtmp Z
|
801 |
+
local g 0
|
802 |
+
foreach vars of local gvars {
|
803 |
+
local ref: word `++g' of `refs'
|
804 |
+
local cons: word `g' of `conss'
|
805 |
+
local k: word count `vars'
|
806 |
+
// - prepare indicator vector
|
807 |
+
mat `I' = `b' * 0
|
808 |
+
foreach var of local vars {
|
809 |
+
if "`var'"!="`ref'" {
|
810 |
+
mat `I'[rownumb(`I',`"`eq'`var'"'),1] = 1
|
811 |
+
}
|
812 |
+
}
|
813 |
+
mat `Icons' = `I'
|
814 |
+
mat `Icons'[rownumb(`Icons',`"`eq'`cons'"'),1] = -1
|
815 |
+
// - transform coefficients vector
|
816 |
+
mat `btmp' = `I'' * `b' / `k'
|
817 |
+
mat rown `btmp' = `"`eq'`ref'"'
|
818 |
+
mat `b' = `b' - `Icons' * `btmp' \ -`btmp'
|
819 |
+
if `hasV' {
|
820 |
+
// - add ref cat to V
|
821 |
+
mat `Vtmp' = ( `I'' * `V' / `k' )
|
822 |
+
mat rown `Vtmp' = `"`eq'`ref'"'
|
823 |
+
mat `V' = ( `V' \ -`Vtmp' ) , ( ( -`Vtmp'' \ `Vtmp' * `I' / `k' ))
|
824 |
+
// - update indicator vectors and transform V
|
825 |
+
mat `I' = `I' \ `btmp'*0
|
826 |
+
mat `Icons' = `Icons' \ `btmp'*0
|
827 |
+
mat `Vtmp' = ( `I'' * `V' / `k' )
|
828 |
+
mat `V' = `V' - `Icons' * `Vtmp' - `Vtmp'' * `Icons'' ///
|
829 |
+
+ `Vtmp' * `I' / `k' * `Icons' * `Icons''
|
830 |
+
mat drop `Vtmp'
|
831 |
+
}
|
832 |
+
mat drop `btmp'
|
833 |
+
}
|
834 |
+
|
835 |
+
// reorder b and V
|
836 |
+
foreach eqi of local eqs {
|
837 |
+
if `"`eqi':"'==`"`eq'"' {
|
838 |
+
foreach var of local master {
|
839 |
+
mat `btmp' = nullmat(`btmp') \ `b'[`"`var'"',1]
|
840 |
+
}
|
841 |
+
}
|
842 |
+
else {
|
843 |
+
mat `btmp' = nullmat(`btmp') \ `b'[`"`eqi':"',1]
|
844 |
+
}
|
845 |
+
}
|
846 |
+
mat `b' = `btmp'
|
847 |
+
mat drop `btmp'
|
848 |
+
if `hasV' {
|
849 |
+
foreach eqi of local eqs {
|
850 |
+
if `"`eqi':"'==`"`eq'"' {
|
851 |
+
foreach var of local master {
|
852 |
+
mat `Vtmp' = nullmat(`Vtmp') \ `V'[`"`var'"',1...]
|
853 |
+
}
|
854 |
+
}
|
855 |
+
else {
|
856 |
+
mat `Vtmp' = nullmat(`Vtmp') \ `V'[`"`eqi':"',1...]
|
857 |
+
}
|
858 |
+
}
|
859 |
+
mat `V' = `Vtmp'
|
860 |
+
mat drop `Vtmp'
|
861 |
+
foreach eqi of local eqs {
|
862 |
+
if `"`eqi':"'==`"`eq'"' {
|
863 |
+
foreach var of local master {
|
864 |
+
mat `Vtmp' = nullmat(`Vtmp') , `V'[1...,`"`var'"']
|
865 |
+
}
|
866 |
+
}
|
867 |
+
else {
|
868 |
+
mat `Vtmp' = nullmat(`Vtmp') , `V'[1...,`"`eqi':"']
|
869 |
+
}
|
870 |
+
}
|
871 |
+
mat `V' = `Vtmp'
|
872 |
+
mat drop `Vtmp'
|
873 |
+
}
|
874 |
+
end
|
875 |
+
|
876 |
+
prog _setXvals
|
877 |
+
syntax anything, se(str) [ x1(str) x2(str) ]
|
878 |
+
gettoken x Vx : anything
|
879 |
+
gettoken Vx : Vx
|
880 |
+
tempname tmp
|
881 |
+
local fixedx
|
882 |
+
forv i = 1/2 {
|
883 |
+
if `"`x`i''"'=="" continue
|
884 |
+
mat `tmp' = `x'[1,"x`i':"]
|
885 |
+
local coefs: colnames `tmp'
|
886 |
+
while (1) {
|
887 |
+
if `"`x`i''"'=="" continue, break
|
888 |
+
gettoken var x`i' : x`i', parse(" =,")
|
889 |
+
if `"`var'"'=="," {
|
890 |
+
gettoken var x`i' : x`i', parse(" =")
|
891 |
+
}
|
892 |
+
gettoken val x`i' : x`i', parse(" =,")
|
893 |
+
if `"`val'"'=="=" {
|
894 |
+
gettoken val x`i' : x`i', parse(" ,")
|
895 |
+
}
|
896 |
+
capt confirm number `val'
|
897 |
+
if _rc | `"`var'"'=="" {
|
898 |
+
di as err "invalid x`i'() option"
|
899 |
+
exit 198
|
900 |
+
}
|
901 |
+
capt unab trash : `var'
|
902 |
+
if _rc {
|
903 |
+
local trash `"`var'"'
|
904 |
+
}
|
905 |
+
local vars: list coefs & trash
|
906 |
+
if `"`vars'"'=="" {
|
907 |
+
di as err `"x`i'(): `var' not found"'
|
908 |
+
exit 111
|
909 |
+
}
|
910 |
+
local coefs: list coefs - vars
|
911 |
+
foreach v of local vars {
|
912 |
+
mat `x'[1,colnumb(`x',`"x`i':`v'"')] = `val'
|
913 |
+
local fixedx `"`fixedx' `"x`i':`v'"'"'
|
914 |
+
}
|
915 |
+
}
|
916 |
+
}
|
917 |
+
if `se' {
|
918 |
+
mata: oaxaca_setfixedXtozero(1)
|
919 |
+
}
|
920 |
+
end
|
921 |
+
|
922 |
+
program _eretpostcmd, eclass
|
923 |
+
eret local cmd "_oaxaca"
|
924 |
+
end
|
925 |
+
|
926 |
+
program _parsedetail2
|
927 |
+
syntax [, Detail2(str) coefs(str) ]
|
928 |
+
local rest "`coefs'"
|
929 |
+
while (1) {
|
930 |
+
if `"`detail2'"'=="" continue, break
|
931 |
+
gettoken group detail2 : detail2, parse(",")
|
932 |
+
gettoken gname vars : group, parse("=:")
|
933 |
+
gettoken trash vars: vars, parse("=:")
|
934 |
+
if `"`gname'"'=="" | `"`vars'"'=="" {
|
935 |
+
di as err "invalid detail() option"
|
936 |
+
exit 198
|
937 |
+
}
|
938 |
+
local gvars
|
939 |
+
foreach var of local vars {
|
940 |
+
capt unab trash: `var'
|
941 |
+
if _rc local trash `"`var'"'
|
942 |
+
local svar: list rest & trash
|
943 |
+
if "`svar'"=="" {
|
944 |
+
di as err `"`var' not found"'
|
945 |
+
exit 111
|
946 |
+
}
|
947 |
+
else {
|
948 |
+
local rest: list rest - svar
|
949 |
+
}
|
950 |
+
local gvars: list gvars | svar
|
951 |
+
}
|
952 |
+
local groups `"`groups' "`gname' `gvars'""'
|
953 |
+
gettoken group detail2 : detail2, parse(",") // get rid of leading comma
|
954 |
+
}
|
955 |
+
local cgroups
|
956 |
+
while (1) {
|
957 |
+
if `"`coefs'"'=="" continue, break
|
958 |
+
gettoken coef coefs : coefs
|
959 |
+
if `:list coef in rest' {
|
960 |
+
local cgroups `"`cgroups' "`coef'""'
|
961 |
+
}
|
962 |
+
else {
|
963 |
+
foreach group in `groups' {
|
964 |
+
gettoken name vars : group
|
965 |
+
if `:list coef in vars' {
|
966 |
+
local group `""`group'""'
|
967 |
+
local cgroups `"`cgroups' `group'"'
|
968 |
+
local groups: list groups - group
|
969 |
+
local coefs: list coefs - vars
|
970 |
+
continue, break
|
971 |
+
}
|
972 |
+
}
|
973 |
+
}
|
974 |
+
}
|
975 |
+
c_local cgroups `"`cgroups'"'
|
976 |
+
end
|
977 |
+
|
978 |
+
program _parseadjust
|
979 |
+
syntax [, adjust(str) coefs(str) ]
|
980 |
+
foreach var of local adjust {
|
981 |
+
capt unab trash: `var'
|
982 |
+
if _rc local trash `"`var'"'
|
983 |
+
local svar: list coefs & trash
|
984 |
+
if "`svar'"=="" {
|
985 |
+
di as err `"`var' not found"'
|
986 |
+
exit 111
|
987 |
+
}
|
988 |
+
else {
|
989 |
+
local coefs: list coefs - svar
|
990 |
+
}
|
991 |
+
local vars: list vars | svar
|
992 |
+
}
|
993 |
+
c_local adjust `"`vars'"'
|
994 |
+
c_local coefsadj `"`coefs'"'
|
995 |
+
end
|
996 |
+
|
997 |
+
program nlcom_nose, rclass
|
998 |
+
gettoken term rest : 0, match(paren)
|
999 |
+
tempname b
|
1000 |
+
while (1) {
|
1001 |
+
if `"`term'"'=="" continue, break
|
1002 |
+
gettoken name exp : term, parse(":")
|
1003 |
+
gettoken trash exp : exp, parse(":")
|
1004 |
+
mat `b' = nullmat(`b'), (`exp')
|
1005 |
+
local coln `"`coln' `"`name'"'"'
|
1006 |
+
gettoken term rest : rest, match(paren)
|
1007 |
+
}
|
1008 |
+
mat coln `b' = `coln'
|
1009 |
+
ret mat b = `b'
|
1010 |
+
end
|
1011 |
+
|
1012 |
+
program PostResults, eclass
|
1013 |
+
syntax anything, b0(str) esample(str) suest(str) [ ///
|
1014 |
+
depname(str) model(str) weights(str) refcoefs(str) ///
|
1015 |
+
detail(str) legend(str asis) adjust(str) fixed(str) ///
|
1016 |
+
v0(str) n1(str) n2(str) ///
|
1017 |
+
wtype(str) wexp(str asis) vce(str) vcetype(str) ///
|
1018 |
+
n_clust(str) clustvar(str) prefix(str) n_strata(str) ///
|
1019 |
+
n_psu(str) n_pop(str) df_r(str) ]
|
1020 |
+
qui count if `esample'
|
1021 |
+
if `"`depname'"'!="" {
|
1022 |
+
local depvar `"`depname'"'
|
1023 |
+
local depname `"depname(`depname')"'
|
1024 |
+
}
|
1025 |
+
eret post `anything', esample(`esample') obs(`r(N)') `depname'
|
1026 |
+
foreach opt in prefix clustvar vcetype vce wexp wtype {
|
1027 |
+
eret local `opt' `"``opt''"'
|
1028 |
+
}
|
1029 |
+
if `suest' eret local suest suest
|
1030 |
+
foreach opt in fixed adjust legend detail refcoefs weights model depvar {
|
1031 |
+
eret local `opt' `"``opt''"'
|
1032 |
+
}
|
1033 |
+
eret local title "Blinder-Oaxaca decomposition"
|
1034 |
+
eret local cmd "_oaxaca"
|
1035 |
+
if "`n1'`n2'"!="" {
|
1036 |
+
eret scalar N_1 = `n1'
|
1037 |
+
eret scalar N_2 = `n2'
|
1038 |
+
}
|
1039 |
+
foreach opt in N_clust N_strata N_psu N_pop df_r {
|
1040 |
+
local optt = lower("`opt'")
|
1041 |
+
if `"``optt''"'!="" {
|
1042 |
+
eret scalar `opt' = ``optt''
|
1043 |
+
}
|
1044 |
+
}
|
1045 |
+
eret mat b0 = `b0'
|
1046 |
+
if "`v0'"!="" {
|
1047 |
+
eret mat V0 = `v0'
|
1048 |
+
}
|
1049 |
+
end
|
1050 |
+
|
1051 |
+
version 9.2
|
1052 |
+
mata:
|
1053 |
+
|
1054 |
+
void oaxaca_extracteqs()
|
1055 |
+
{
|
1056 |
+
b = st_matrix(st_local("b"))
|
1057 |
+
V = st_matrix(st_local("V"))
|
1058 |
+
old = tokens(st_local("oldeqs"))
|
1059 |
+
newi = tokens(st_local("neweqs"))
|
1060 |
+
stripe = st_matrixcolstripe(st_local("b"))
|
1061 |
+
r = 0
|
1062 |
+
j = 1
|
1063 |
+
match = 0
|
1064 |
+
for (i=1; i<=rows(stripe); i++) {
|
1065 |
+
if (stripe[i,1]==old[j]) {
|
1066 |
+
r++
|
1067 |
+
match = 1
|
1068 |
+
}
|
1069 |
+
else if (match) {
|
1070 |
+
j++
|
1071 |
+
i--
|
1072 |
+
match = 0
|
1073 |
+
}
|
1074 |
+
if (j>length(old)) break
|
1075 |
+
}
|
1076 |
+
p = J(r,1,.)
|
1077 |
+
r = 0
|
1078 |
+
j = 1
|
1079 |
+
for (i=1; i<=rows(stripe); i++) {
|
1080 |
+
if (stripe[i,1]==old[j]) {
|
1081 |
+
p[++r] = i
|
1082 |
+
match = 1
|
1083 |
+
stripe[i,1] = newi[j]
|
1084 |
+
}
|
1085 |
+
else if (match) {
|
1086 |
+
j++
|
1087 |
+
i--
|
1088 |
+
match = 0
|
1089 |
+
}
|
1090 |
+
if (j>length(old)) break
|
1091 |
+
}
|
1092 |
+
b = b[,p]
|
1093 |
+
V = V[p,p]
|
1094 |
+
stripe = stripe[p,]
|
1095 |
+
st_matrix(st_local("b"), b)
|
1096 |
+
st_matrixcolstripe(st_local("b"), stripe)
|
1097 |
+
st_matrix(st_local("V"), V)
|
1098 |
+
st_matrixcolstripe(st_local("V"), stripe)
|
1099 |
+
st_matrixrowstripe(st_local("V"), stripe)
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
void oaxaca_insertmissingcoefs()
|
1103 |
+
{
|
1104 |
+
b = st_matrix(st_local("b"))
|
1105 |
+
stripe = st_matrixcolstripe(st_local("b"))
|
1106 |
+
coefs = select(stripe[,2],(stripe[,1]:=="b1"))
|
1107 |
+
coefs2 = select(stripe[,2],(stripe[,1]:=="b2"))
|
1108 |
+
r = 0
|
1109 |
+
for (i=1; i<=length(coefs2); i++) {
|
1110 |
+
if (anyof(coefs, coefs2[i])==0) r++
|
1111 |
+
}
|
1112 |
+
if (r>0) {
|
1113 |
+
p = J(r,1,.)
|
1114 |
+
r = 0
|
1115 |
+
for (i=1; i<=length(coefs2); i++) {
|
1116 |
+
if (anyof(coefs, coefs2[i])==0) p[++r] = i
|
1117 |
+
}
|
1118 |
+
coefs = coefs \ coefs2[p]
|
1119 |
+
}
|
1120 |
+
if (anyof(coefs,"_cons") & !allof(coefs,"_cons")) {
|
1121 |
+
coefs = select(coefs,coefs:!="_cons") \ "_cons"
|
1122 |
+
}
|
1123 |
+
ncoef = length(coefs)
|
1124 |
+
neq = 2 + (stripe[rows(stripe),1]=="b_ref")
|
1125 |
+
r = 0
|
1126 |
+
for (j=1; j<=neq; j++) {
|
1127 |
+
eq = ("b1", "b2", "b_ref")[j]
|
1128 |
+
for (i=1; i<=ncoef; i++) {
|
1129 |
+
r = r + (length(oaxaca_which(stripe[,1]:==eq :& stripe[,2]:==coefs[i]))>0)
|
1130 |
+
}
|
1131 |
+
}
|
1132 |
+
p = J(r,1,.)
|
1133 |
+
r = 1
|
1134 |
+
p0 = (1::neq*ncoef)
|
1135 |
+
for (j=1; j<=neq; j++) {
|
1136 |
+
eq = ("b1", "b2", "b_ref")[j]
|
1137 |
+
for (i=1; i<=ncoef; i++) {
|
1138 |
+
tmp = oaxaca_which(stripe[,1]:==eq :& stripe[,2]:==coefs[i])
|
1139 |
+
if (length(tmp)>0) {
|
1140 |
+
p[r++] = tmp[1]
|
1141 |
+
}
|
1142 |
+
else p0[(j-1)*ncoef+i] = .
|
1143 |
+
}
|
1144 |
+
}
|
1145 |
+
p0 = select(p0, p0:!=.)
|
1146 |
+
bnew = J(1,neq*ncoef,0)
|
1147 |
+
bnew[p0] = b[p]
|
1148 |
+
stripenew = (J(ncoef,1,"b1"),coefs) \ (J(ncoef,1,"b2"),coefs)
|
1149 |
+
if (neq==3) stripenew = (stripenew) \ (J(ncoef,1,"b_ref"),coefs)
|
1150 |
+
st_matrix(st_local("b"), bnew)
|
1151 |
+
st_matrixcolstripe(st_local("b"), stripenew)
|
1152 |
+
st_local("coefs",oaxaca_invtokens(coefs))
|
1153 |
+
if (st_local("se")=="1") {
|
1154 |
+
V = st_matrix(st_local("V"))
|
1155 |
+
Vnew = J(rows(V),neq*ncoef,0)
|
1156 |
+
Vnew[,p0] = V[,p]
|
1157 |
+
V = J(neq*ncoef,neq*ncoef,0)
|
1158 |
+
V[p0,] = Vnew[p,]
|
1159 |
+
st_matrix(st_local("V"), V)
|
1160 |
+
st_matrixcolstripe(st_local("V"), stripenew)
|
1161 |
+
st_matrixrowstripe(st_local("V"), stripenew)
|
1162 |
+
}
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
void oaxaca_reorderxandVx()
|
1166 |
+
{
|
1167 |
+
b = st_matrix(st_local("x"))
|
1168 |
+
coefs = st_matrixcolstripe(st_local("x")) //tokens(st_local("coefs"))'
|
1169 |
+
k = length(b)
|
1170 |
+
p = range(1, k-1, 2) \ range(2, k, 2)
|
1171 |
+
b = b[p]
|
1172 |
+
stripe = ("x":+coefs[p,2]), coefs[p,1] //(J(length(coefs),1,"x1"),coefs) \ (J(length(coefs),1,"x2"),coefs)
|
1173 |
+
st_matrix(st_local("x"), b)
|
1174 |
+
st_matrixcolstripe(st_local("x"), stripe)
|
1175 |
+
if (st_local("se")=="1") {
|
1176 |
+
V = st_matrix(st_local("Vx"))
|
1177 |
+
V = V[p,p]
|
1178 |
+
st_matrix(st_local("Vx"), V)
|
1179 |
+
st_matrixcolstripe(st_local("Vx"), stripe)
|
1180 |
+
st_matrixrowstripe(st_local("Vx"), stripe)
|
1181 |
+
}
|
1182 |
+
}
|
1183 |
+
|
1184 |
+
void oaxaca_setfixedXtozero(real scalar eq)
|
1185 |
+
{
|
1186 |
+
V = st_matrix(st_local("Vx"))
|
1187 |
+
fixed = tokens(st_local("fixedx"))'
|
1188 |
+
if (eq) {
|
1189 |
+
stripe = st_matrixcolstripe(st_local("Vx"))
|
1190 |
+
stripe = stripe[,1] :+ ":" :+ stripe[,2]
|
1191 |
+
}
|
1192 |
+
else stripe = st_matrixcolstripe(st_local("Vx"))[,2]
|
1193 |
+
r = 0
|
1194 |
+
for (i=1;i<=length(fixed);i++) {
|
1195 |
+
r = r + length(oaxaca_which(stripe:==fixed[i]))
|
1196 |
+
}
|
1197 |
+
p = J(r,1,.)
|
1198 |
+
r = 1
|
1199 |
+
for (i=1;i<=length(fixed);i++) {
|
1200 |
+
tmp = oaxaca_which(stripe:==fixed[i])
|
1201 |
+
p[|r \ r+length(tmp)-1|] = tmp
|
1202 |
+
r = r + length(tmp)
|
1203 |
+
}
|
1204 |
+
V[p,] = V[p,]*0
|
1205 |
+
V[,p] = V[,p]*0
|
1206 |
+
st_replacematrix(st_local("Vx"),V)
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
void oaxaca_decomp()
|
1210 |
+
{
|
1211 |
+
se = (st_local("se")=="1")
|
1212 |
+
tf = (st_local("threefold")!="")
|
1213 |
+
tfr = (st_local("threefold2")!="")
|
1214 |
+
ref = (st_local("reference")!="")
|
1215 |
+
wgt = strtoreal(tokens(st_local("weights")))
|
1216 |
+
split = (st_local("split")!="")
|
1217 |
+
detail = (st_local("detail")!="")
|
1218 |
+
cgroups = tokens(st_local("cgroups"))
|
1219 |
+
ngrp = length(cgroups)
|
1220 |
+
adjust = tokens(st_local("adjust"))
|
1221 |
+
adjyes = length(adjust)>0
|
1222 |
+
b = st_matrix("e(b)")
|
1223 |
+
stripe = st_matrixcolstripe("e(b)")
|
1224 |
+
if (se) V = st_matrix("e(V)")
|
1225 |
+
ncoefs = 0
|
1226 |
+
for (i=1; i<=ngrp; i++) {
|
1227 |
+
ncoefs = ncoefs + max(((length(tokens(cgroups[i]))-1),1))
|
1228 |
+
}
|
1229 |
+
if (length(wgt)>0) { // expand wgt (recycle)
|
1230 |
+
w = J(1,ncoefs,.)
|
1231 |
+
for (i=1; i<=ncoefs; i=i+length(wgt)) {
|
1232 |
+
r = i + length(wgt) - 1
|
1233 |
+
if (r<=ncoefs) w[|i \ r|] = wgt
|
1234 |
+
else w[|i \ ncoefs|] = wgt[|1 \ i-ncoefs+1|]
|
1235 |
+
}
|
1236 |
+
m = 1:-w
|
1237 |
+
}
|
1238 |
+
b1 = x1 = b2 = x2 = p = J(1,ncoefs,.)
|
1239 |
+
G = J(ncoefs,ngrp,0)
|
1240 |
+
grpnms = J(1,ngrp,"")
|
1241 |
+
k = 0
|
1242 |
+
for (i=1; i<=ngrp; i++) {
|
1243 |
+
grp = tokens(cgroups[i])
|
1244 |
+
if (length(grp)==1) grp = grp, grp
|
1245 |
+
grpnms[i] = grp[1]
|
1246 |
+
for (j=2; j<=length(grp); j++) { // skip first
|
1247 |
+
coef = grp[j]
|
1248 |
+
k++
|
1249 |
+
b1[k] = oaxaca_which(stripe[,1]:=="b1":&stripe[,2]:==coef)
|
1250 |
+
x1[k] = oaxaca_which(stripe[,1]:=="x1":&stripe[,2]:==coef)
|
1251 |
+
b2[k] = oaxaca_which(stripe[,1]:=="b2":&stripe[,2]:==coef)
|
1252 |
+
x2[k] = oaxaca_which(stripe[,1]:=="x2":&stripe[,2]:==coef)
|
1253 |
+
if (ref) p[k] = oaxaca_which(stripe[,1]:=="b_ref":&stripe[,2]:==coef)
|
1254 |
+
G[k,i] = 1
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
coln = "D_Prediction_1", "D_Prediction_2", "D_Difference"
|
1258 |
+
if (length(adjust)>0) {
|
1259 |
+
b1a = x1a = b2a = x2a = J(1,length(adjust),.)
|
1260 |
+
for (i=1; i<=length(adjust); i++) {
|
1261 |
+
coef = adjust[i]
|
1262 |
+
b1a[i] = oaxaca_which(stripe[,1]:=="b1":&stripe[,2]:==coef)
|
1263 |
+
x1a[i] = oaxaca_which(stripe[,1]:=="x1":&stripe[,2]:==coef)
|
1264 |
+
b2a[i] = oaxaca_which(stripe[,1]:=="b2":&stripe[,2]:==coef)
|
1265 |
+
x2a[i] = oaxaca_which(stripe[,1]:=="x2":&stripe[,2]:==coef)
|
1266 |
+
}
|
1267 |
+
res =
|
1268 |
+
b[(x1,x1a)]*b[(b1,b1a)]',
|
1269 |
+
b[(x2,x2a)]*b[(b2,b2a)]',
|
1270 |
+
b[(x1,x1a)]*b[(b1,b1a)]' - b[(x2,x2a)]*b[(b2,b2a)]',
|
1271 |
+
b[x1]*b[b1]' - b[x2]*b[b2]'
|
1272 |
+
coln = coln, "D_Adjusted"
|
1273 |
+
if (se) {
|
1274 |
+
D = J(4, length(b), 0)
|
1275 |
+
D[1,(b1,b1a,x1,x1a)] = b[(x1,x1a,b1,b1a)]
|
1276 |
+
D[2,(b2,b2a,x2,x2a)] = b[(x2,x2a,b2,b2a)]
|
1277 |
+
D[3,(b1,b1a,x1,x1a,b2,b2a,x2,x2a)] = b[(x1,x1a,b1,b1a)], -b[(x2,x2a,b2,b2a)]
|
1278 |
+
D[4,(b1,x1,b2,x2)] = b[(x1,b1)], -b[(x2,b2)]
|
1279 |
+
}
|
1280 |
+
}
|
1281 |
+
else {
|
1282 |
+
res =
|
1283 |
+
b[x1]*b[b1]',
|
1284 |
+
b[x2]*b[b2]',
|
1285 |
+
b[x1]*b[b1]' - b[x2]*b[b2]'
|
1286 |
+
if (se) {
|
1287 |
+
D = J(3, length(b), 0)
|
1288 |
+
D[1,(b1,x1)] = b[(x1,b1)]
|
1289 |
+
D[2,(b2,x2)] = b[(x2,b2)]
|
1290 |
+
D[3,(b1,x1,b2,x2)] = b[(x1,b1)], -b[(x2,b2)]
|
1291 |
+
}
|
1292 |
+
}
|
1293 |
+
if (se) j = rows(D)
|
1294 |
+
if (tfr) { // threefold reverse
|
1295 |
+
if (detail) {
|
1296 |
+
res = res,
|
1297 |
+
((b[x1]-b[x2]) :* b[b1]) * G, (b[x1]-b[x2])*b[b1]',
|
1298 |
+
(b[x1] :* (b[b1]-b[b2])) * G, b[x1]*(b[b1]-b[b2])',
|
1299 |
+
((b[x1]-b[x2]) :* (b[b2]-b[b1])) * G, (b[x1]-b[x2])*(b[b2]-b[b1])'
|
1300 |
+
coln = coln, "E_":+grpnms, "E_Total", "C_":+grpnms, "C_Total",
|
1301 |
+
"I_":+grpnms, "I_Total"
|
1302 |
+
if (se) {
|
1303 |
+
D = D \ J(3*(ngrp+1), length(b), 0)
|
1304 |
+
D[++j::j+ngrp-1,(x1,x2,b1)] = G'*diag(b[b1]),G'*diag(-b[b1]),G'*diag(b[x1]-b[x2])
|
1305 |
+
D[j=j+ngrp,(x1,x2,b1)] = b[b1], -b[b1], b[x1]-b[x2]
|
1306 |
+
D[++j::j+ngrp-1,(x1,b1,b2)] = G'*diag(b[b1]-b[b2]), G'*diag(b[x1]), G'*diag(-b[x1])
|
1307 |
+
D[j=j+ngrp,(x1,b1,b2)] = b[b1]-b[b2], b[x1], -b[x1]
|
1308 |
+
D[++j::j+ngrp-1,(x1,x2,b1,b2)] = G'*diag(b[b2]-b[b1]), G'*diag(b[b1]-b[b2]),
|
1309 |
+
G'*diag(b[x2]-b[x1]), G'*diag(b[x1]-b[x2])
|
1310 |
+
D[j=j+ngrp,(x1,x2,b1,b2)] = b[b2]-b[b1], b[b1]-b[b2], b[x2]-b[x1], b[x1]-b[x2]
|
1311 |
+
}
|
1312 |
+
}
|
1313 |
+
else {
|
1314 |
+
res = res,
|
1315 |
+
(b[x1]-b[x2])*b[b1]',
|
1316 |
+
b[x1]*(b[b1]-b[b2])',
|
1317 |
+
(b[x1]-b[x2])*(b[b2]-b[b1])'
|
1318 |
+
coln = coln, "E_", "C_", "I_"
|
1319 |
+
if (se) {
|
1320 |
+
D = D \ J(3, length(b), 0)
|
1321 |
+
D[++j,(x1,x2,b1)] = b[b1], -b[b1], b[x1]-b[x2]
|
1322 |
+
D[++j,(x1,b1,b2)] = b[b1]-b[b2], b[x1], -b[x1]
|
1323 |
+
D[++j,(x1,x2,b1,b2)] = b[b2]-b[b1], b[b1]-b[b2], b[x2]-b[x1], b[x1]-b[x2]
|
1324 |
+
}
|
1325 |
+
}
|
1326 |
+
}
|
1327 |
+
else if (tf) { // threefold
|
1328 |
+
if (detail) {
|
1329 |
+
res = res,
|
1330 |
+
((b[x1]-b[x2]) :* b[b2]) * G, (b[x1]-b[x2])*b[b2]',
|
1331 |
+
(b[x2] :* (b[b1]-b[b2])) * G, b[x2]*(b[b1]-b[b2])',
|
1332 |
+
((b[x1]-b[x2]) :* (b[b1]-b[b2])) * G, (b[x1]-b[x2])*(b[b1]-b[b2])'
|
1333 |
+
coln = coln, "E_":+grpnms, "E_Total", "C_":+grpnms, "C_Total",
|
1334 |
+
"I_":+grpnms, "I_Total"
|
1335 |
+
if (se) {
|
1336 |
+
D = D \ J(3*(ngrp+1), length(b), 0)
|
1337 |
+
D[++j::j+ngrp-1,(x1,x2,b2)] = G'*diag(b[b2]),G'*diag(-b[b2]),G'*diag(b[x1]-b[x2])
|
1338 |
+
D[j=j+ngrp,(x1,x2,b2)] = b[b2], -b[b2], b[x1]-b[x2]
|
1339 |
+
D[++j::j+ngrp-1,(x2,b1,b2)] = G'*diag(b[b1]-b[b2]), G'*diag(b[x2]), G'*diag(-b[x2])
|
1340 |
+
D[j=j+ngrp,(x2,b1,b2)] = b[b1]-b[b2], b[x2], -b[x2]
|
1341 |
+
D[++j::j+ngrp-1,(x1,x2,b1,b2)] = G'*diag(b[b1]-b[b2]), G'*diag(b[b2]-b[b1]),
|
1342 |
+
G'*diag(b[x1]-b[x2]), G'*diag(b[x2]-b[x1])
|
1343 |
+
D[j=j+ngrp,(x1,x2,b1,b2)] = b[b1]-b[b2], b[b2]-b[b1], b[x1]-b[x2], b[x2]-b[x1]
|
1344 |
+
}
|
1345 |
+
}
|
1346 |
+
else {
|
1347 |
+
res = res,
|
1348 |
+
(b[x1]-b[x2])*b[b2]',
|
1349 |
+
b[x2]*(b[b1]-b[b2])',
|
1350 |
+
(b[x1]-b[x2])*(b[b1]-b[b2])'
|
1351 |
+
coln = coln, "E_", "C_", "I_"
|
1352 |
+
if (se) {
|
1353 |
+
D = D \ J(3, length(b), 0)
|
1354 |
+
D[++j,(x1,x2,b2)] = b[b2], -b[b2], b[x1]-b[x2]
|
1355 |
+
D[++j,(x2,b1,b2)] = b[b1]-b[b2], b[x2], -b[x2]
|
1356 |
+
D[++j,(x1,x2,b1,b2)] = b[b1]-b[b2], b[b2]-b[b1], b[x1]-b[x2], b[x2]-b[x1]
|
1357 |
+
}
|
1358 |
+
}
|
1359 |
+
}
|
1360 |
+
else if (ref) { // reference coefs
|
1361 |
+
if (detail) {
|
1362 |
+
res = res,
|
1363 |
+
((b[x1]-b[x2]) :* b[p]) * G, (b[x1]-b[x2])*b[p]',
|
1364 |
+
(split ? (b[x1] :* (b[b1]-b[p])) * G, b[x1] * (b[b1]-b[p])',
|
1365 |
+
(b[x2] :* (b[p]-b[b2])) * G, b[x2] * (b[p]-b[b2])'
|
1366 |
+
: (b[x1] :* (b[b1]-b[p]) + b[x2] :* (b[p]-b[b2])) * G,
|
1367 |
+
b[x1] * (b[b1]-b[p])' + b[x2] * (b[p]-b[b2])'
|
1368 |
+
)
|
1369 |
+
coln = coln, "E_":+grpnms, "E_Total", (split ?
|
1370 |
+
("U1_":+grpnms, "U1_Total", "U2_":+grpnms, "U2_Total")
|
1371 |
+
: ("U_":+grpnms, "U_Total"))
|
1372 |
+
if (se) {
|
1373 |
+
D = D \ J((2+split)*(ngrp+1), length(b), 0)
|
1374 |
+
D[++j::j+ngrp-1,(x1,x2,p)] = G'*diag(b[p]), G'*diag(-b[p]), G'*diag(b[x1]-b[x2])
|
1375 |
+
D[j=j+ngrp,(x1,x2,p)] = b[p], -b[p], b[x1]-b[x2]
|
1376 |
+
if (split) {
|
1377 |
+
D[++j::j+ngrp-1,(x1,b1,p)] = G'*diag(b[b1]-b[p]), G'*diag(b[x1]), G'*diag(-b[x1])
|
1378 |
+
D[j=j+ngrp,(x1,b1,p)] = b[b1]-b[p], b[x1], -b[x1]
|
1379 |
+
D[++j::j+ngrp-1,(x2,p,b2)] = G'*diag(b[p]-b[b2]), G'*diag(b[x2]), G'*diag(-b[x2])
|
1380 |
+
D[j=j+ngrp,(x2,p,b2)] = b[p]-b[b2], b[x2], -b[x2]
|
1381 |
+
}
|
1382 |
+
else {
|
1383 |
+
D[++j::j+ngrp-1,(x1,x2,b1,b2,p)] = G'*diag(b[b1]-b[p]), G'*diag(b[p]-b[b2]),
|
1384 |
+
G'*diag(b[x1]), G'*diag(-b[x2]), G'*diag(b[x2]-b[x1])
|
1385 |
+
D[j=j+ngrp,(x1,x2,b1,b2,p)] = b[b1]-b[p], b[p]-b[b2], b[x1], -b[x2], b[x2]-b[x1]
|
1386 |
+
}
|
1387 |
+
}
|
1388 |
+
}
|
1389 |
+
else {
|
1390 |
+
res = res,
|
1391 |
+
(b[x1]-b[x2])*b[p]',
|
1392 |
+
(split ? b[x1] * (b[b1]-b[p])', b[x2] * (b[p]-b[b2])'
|
1393 |
+
: b[x1] * (b[b1]-b[p])' + b[x2] * (b[p]-b[b2])'
|
1394 |
+
)
|
1395 |
+
coln = coln, "E_", (split ? ("U1_", "U2_") : "U_")
|
1396 |
+
if (se) {
|
1397 |
+
D = D \ J(2+split, length(b), 0)
|
1398 |
+
D[++j,(x1,x2,p)] = b[p], -b[p], b[x1]-b[x2]
|
1399 |
+
if (split) {
|
1400 |
+
D[++j,(x1,b1,p)] = b[b1]-b[p], b[x1], -b[x1]
|
1401 |
+
D[++j,(x2,p,b2)] = b[p]-b[b2], b[x2], -b[x2]
|
1402 |
+
}
|
1403 |
+
else {
|
1404 |
+
D[++j,(x1,x2,b1,b2,p)] = b[b1]-b[p], b[p]-b[b2], b[x1], -b[x2], b[x2]-b[x1]
|
1405 |
+
}
|
1406 |
+
}
|
1407 |
+
}
|
1408 |
+
}
|
1409 |
+
else /*if length(wgt)>0*/ { // weights
|
1410 |
+
if (detail) {
|
1411 |
+
res = res,
|
1412 |
+
((b[x1]-b[x2]) :* (w:*b[b1]+m:*b[b2])) * G,
|
1413 |
+
(b[x1]-b[x2]) * (w:*b[b1]+m:*b[b2])',
|
1414 |
+
(split ? (b[x1] :* (m:*b[b1]-m:*b[b2])) * G, b[x1] * (m:*b[b1]-m:*b[b2])',
|
1415 |
+
(b[x2] :* (w:*b[b1]-w:*b[b2])) * G, b[x2] * (w:*b[b1]-w:*b[b2])'
|
1416 |
+
: (b[x1] :* (m:*b[b1]-m:*b[b2]) + b[x2] :* (w:*b[b1]-w:*b[b2])) * G,
|
1417 |
+
b[x1] * (m:*b[b1]-m:*b[b2])' + b[x2] * (w:*b[b1]-w:*b[b2])'
|
1418 |
+
)
|
1419 |
+
coln = coln, "E_":+grpnms, "E_Total", (split ?
|
1420 |
+
("U1_":+grpnms, "U1_Total", "U2_":+grpnms, "U2_Total")
|
1421 |
+
: ("U_":+grpnms, "U_Total"))
|
1422 |
+
if (se) {
|
1423 |
+
D = D \ J((2+split)*(ngrp+1), length(b), 0)
|
1424 |
+
D[++j::j+ngrp-1,(x1,x2,b1,b2)] =
|
1425 |
+
G'*diag(w:*b[b1]+m:*b[b2]), G'*diag(-w:*b[b1]-m:*b[b2]),
|
1426 |
+
G'*diag(w:*b[x1]-w:*b[x2]), G'*diag(m:*b[x1]-m:*b[x2])
|
1427 |
+
D[j=j+ngrp,(x1,x2,b1,b2)] = w:*b[b1]+m:*b[b2], -w:*b[b1]-m:*b[b2],
|
1428 |
+
w:*b[x1]-w:*b[x2], m:*b[x1]-m:*b[x2]
|
1429 |
+
if (split) {
|
1430 |
+
D[++j::j+ngrp-1,(x1,b1,b2)] = G'*diag(m:*b[b1]-m:*b[b2]), G'*diag(m:*b[x1]),
|
1431 |
+
G'*diag(-m:*b[x1])
|
1432 |
+
D[j=j+ngrp,(x1,b1,b2)] = m:*b[b1]-m:*b[b2], m:*b[x1], -m:*b[x1]
|
1433 |
+
D[++j::j+ngrp-1,(x2,b1,b2)] = G'*diag(w:*b[b1]-w:*b[b2]), G'*diag(w:*b[x2]),
|
1434 |
+
G'*diag(-w:*b[x2])
|
1435 |
+
D[j=j+ngrp,(x2,b1,b2)] = w:*b[b1]-w:*b[b2], w:*b[x2], -w:*b[x2]
|
1436 |
+
}
|
1437 |
+
else {
|
1438 |
+
D[++j::j+ngrp-1,(x1,x2,b1,b2)] =
|
1439 |
+
G'*diag(m:*b[b1]-m:*b[b2]), G'*diag(w:*b[b1]-w:*b[b2]),
|
1440 |
+
G'*diag(m:*b[x1]+w:*b[x2]), G'*diag(-m:*b[x1]-w:*b[x2])
|
1441 |
+
D[j=j+ngrp,(x1,x2,b1,b2)] = m:*b[b1]-m:*b[b2], w:*b[b1]-w:*b[b2],
|
1442 |
+
m:*b[x1]+w:*b[x2], -m:*b[x1]-w:*b[x2]
|
1443 |
+
}
|
1444 |
+
}
|
1445 |
+
}
|
1446 |
+
else {
|
1447 |
+
res = res,
|
1448 |
+
(b[x1]-b[x2]) * (w:*b[b1]+m:*b[b2])',
|
1449 |
+
(split ? b[x1] * (m:*b[b1]-m:*b[b2])', b[x2] * (w:*b[b1]-w:*b[b2])'
|
1450 |
+
: b[x1] * (m:*b[b1]-m:*b[b2])' + b[x2] * (w:*b[b1]-w:*b[b2])'
|
1451 |
+
)
|
1452 |
+
coln = coln, "E_", (split ? ("U1_", "U2_") : "U_")
|
1453 |
+
if (se) {
|
1454 |
+
D = D \ J(2+split, length(b), 0)
|
1455 |
+
D[++j,(x1,x2,b1,b2)] = w:*b[b1]+m:*b[b2], -w:*b[b1]-m:*b[b2],
|
1456 |
+
w:*b[x1]-w:*b[x2], m:*b[x1]-m:*b[x2]
|
1457 |
+
if (split) {
|
1458 |
+
D[++j,(x1,b1,b2)] = m:*b[b1]-m:*b[b2], m:*b[x1], -m:*b[x1]
|
1459 |
+
D[++j,(x2,b1,b2)] = w:*b[b1]-w:*b[b2], w:*b[x2], -w:*b[x2]
|
1460 |
+
}
|
1461 |
+
else {
|
1462 |
+
D[++j,(x1,x2,b1,b2)] = m:*b[b1]-m:*b[b2], w:*b[b1]-w:*b[b2],
|
1463 |
+
m:*b[x1]+w:*b[x2], -m:*b[x1]-w:*b[x2]
|
1464 |
+
}
|
1465 |
+
}
|
1466 |
+
}
|
1467 |
+
}
|
1468 |
+
if (se) {
|
1469 |
+
V = D*V*D'
|
1470 |
+
}
|
1471 |
+
stripe = J(length(coln),1,""), coln'
|
1472 |
+
if (detail) {
|
1473 |
+
notcons = (stripe[,2]:!="E__cons":&stripe[,2]:!="I__cons")
|
1474 |
+
res = select(res, notcons')
|
1475 |
+
stripe = select(stripe, notcons)
|
1476 |
+
}
|
1477 |
+
st_matrix(st_local("b"), res)
|
1478 |
+
st_matrixcolstripe(st_local("b"), stripe)
|
1479 |
+
if (se) {
|
1480 |
+
if (detail) V = select(select(V, notcons'), notcons)
|
1481 |
+
st_matrix(st_local("V"),V)
|
1482 |
+
st_matrixrowstripe(st_local("V"),stripe)
|
1483 |
+
st_matrixcolstripe(st_local("V"),stripe)
|
1484 |
+
}
|
1485 |
+
}
|
1486 |
+
|
1487 |
+
string scalar oaxaca_invtokens(string vector In)
|
1488 |
+
{
|
1489 |
+
string scalar Out
|
1490 |
+
real scalar i
|
1491 |
+
|
1492 |
+
Out = ""
|
1493 |
+
for (i=1; i<=length(In); i++) {
|
1494 |
+
Out = Out + (i>1 ? " " : "") + In[i]
|
1495 |
+
}
|
1496 |
+
return(Out)
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
real matrix oaxaca_which(real vector I)
|
1500 |
+
{
|
1501 |
+
if (cols(I)!=1) return(select(1..cols(I), I))
|
1502 |
+
else return(select(1::rows(I), I))
|
1503 |
+
}
|
1504 |
+
|
1505 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/b/binscatter.ado
ADDED
@@ -0,0 +1,1048 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 7.02 24nov2013 Michael Stepner, [email protected]
|
2 |
+
|
3 |
+
/* CC0 license information:
|
4 |
+
To the extent possible under law, the author has dedicated all copyright and related and neighboring rights
|
5 |
+
to this software to the public domain worldwide. This software is distributed without any warranty.
|
6 |
+
|
7 |
+
This code is licensed under the CC0 1.0 Universal license. The full legal text as well as a
|
8 |
+
human-readable summary can be accessed at http://creativecommons.org/publicdomain/zero/1.0/
|
9 |
+
*/
|
10 |
+
|
11 |
+
* Why did I include a formal license? Jeff Atwood gives good reasons: http://www.codinghorror.com/blog/2007/04/pick-a-license-any-license.html
|
12 |
+
|
13 |
+
|
14 |
+
program define binscatter, eclass sortpreserve
|
15 |
+
version 12.1
|
16 |
+
|
17 |
+
syntax varlist(min=2 numeric) [if] [in] [aweight fweight], [by(varname) ///
|
18 |
+
Nquantiles(integer 20) GENxq(name) discrete xq(varname numeric) MEDians ///
|
19 |
+
CONTROLs(varlist numeric ts fv) absorb(varname) noAddmean ///
|
20 |
+
LINEtype(string) rd(numlist ascending) reportreg ///
|
21 |
+
COLors(string) MColors(string) LColors(string) Msymbols(string) ///
|
22 |
+
savegraph(string) savedata(string) replace ///
|
23 |
+
nofastxtile randvar(varname numeric) randcut(real 1) randn(integer -1) ///
|
24 |
+
/* LEGACY OPTIONS */ nbins(integer 20) create_xq x_q(varname numeric) symbols(string) method(string) unique(string) ///
|
25 |
+
*]
|
26 |
+
|
27 |
+
set more off
|
28 |
+
|
29 |
+
* Create convenient weight local
|
30 |
+
if ("`weight'"!="") local wt [`weight'`exp']
|
31 |
+
|
32 |
+
***** Begin legacy option compatibility code
|
33 |
+
|
34 |
+
if (`nbins'!=20) {
|
35 |
+
if (`nquantiles'!=20) {
|
36 |
+
di as error "Cannot specify both nquantiles() and nbins(): both are the same option, nbins is supported only for backward compatibility."
|
37 |
+
exit
|
38 |
+
}
|
39 |
+
di as text "NOTE: legacy option nbins() has been renamed nquantiles(), and is supported only for backward compatibility."
|
40 |
+
local nquantiles=`nbins'
|
41 |
+
}
|
42 |
+
|
43 |
+
if ("`create_xq'"!="") {
|
44 |
+
if ("`genxq'"!="") {
|
45 |
+
di as error "Cannot specify both genxq() and create_xq: both are the same option, create_xq is supported only for backward compatibility."
|
46 |
+
exit
|
47 |
+
}
|
48 |
+
di as text "NOTE: legacy option create_xq has been renamed genxq(), and is supported only for backward compatibility."
|
49 |
+
local genxq="q_"+word("`varlist'",-1)
|
50 |
+
}
|
51 |
+
|
52 |
+
if ("`x_q'"!="") {
|
53 |
+
if ("`xq'"!="") {
|
54 |
+
di as error "Cannot specify both xq() and x_q(): both are the same option, x_q() is supported only for backward compatibility."
|
55 |
+
exit
|
56 |
+
}
|
57 |
+
di as text "NOTE: legacy option x_q() has been renamed xq(), and is supported only for backward compatibility."
|
58 |
+
local xq `x_q'
|
59 |
+
}
|
60 |
+
|
61 |
+
if ("`symbols'"!="") {
|
62 |
+
if ("`msymbols'"!="") {
|
63 |
+
di as error "Cannot specify both msymbols() and symbols(): both are the same option, symbols() is supported only for backward compatibility."
|
64 |
+
exit
|
65 |
+
}
|
66 |
+
di as text "NOTE: legacy option symbols() has been renamed msymbols(), and is supported only for backward compatibility."
|
67 |
+
local msymbols `symbols'
|
68 |
+
}
|
69 |
+
|
70 |
+
if ("`linetype'"=="noline") {
|
71 |
+
di as text "NOTE: legacy line type 'noline' has been renamed 'none', and is supported only for backward compatibility."
|
72 |
+
local linetype none
|
73 |
+
}
|
74 |
+
|
75 |
+
if ("`method'"!="") {
|
76 |
+
di as text "NOTE: method() is no longer a recognized option, and will be ignored. binscatter now always uses the fastest method without a need for two instances"
|
77 |
+
}
|
78 |
+
|
79 |
+
if ("`unique'"!="") {
|
80 |
+
di as text "NOTE: unique() is no longer a recognized option, and will be ignored. binscatter now considers the x-variable discrete if it has fewer unique values than nquantiles()"
|
81 |
+
}
|
82 |
+
|
83 |
+
***** End legacy option capatibility code
|
84 |
+
|
85 |
+
*** Perform checks
|
86 |
+
|
87 |
+
* Set default linetype and check valid
|
88 |
+
if ("`linetype'"=="") local linetype lfit
|
89 |
+
else if !inlist("`linetype'","connect","lfit","qfit","none") {
|
90 |
+
di as error "linetype() must either be connect, lfit, qfit, or none"
|
91 |
+
exit
|
92 |
+
}
|
93 |
+
|
94 |
+
* Check that nofastxtile isn't combined with fastxtile-only options
|
95 |
+
if "`fastxtile'"=="nofastxtile" & ("`randvar'"!="" | `randcut'!=1 | `randn'!=-1) {
|
96 |
+
di as error "Cannot combine randvar, randcut or randn with nofastxtile"
|
97 |
+
exit
|
98 |
+
}
|
99 |
+
|
100 |
+
* Misc checks
|
101 |
+
if ("`genxq'"!="" & ("`xq'"!="" | "`discrete'"!="")) | ("`xq'"!="" & "`discrete'"!="") {
|
102 |
+
di as error "Cannot specify more than one of genxq(), xq(), and discrete simultaneously."
|
103 |
+
exit
|
104 |
+
}
|
105 |
+
if ("`genxq'"!="") confirm new variable `genxq'
|
106 |
+
if ("`xq'"!="") {
|
107 |
+
capture assert `xq'==int(`xq') & `xq'>0
|
108 |
+
if _rc!=0 {
|
109 |
+
di as error "xq() must contain only positive integers."
|
110 |
+
exit
|
111 |
+
}
|
112 |
+
|
113 |
+
if ("`controls'`absorb'"!="") di as text "warning: xq() is specified in combination with controls() or absorb(). note that binning takes places after residualization, so the xq variable should contain bins of the residuals."
|
114 |
+
}
|
115 |
+
if `nquantiles'!=20 & ("`xq'"!="" | "`discrete'"!="") {
|
116 |
+
di as error "Cannot specify nquantiles in combination with discrete or an xq variable."
|
117 |
+
exit
|
118 |
+
}
|
119 |
+
if "`reportreg'"!="" & !inlist("`linetype'","lfit","qfit") {
|
120 |
+
di as error "Cannot specify 'reportreg' when no fit line is being created."
|
121 |
+
exit
|
122 |
+
}
|
123 |
+
if "`replace'"=="" {
|
124 |
+
if `"`savegraph'"'!="" {
|
125 |
+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") confirm new file `"`savegraph'"'
|
126 |
+
else confirm new file `"`savegraph'.gph"'
|
127 |
+
}
|
128 |
+
if `"`savedata'"'!="" {
|
129 |
+
confirm new file `"`savedata'.csv"'
|
130 |
+
confirm new file `"`savedata'.do"'
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
* Mark sample (reflects the if/in conditions, and includes only nonmissing observations)
|
135 |
+
marksample touse
|
136 |
+
markout `touse' `by' `xq' `controls' `absorb', strok
|
137 |
+
qui count if `touse'
|
138 |
+
local samplesize=r(N)
|
139 |
+
local touse_first=_N-`samplesize'+1
|
140 |
+
local touse_last=_N
|
141 |
+
|
142 |
+
* Parse varlist into y-vars and x-var
|
143 |
+
local x_var=word("`varlist'",-1)
|
144 |
+
local y_vars=regexr("`varlist'"," `x_var'$","")
|
145 |
+
local ynum=wordcount("`y_vars'")
|
146 |
+
|
147 |
+
* Check number of unique byvals & create local storing byvals
|
148 |
+
if "`by'"!="" {
|
149 |
+
local byvarname `by'
|
150 |
+
|
151 |
+
capture confirm numeric variable `by'
|
152 |
+
if _rc {
|
153 |
+
* by-variable is string => generate a numeric version
|
154 |
+
tempvar by
|
155 |
+
tempname bylabel
|
156 |
+
egen `by'=group(`byvarname'), lname(`bylabel')
|
157 |
+
}
|
158 |
+
|
159 |
+
local bylabel `:value label `by'' /*catch value labels for numeric by-vars too*/
|
160 |
+
|
161 |
+
tempname byvalmatrix
|
162 |
+
qui tab `by' if `touse', nofreq matrow(`byvalmatrix')
|
163 |
+
|
164 |
+
local bynum=r(r)
|
165 |
+
forvalues i=1/`bynum' {
|
166 |
+
local byvals `byvals' `=`byvalmatrix'[`i',1]'
|
167 |
+
}
|
168 |
+
}
|
169 |
+
else local bynum=1
|
170 |
+
|
171 |
+
|
172 |
+
****** Create residuals ******
|
173 |
+
|
174 |
+
if (`"`controls'`absorb'"'!="") quietly {
|
175 |
+
|
176 |
+
* Parse absorb to define the type of regression to be used
|
177 |
+
if `"`absorb'"'!="" {
|
178 |
+
local regtype "areg"
|
179 |
+
local absorb "absorb(`absorb')"
|
180 |
+
}
|
181 |
+
else {
|
182 |
+
local regtype "reg"
|
183 |
+
}
|
184 |
+
|
185 |
+
* Generate residuals
|
186 |
+
|
187 |
+
local firstloop=1
|
188 |
+
foreach var of varlist `x_var' `y_vars' {
|
189 |
+
tempvar residvar
|
190 |
+
`regtype' `var' `controls' `wt' if `touse', `absorb'
|
191 |
+
predict `residvar' if e(sample), residuals
|
192 |
+
if ("`addmean'"!="noaddmean") {
|
193 |
+
summarize `var' `wt' if `touse', meanonly
|
194 |
+
replace `residvar'=`residvar'+r(mean)
|
195 |
+
}
|
196 |
+
|
197 |
+
label variable `residvar' "`var'"
|
198 |
+
if `firstloop'==1 {
|
199 |
+
local x_r `residvar'
|
200 |
+
local firstloop=0
|
201 |
+
}
|
202 |
+
else local y_vars_r `y_vars_r' `residvar'
|
203 |
+
}
|
204 |
+
|
205 |
+
}
|
206 |
+
else { /*absorb and controls both empty, no need for regression*/
|
207 |
+
local x_r `x_var'
|
208 |
+
local y_vars_r `y_vars'
|
209 |
+
}
|
210 |
+
|
211 |
+
|
212 |
+
****** Regressions for fit lines ******
|
213 |
+
|
214 |
+
if ("`reportreg'"=="") local reg_verbosity "quietly"
|
215 |
+
|
216 |
+
if inlist("`linetype'","lfit","qfit") `reg_verbosity' {
|
217 |
+
|
218 |
+
* If doing a quadratic fit, generate a quadratic term in x
|
219 |
+
if "`linetype'"=="qfit" {
|
220 |
+
tempvar x_r2
|
221 |
+
gen `x_r2'=`x_r'^2
|
222 |
+
}
|
223 |
+
|
224 |
+
* Create matrices to hold regression results
|
225 |
+
tempname e_b_temp
|
226 |
+
forvalues i=1/`ynum' {
|
227 |
+
tempname y`i'_coefs
|
228 |
+
}
|
229 |
+
|
230 |
+
* LOOP over by-vars
|
231 |
+
local counter_by=1
|
232 |
+
if ("`by'"=="") local noby="noby"
|
233 |
+
foreach byval in `byvals' `noby' {
|
234 |
+
|
235 |
+
* LOOP over rd intervals
|
236 |
+
tokenize "`rd'"
|
237 |
+
local counter_rd=1
|
238 |
+
|
239 |
+
while ("`1'"!="" | `counter_rd'==1) {
|
240 |
+
|
241 |
+
* display text headers
|
242 |
+
if "`reportreg'"!="" {
|
243 |
+
di "{txt}{hline}"
|
244 |
+
if ("`by'"!="") {
|
245 |
+
if ("`bylabel'"=="") di "-> `byvarname' = `byval'"
|
246 |
+
else {
|
247 |
+
di "-> `byvarname' = `: label `bylabel' `byval''"
|
248 |
+
}
|
249 |
+
}
|
250 |
+
if ("`rd'"!="") {
|
251 |
+
if (`counter_rd'==1) di "RD: `x_var'<=`1'"
|
252 |
+
else if ("`2'"!="") di "RD: `x_var'>`1' & `x_var'<=`2'"
|
253 |
+
else di "RD: `x_var'>`1'"
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
* set conditions on reg
|
258 |
+
local conds `touse'
|
259 |
+
|
260 |
+
if ("`by'"!="" ) local conds `conds' & `by'==`byval'
|
261 |
+
|
262 |
+
if ("`rd'"!="") {
|
263 |
+
if (`counter_rd'==1) local conds `conds' & `x_r'<=`1'
|
264 |
+
else if ("`2'"!="") local conds `conds' & `x_r'>`1' & `x_r'<=`2'
|
265 |
+
else local conds `conds' & `x_r'>`1'
|
266 |
+
}
|
267 |
+
|
268 |
+
* LOOP over y-vars
|
269 |
+
local counter_depvar=1
|
270 |
+
foreach depvar of varlist `y_vars_r' {
|
271 |
+
|
272 |
+
* display text headers
|
273 |
+
if (`ynum'>1) {
|
274 |
+
if ("`controls'`absorb'"!="") local depvar_name : var label `depvar'
|
275 |
+
else local depvar_name `depvar'
|
276 |
+
di as text "{bf:y_var = `depvar_name'}"
|
277 |
+
}
|
278 |
+
|
279 |
+
* perform regression
|
280 |
+
if ("`reg_verbosity'"=="quietly") capture reg `depvar' `x_r2' `x_r' `wt' if `conds'
|
281 |
+
else capture noisily reg `depvar' `x_r2' `x_r' `wt' if `conds'
|
282 |
+
|
283 |
+
* store results
|
284 |
+
if (_rc==0) matrix e_b_temp=e(b)
|
285 |
+
else if (_rc==2000) {
|
286 |
+
if ("`reg_verbosity'"=="quietly") di as error "no observations for one of the fit lines. add 'reportreg' for more info."
|
287 |
+
|
288 |
+
if ("`linetype'"=="lfit") matrix e_b_temp=.,.
|
289 |
+
else /*("`linetype'"=="qfit")*/ matrix e_b_temp=.,.,.
|
290 |
+
}
|
291 |
+
else {
|
292 |
+
error _rc
|
293 |
+
exit _rc
|
294 |
+
}
|
295 |
+
|
296 |
+
* relabel matrix row
|
297 |
+
if ("`by'"!="") matrix roweq e_b_temp = "by`counter_by'"
|
298 |
+
if ("`rd'"!="") matrix rownames e_b_temp = "rd`counter_rd'"
|
299 |
+
else matrix rownames e_b_temp = "="
|
300 |
+
|
301 |
+
* save to y_var matrix
|
302 |
+
if (`counter_by'==1 & `counter_rd'==1) matrix `y`counter_depvar'_coefs'=e_b_temp
|
303 |
+
else matrix `y`counter_depvar'_coefs'=`y`counter_depvar'_coefs' \ e_b_temp
|
304 |
+
|
305 |
+
* increment depvar counter
|
306 |
+
local ++counter_depvar
|
307 |
+
}
|
308 |
+
|
309 |
+
* increment rd counter
|
310 |
+
if (`counter_rd'!=1) mac shift
|
311 |
+
local ++counter_rd
|
312 |
+
|
313 |
+
}
|
314 |
+
|
315 |
+
* increment by counter
|
316 |
+
local ++counter_by
|
317 |
+
|
318 |
+
}
|
319 |
+
|
320 |
+
* relabel matrix column names
|
321 |
+
forvalues i=1/`ynum' {
|
322 |
+
if ("`linetype'"=="lfit") matrix colnames `y`i'_coefs' = "`x_var'" "_cons"
|
323 |
+
else if ("`linetype'"=="qfit") matrix colnames `y`i'_coefs' = "`x_var'^2" "`x_var'" "_cons"
|
324 |
+
}
|
325 |
+
|
326 |
+
}
|
327 |
+
|
328 |
+
******* Define the bins *******
|
329 |
+
|
330 |
+
* Specify and/or create the xq var, as necessary
|
331 |
+
if "`xq'"=="" {
|
332 |
+
|
333 |
+
if !(`touse_first'==1 & word("`:sortedby'",1)=="`x_r'") sort `touse' `x_r'
|
334 |
+
|
335 |
+
if "`discrete'"=="" { /* xq() and discrete are not specified */
|
336 |
+
|
337 |
+
* Check whether the number of unique values > nquantiles, or <= nquantiles
|
338 |
+
capture mata: characterize_unique_vals_sorted("`x_r'",`touse_first',`touse_last',`nquantiles')
|
339 |
+
|
340 |
+
if (_rc==0) { /* number of unique values <= nquantiles, set to discrete */
|
341 |
+
local discrete discrete
|
342 |
+
if ("`genxq'"!="") di as text `"note: the x-variable has fewer unique values than the number of bins specified (`nquantiles'). It will therefore be treated as discrete, and genxq() will be ignored"'
|
343 |
+
|
344 |
+
local xq `x_r'
|
345 |
+
local nquantiles=r(r)
|
346 |
+
if ("`by'"=="") {
|
347 |
+
tempname xq_boundaries xq_values
|
348 |
+
matrix `xq_boundaries'=r(boundaries)
|
349 |
+
matrix `xq_values'=r(values)
|
350 |
+
}
|
351 |
+
}
|
352 |
+
else if (_rc==134) { /* number of unique values > nquantiles, perform binning */
|
353 |
+
if ("`genxq'"!="") local xq `genxq'
|
354 |
+
else tempvar xq
|
355 |
+
|
356 |
+
if ("`fastxtile'"!="nofastxtile") fastxtile `xq' = `x_r' `wt' in `touse_first'/`touse_last', nq(`nquantiles') randvar(`randvar') randcut(`randcut') randn(`randn')
|
357 |
+
else xtile `xq' = `x_r' `wt' in `touse_first'/`touse_last', nq(`nquantiles')
|
358 |
+
|
359 |
+
if ("`by'"=="") {
|
360 |
+
mata: characterize_unique_vals_sorted("`xq'",`touse_first',`touse_last',`nquantiles')
|
361 |
+
|
362 |
+
if (r(r)!=`nquantiles') {
|
363 |
+
di as text "warning: nquantiles(`nquantiles') was specified, but only `r(r)' were generated. see help file under nquantiles() for explanation."
|
364 |
+
local nquantiles=r(r)
|
365 |
+
}
|
366 |
+
|
367 |
+
tempname xq_boundaries xq_values
|
368 |
+
matrix `xq_boundaries'=r(boundaries)
|
369 |
+
matrix `xq_values'=r(values)
|
370 |
+
}
|
371 |
+
}
|
372 |
+
else {
|
373 |
+
error _rc
|
374 |
+
}
|
375 |
+
|
376 |
+
}
|
377 |
+
|
378 |
+
else { /* discrete is specified, xq() & genxq() are not */
|
379 |
+
|
380 |
+
if ("`controls'`absorb'"!="") di as text "warning: discrete is specified in combination with controls() or absorb(). note that binning takes places after residualization, so the residualized x-variable may contain many more unique values."
|
381 |
+
|
382 |
+
capture mata: characterize_unique_vals_sorted("`x_r'",`touse_first',`touse_last',`=`samplesize'/2')
|
383 |
+
|
384 |
+
if (_rc==0) {
|
385 |
+
local xq `x_r'
|
386 |
+
local nquantiles=r(r)
|
387 |
+
if ("`by'"=="") {
|
388 |
+
tempname xq_boundaries xq_values
|
389 |
+
matrix `xq_boundaries'=r(boundaries)
|
390 |
+
matrix `xq_values'=r(values)
|
391 |
+
}
|
392 |
+
}
|
393 |
+
else if (_rc==134) {
|
394 |
+
di as error "discrete specified, but number of unique values is > (sample size/2)"
|
395 |
+
exit 134
|
396 |
+
}
|
397 |
+
else {
|
398 |
+
error _rc
|
399 |
+
}
|
400 |
+
}
|
401 |
+
}
|
402 |
+
else {
|
403 |
+
|
404 |
+
if !(`touse_first'==1 & word("`:sortedby'",1)=="`xq'") sort `touse' `xq'
|
405 |
+
|
406 |
+
* set nquantiles & boundaries
|
407 |
+
mata: characterize_unique_vals_sorted("`xq'",`touse_first',`touse_last',`=`samplesize'/2')
|
408 |
+
|
409 |
+
if (_rc==0) {
|
410 |
+
local nquantiles=r(r)
|
411 |
+
if ("`by'"=="") {
|
412 |
+
tempname xq_boundaries xq_values
|
413 |
+
matrix `xq_boundaries'=r(boundaries)
|
414 |
+
matrix `xq_values'=r(values)
|
415 |
+
}
|
416 |
+
}
|
417 |
+
else if (_rc==134) {
|
418 |
+
di as error "discrete specified, but number of unique values is > (sample size/2)"
|
419 |
+
exit 134
|
420 |
+
}
|
421 |
+
else {
|
422 |
+
error _rc
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
********** Compute scatter points **********
|
427 |
+
|
428 |
+
if ("`by'"!="") {
|
429 |
+
sort `touse' `by' `xq'
|
430 |
+
tempname by_boundaries
|
431 |
+
mata: characterize_unique_vals_sorted("`by'",`touse_first',`touse_last',`bynum')
|
432 |
+
matrix `by_boundaries'=r(boundaries)
|
433 |
+
}
|
434 |
+
|
435 |
+
forvalues b=1/`bynum' {
|
436 |
+
if ("`by'"!="") {
|
437 |
+
mata: characterize_unique_vals_sorted("`xq'",`=`by_boundaries'[`b',1]',`=`by_boundaries'[`b',2]',`nquantiles')
|
438 |
+
tempname xq_boundaries xq_values
|
439 |
+
matrix `xq_boundaries'=r(boundaries)
|
440 |
+
matrix `xq_values'=r(values)
|
441 |
+
}
|
442 |
+
/* otherwise xq_boundaries and xq_values are defined above in the binning code block */
|
443 |
+
|
444 |
+
* Define x-means
|
445 |
+
tempname xbin_means
|
446 |
+
if ("`discrete'"=="discrete") {
|
447 |
+
matrix `xbin_means'=`xq_values'
|
448 |
+
}
|
449 |
+
else {
|
450 |
+
means_in_boundaries `x_r' `wt', bounds(`xq_boundaries') `medians'
|
451 |
+
matrix `xbin_means'=r(means)
|
452 |
+
}
|
453 |
+
|
454 |
+
* LOOP over y-vars to define y-means
|
455 |
+
local counter_depvar=0
|
456 |
+
foreach depvar of varlist `y_vars_r' {
|
457 |
+
local ++counter_depvar
|
458 |
+
|
459 |
+
means_in_boundaries `depvar' `wt', bounds(`xq_boundaries') `medians'
|
460 |
+
|
461 |
+
* store to matrix
|
462 |
+
if (`b'==1) {
|
463 |
+
tempname y`counter_depvar'_scatterpts
|
464 |
+
matrix `y`counter_depvar'_scatterpts' = `xbin_means',r(means)
|
465 |
+
}
|
466 |
+
else {
|
467 |
+
* make matrices conformable before right appending
|
468 |
+
local rowdiff=rowsof(`y`counter_depvar'_scatterpts')-rowsof(`xbin_means')
|
469 |
+
if (`rowdiff'==0) matrix `y`counter_depvar'_scatterpts' = `y`counter_depvar'_scatterpts',`xbin_means',r(means)
|
470 |
+
else if (`rowdiff'>0) matrix `y`counter_depvar'_scatterpts' = `y`counter_depvar'_scatterpts', ( (`xbin_means',r(means)) \ J(`rowdiff',2,.) )
|
471 |
+
else /*(`rowdiff'<0)*/ matrix `y`counter_depvar'_scatterpts' = ( `y`counter_depvar'_scatterpts' \ J(-`rowdiff',colsof(`y`counter_depvar'_scatterpts'),.) ) ,`xbin_means',r(means)
|
472 |
+
}
|
473 |
+
}
|
474 |
+
}
|
475 |
+
|
476 |
+
*********** Perform Graphing ***********
|
477 |
+
|
478 |
+
* If rd is specified, prepare xline parameters
|
479 |
+
if "`rd'"!="" {
|
480 |
+
foreach xval in "`rd'" {
|
481 |
+
local xlines `xlines' xline(`xval', lpattern(dash) lcolor(gs8))
|
482 |
+
}
|
483 |
+
}
|
484 |
+
|
485 |
+
* Fill colors if missing
|
486 |
+
if `"`colors'"'=="" local colors ///
|
487 |
+
navy maroon forest_green dkorange teal cranberry lavender ///
|
488 |
+
khaki sienna emidblue emerald brown erose gold bluishgray ///
|
489 |
+
/* lime magenta cyan pink blue */
|
490 |
+
if `"`mcolors'"'=="" {
|
491 |
+
if (`ynum'==1 & `bynum'==1 & "`linetype'"!="connect") local mcolors `: word 1 of `colors''
|
492 |
+
else local mcolors `colors'
|
493 |
+
}
|
494 |
+
if `"`lcolors'"'=="" {
|
495 |
+
if (`ynum'==1 & `bynum'==1 & "`linetype'"!="connect") local lcolors `: word 2 of `colors''
|
496 |
+
else local lcolors `colors'
|
497 |
+
}
|
498 |
+
local num_mcolor=wordcount(`"`mcolors'"')
|
499 |
+
local num_lcolor=wordcount(`"`lcolors'"')
|
500 |
+
|
501 |
+
|
502 |
+
* Prepare connect & msymbol options
|
503 |
+
if ("`linetype'"=="connect") local connect "c(l)"
|
504 |
+
if "`msymbols'"!="" {
|
505 |
+
local symbol_prefix "msymbol("
|
506 |
+
local symbol_suffix ")"
|
507 |
+
}
|
508 |
+
|
509 |
+
*** Prepare scatters
|
510 |
+
|
511 |
+
* c indexes which color is to be used
|
512 |
+
local c=0
|
513 |
+
|
514 |
+
local counter_series=0
|
515 |
+
|
516 |
+
* LOOP over by-vars
|
517 |
+
local counter_by=0
|
518 |
+
if ("`by'"=="") local noby="noby"
|
519 |
+
foreach byval in `byvals' `noby' {
|
520 |
+
local ++counter_by
|
521 |
+
|
522 |
+
local xind=`counter_by'*2-1
|
523 |
+
local yind=`counter_by'*2
|
524 |
+
|
525 |
+
* LOOP over y-vars
|
526 |
+
local counter_depvar=0
|
527 |
+
foreach depvar of varlist `y_vars' {
|
528 |
+
local ++counter_depvar
|
529 |
+
local ++c
|
530 |
+
|
531 |
+
* LOOP over rows (each row contains a coordinate pair)
|
532 |
+
local row=1
|
533 |
+
local xval=`y`counter_depvar'_scatterpts'[`row',`xind']
|
534 |
+
local yval=`y`counter_depvar'_scatterpts'[`row',`yind']
|
535 |
+
|
536 |
+
if !missing(`xval',`yval') {
|
537 |
+
local ++counter_series
|
538 |
+
local scatters `scatters' (scatteri
|
539 |
+
if ("`savedata'"!="") {
|
540 |
+
if ("`by'"=="") local savedata_scatters `savedata_scatters' (scatter `depvar' `x_var'
|
541 |
+
else local savedata_scatters `savedata_scatters' (scatter `depvar'_by`counter_by' `x_var'_by`counter_by'
|
542 |
+
}
|
543 |
+
}
|
544 |
+
else {
|
545 |
+
* skip the rest of this loop iteration
|
546 |
+
continue
|
547 |
+
}
|
548 |
+
|
549 |
+
while (`xval'!=. & `yval'!=.) {
|
550 |
+
local scatters `scatters' `yval' `xval'
|
551 |
+
|
552 |
+
local ++row
|
553 |
+
local xval=`y`counter_depvar'_scatterpts'[`row',`xind']
|
554 |
+
local yval=`y`counter_depvar'_scatterpts'[`row',`yind']
|
555 |
+
}
|
556 |
+
|
557 |
+
* Add options
|
558 |
+
local scatter_options `connect' mcolor(`: word `c' of `mcolors'') lcolor(`: word `c' of `lcolors'') `symbol_prefix'`: word `c' of `msymbols''`symbol_suffix'
|
559 |
+
local scatters `scatters', `scatter_options')
|
560 |
+
if ("`savedata'"!="") local savedata_scatters `savedata_scatters', `scatter_options')
|
561 |
+
|
562 |
+
|
563 |
+
* Add legend
|
564 |
+
if "`by'"=="" {
|
565 |
+
if (`ynum'==1) local legend_labels off
|
566 |
+
else local legend_labels `legend_labels' lab(`counter_series' `depvar')
|
567 |
+
}
|
568 |
+
else {
|
569 |
+
if ("`bylabel'"=="") local byvalname=`byval'
|
570 |
+
else {
|
571 |
+
local byvalname `: label `bylabel' `byval''
|
572 |
+
}
|
573 |
+
|
574 |
+
if (`ynum'==1) local legend_labels `legend_labels' lab(`counter_series' `byvarname'=`byvalname')
|
575 |
+
else local legend_labels `legend_labels' lab(`counter_series' `depvar': `byvarname'=`byvalname')
|
576 |
+
}
|
577 |
+
if ("`by'"!="" | `ynum'>1) local order `order' `counter_series'
|
578 |
+
|
579 |
+
}
|
580 |
+
|
581 |
+
}
|
582 |
+
|
583 |
+
*** Fit lines
|
584 |
+
|
585 |
+
if inlist(`"`linetype'"',"lfit","qfit") {
|
586 |
+
|
587 |
+
* c indexes which color is to be used
|
588 |
+
local c=0
|
589 |
+
|
590 |
+
local rdnum=wordcount("`rd'")+1
|
591 |
+
|
592 |
+
tempname fitline_bounds
|
593 |
+
if ("`rd'"=="") matrix `fitline_bounds'=.,.
|
594 |
+
else matrix `fitline_bounds'=.,`=subinstr("`rd'"," ",",",.)',.
|
595 |
+
|
596 |
+
* LOOP over by-vars
|
597 |
+
local counter_by=0
|
598 |
+
if ("`by'"=="") local noby="noby"
|
599 |
+
foreach byval in `byvals' `noby' {
|
600 |
+
local ++counter_by
|
601 |
+
|
602 |
+
** Set the column for the x-coords in the scatterpts matrix
|
603 |
+
local xind=`counter_by'*2-1
|
604 |
+
|
605 |
+
* Set the row to start seeking from
|
606 |
+
* note: each time we seek a coeff, it should be from row (rd_num)(counter_by-1)+counter_rd
|
607 |
+
local row0=( `rdnum' ) * (`counter_by' - 1)
|
608 |
+
|
609 |
+
|
610 |
+
* LOOP over y-vars
|
611 |
+
local counter_depvar=0
|
612 |
+
foreach depvar of varlist `y_vars_r' {
|
613 |
+
local ++counter_depvar
|
614 |
+
local ++c
|
615 |
+
|
616 |
+
* Find lower and upper bounds for the fit line
|
617 |
+
matrix `fitline_bounds'[1,1]=`y`counter_depvar'_scatterpts'[1,`xind']
|
618 |
+
|
619 |
+
local fitline_ub_rindex=`nquantiles'
|
620 |
+
local fitline_ub=.
|
621 |
+
while `fitline_ub'==. {
|
622 |
+
local fitline_ub=`y`counter_depvar'_scatterpts'[`fitline_ub_rindex',`xind']
|
623 |
+
local --fitline_ub_rindex
|
624 |
+
}
|
625 |
+
matrix `fitline_bounds'[1,`rdnum'+1]=`fitline_ub'
|
626 |
+
|
627 |
+
* LOOP over rd intervals
|
628 |
+
forvalues counter_rd=1/`rdnum' {
|
629 |
+
|
630 |
+
if (`"`linetype'"'=="lfit") {
|
631 |
+
local coef_quad=0
|
632 |
+
local coef_lin=`y`counter_depvar'_coefs'[`row0'+`counter_rd',1]
|
633 |
+
local coef_cons=`y`counter_depvar'_coefs'[`row0'+`counter_rd',2]
|
634 |
+
}
|
635 |
+
else if (`"`linetype'"'=="qfit") {
|
636 |
+
local coef_quad=`y`counter_depvar'_coefs'[`row0'+`counter_rd',1]
|
637 |
+
local coef_lin=`y`counter_depvar'_coefs'[`row0'+`counter_rd',2]
|
638 |
+
local coef_cons=`y`counter_depvar'_coefs'[`row0'+`counter_rd',3]
|
639 |
+
}
|
640 |
+
|
641 |
+
if !missing(`coef_quad',`coef_lin',`coef_cons') {
|
642 |
+
local leftbound=`fitline_bounds'[1,`counter_rd']
|
643 |
+
local rightbound=`fitline_bounds'[1,`counter_rd'+1]
|
644 |
+
|
645 |
+
local fits `fits' (function `coef_quad'*x^2+`coef_lin'*x+`coef_cons', range(`leftbound' `rightbound') lcolor(`: word `c' of `lcolors''))
|
646 |
+
}
|
647 |
+
}
|
648 |
+
}
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
* Prepare y-axis title
|
653 |
+
if (`ynum'==1) local ytitle `y_vars'
|
654 |
+
else if (`ynum'==2) local ytitle : subinstr local y_vars " " " and "
|
655 |
+
else local ytitle : subinstr local y_vars " " "; ", all
|
656 |
+
|
657 |
+
* Display graph
|
658 |
+
local graphcmd twoway `scatters' `fits', graphregion(fcolor(white)) `xlines' xtitle(`x_var') ytitle(`ytitle') legend(`legend_labels' order(`order')) `options'
|
659 |
+
if ("`savedata'"!="") local savedata_graphcmd twoway `savedata_scatters' `fits', graphregion(fcolor(white)) `xlines' xtitle(`x_var') ytitle(`ytitle') legend(`legend_labels' order(`order')) `options'
|
660 |
+
`graphcmd'
|
661 |
+
|
662 |
+
****** Save results ******
|
663 |
+
|
664 |
+
* Save graph
|
665 |
+
if `"`savegraph'"'!="" {
|
666 |
+
* check file extension using a regular expression
|
667 |
+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
|
668 |
+
|
669 |
+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
|
670 |
+
else graph export `"`savegraph'"', `replace'
|
671 |
+
}
|
672 |
+
|
673 |
+
* Save data
|
674 |
+
if ("`savedata'"!="") {
|
675 |
+
|
676 |
+
*** Save a CSV containing the scatter points
|
677 |
+
tempname savedatafile
|
678 |
+
file open `savedatafile' using `"`savedata'.csv"', write text `replace'
|
679 |
+
|
680 |
+
* LOOP over rows
|
681 |
+
forvalues row=0/`nquantiles' {
|
682 |
+
|
683 |
+
*** Put the x-variable at the left
|
684 |
+
* LOOP over by-vals
|
685 |
+
forvalues counter_by=1/`bynum' {
|
686 |
+
|
687 |
+
if (`row'==0) { /* write variable names */
|
688 |
+
if "`by'"!="" local bynlabel _by`counter_by'
|
689 |
+
file write `savedatafile' "`x_var'`bynlabel',"
|
690 |
+
}
|
691 |
+
else { /* write data values */
|
692 |
+
if (`row'<=`=rowsof(`y1_scatterpts')') file write `savedatafile' (`y1_scatterpts'[`row',`counter_by'*2-1]) ","
|
693 |
+
else file write `savedatafile' ".,"
|
694 |
+
}
|
695 |
+
}
|
696 |
+
|
697 |
+
*** Now y-variables at the right
|
698 |
+
|
699 |
+
* LOOP over y-vars
|
700 |
+
local counter_depvar=0
|
701 |
+
foreach depvar of varlist `y_vars' {
|
702 |
+
local ++counter_depvar
|
703 |
+
|
704 |
+
* LOOP over by-vals
|
705 |
+
forvalues counter_by=1/`bynum' {
|
706 |
+
|
707 |
+
|
708 |
+
if (`row'==0) { /* write variable names */
|
709 |
+
if "`by'"!="" local bynlabel _by`counter_by'
|
710 |
+
file write `savedatafile' "`depvar'`bynlabel'"
|
711 |
+
}
|
712 |
+
else { /* write data values */
|
713 |
+
if (`row'<=`=rowsof(`y`counter_depvar'_scatterpts')') file write `savedatafile' (`y`counter_depvar'_scatterpts'[`row',`counter_by'*2])
|
714 |
+
else file write `savedatafile' "."
|
715 |
+
}
|
716 |
+
|
717 |
+
* unless this is the last variable in the dataset, add a comma
|
718 |
+
if !(`counter_depvar'==`ynum' & `counter_by'==`bynum') file write `savedatafile' ","
|
719 |
+
|
720 |
+
} /* end by-val loop */
|
721 |
+
|
722 |
+
} /* end y-var loop */
|
723 |
+
|
724 |
+
file write `savedatafile' _n
|
725 |
+
|
726 |
+
} /* end row loop */
|
727 |
+
|
728 |
+
file close `savedatafile'
|
729 |
+
di as text `"(file `savedata'.csv written containing saved data)"'
|
730 |
+
|
731 |
+
|
732 |
+
|
733 |
+
*** Save a do-file with the commands to generate a nicely labeled dataset and re-create the binscatter graph
|
734 |
+
|
735 |
+
file open `savedatafile' using `"`savedata'.do"', write text `replace'
|
736 |
+
|
737 |
+
file write `savedatafile' `"insheet using `savedata'.csv"' _n _n
|
738 |
+
|
739 |
+
if "`by'"!="" {
|
740 |
+
foreach var of varlist `x_var' `y_vars' {
|
741 |
+
local counter_by=0
|
742 |
+
foreach byval in `byvals' {
|
743 |
+
local ++counter_by
|
744 |
+
if ("`bylabel'"=="") local byvalname=`byval'
|
745 |
+
else {
|
746 |
+
local byvalname `: label `bylabel' `byval''
|
747 |
+
}
|
748 |
+
file write `savedatafile' `"label variable `var'_by`counter_by' "`var'; `byvarname'==`byvalname'""' _n
|
749 |
+
}
|
750 |
+
}
|
751 |
+
file write `savedatafile' _n
|
752 |
+
}
|
753 |
+
|
754 |
+
file write `savedatafile' `"`savedata_graphcmd'"' _n
|
755 |
+
|
756 |
+
file close `savedatafile'
|
757 |
+
di as text `"(file `savedata'.do written containing commands to process saved data)"'
|
758 |
+
|
759 |
+
}
|
760 |
+
|
761 |
+
*** Return items
|
762 |
+
ereturn post, esample(`touse')
|
763 |
+
|
764 |
+
ereturn scalar N = `samplesize'
|
765 |
+
|
766 |
+
ereturn local graphcmd `"`graphcmd'"'
|
767 |
+
if inlist("`linetype'","lfit","qfit") {
|
768 |
+
forvalues yi=`ynum'(-1)1 {
|
769 |
+
ereturn matrix y`yi'_coefs=`y`yi'_coefs'
|
770 |
+
}
|
771 |
+
}
|
772 |
+
|
773 |
+
if ("`rd'"!="") {
|
774 |
+
tempname rdintervals
|
775 |
+
matrix `rdintervals' = (. \ `=subinstr("`rd'"," ","\",.)' ) , ( `=subinstr("`rd'"," ","\",.)' \ .)
|
776 |
+
|
777 |
+
forvalues i=1/`=rowsof(`rdintervals')' {
|
778 |
+
local rdintervals_labels `rdintervals_labels' rd`i'
|
779 |
+
}
|
780 |
+
matrix rownames `rdintervals' = `rdintervals_labels'
|
781 |
+
matrix colnames `rdintervals' = gt lt_eq
|
782 |
+
ereturn matrix rdintervals=`rdintervals'
|
783 |
+
}
|
784 |
+
|
785 |
+
if ("`by'"!="" & "`by'"=="`byvarname'") { /* if a numeric by-variable was specified */
|
786 |
+
forvalues i=1/`=rowsof(`byvalmatrix')' {
|
787 |
+
local byvalmatrix_labels `byvalmatrix_labels' by`i'
|
788 |
+
}
|
789 |
+
matrix rownames `byvalmatrix' = `byvalmatrix_labels'
|
790 |
+
matrix colnames `byvalmatrix' = `by'
|
791 |
+
ereturn matrix byvalues=`byvalmatrix'
|
792 |
+
}
|
793 |
+
|
794 |
+
end
|
795 |
+
|
796 |
+
|
797 |
+
**********************************
|
798 |
+
|
799 |
+
* Helper programs
|
800 |
+
|
801 |
+
program define means_in_boundaries, rclass
|
802 |
+
version 12.1
|
803 |
+
|
804 |
+
syntax varname(numeric) [aweight fweight], BOUNDsmat(name) [MEDians]
|
805 |
+
|
806 |
+
* Create convenient weight local
|
807 |
+
if ("`weight'"!="") local wt [`weight'`exp']
|
808 |
+
|
809 |
+
local r=rowsof(`boundsmat')
|
810 |
+
matrix means=J(`r',1,.)
|
811 |
+
|
812 |
+
if ("`medians'"!="medians") {
|
813 |
+
forvalues i=1/`r' {
|
814 |
+
sum `varlist' in `=`boundsmat'[`i',1]'/`=`boundsmat'[`i',2]' `wt', meanonly
|
815 |
+
matrix means[`i',1]=r(mean)
|
816 |
+
}
|
817 |
+
}
|
818 |
+
else {
|
819 |
+
forvalues i=1/`r' {
|
820 |
+
_pctile `varlist' in `=`boundsmat'[`i',1]'/`=`boundsmat'[`i',2]' `wt', percentiles(50)
|
821 |
+
matrix means[`i',1]=r(r1)
|
822 |
+
}
|
823 |
+
}
|
824 |
+
|
825 |
+
return clear
|
826 |
+
return matrix means=means
|
827 |
+
|
828 |
+
end
|
829 |
+
|
830 |
+
*** copy of: version 1.21 8oct2013 Michael Stepner, [email protected]
|
831 |
+
program define fastxtile, rclass
|
832 |
+
version 11
|
833 |
+
|
834 |
+
* Parse weights, if any
|
835 |
+
_parsewt "aweight fweight pweight" `0'
|
836 |
+
local 0 "`s(newcmd)'" /* command minus weight statement */
|
837 |
+
local wt "`s(weight)'" /* contains [weight=exp] or nothing */
|
838 |
+
|
839 |
+
* Extract parameters
|
840 |
+
syntax newvarname=/exp [if] [in] [,Nquantiles(integer 2) Cutpoints(varname numeric) ALTdef ///
|
841 |
+
CUTValues(numlist ascending) randvar(varname numeric) randcut(real 1) randn(integer -1)]
|
842 |
+
|
843 |
+
* Mark observations which will be placed in quantiles
|
844 |
+
marksample touse, novarlist
|
845 |
+
markout `touse' `exp'
|
846 |
+
qui count if `touse'
|
847 |
+
local popsize=r(N)
|
848 |
+
|
849 |
+
if "`cutpoints'"=="" & "`cutvalues'"=="" { /***** NQUANTILES *****/
|
850 |
+
if `"`wt'"'!="" & "`altdef'"!="" {
|
851 |
+
di as error "altdef option cannot be used with weights"
|
852 |
+
exit 198
|
853 |
+
}
|
854 |
+
|
855 |
+
if `randn'!=-1 {
|
856 |
+
if `randcut'!=1 {
|
857 |
+
di as error "cannot specify both randcut() and randn()"
|
858 |
+
exit 198
|
859 |
+
}
|
860 |
+
else if `randn'<1 {
|
861 |
+
di as error "randn() must be a positive integer"
|
862 |
+
exit 198
|
863 |
+
}
|
864 |
+
else if `randn'>`popsize' {
|
865 |
+
di as text "randn() is larger than the population. using the full population."
|
866 |
+
local randvar=""
|
867 |
+
}
|
868 |
+
else {
|
869 |
+
local randcut=`randn'/`popsize'
|
870 |
+
|
871 |
+
if "`randvar'"!="" {
|
872 |
+
qui sum `randvar', meanonly
|
873 |
+
if r(min)<0 | r(max)>1 {
|
874 |
+
di as error "with randn(), the randvar specified must be in [0,1] and ought to be uniformly distributed"
|
875 |
+
exit 198
|
876 |
+
}
|
877 |
+
}
|
878 |
+
}
|
879 |
+
}
|
880 |
+
|
881 |
+
* Check if need to gen a temporary uniform random var
|
882 |
+
if "`randvar'"=="" {
|
883 |
+
if (`randcut'<1 & `randcut'>0) {
|
884 |
+
tempvar randvar
|
885 |
+
gen `randvar'=runiform()
|
886 |
+
}
|
887 |
+
* randcut sanity check
|
888 |
+
else if `randcut'!=1 {
|
889 |
+
di as error "if randcut() is specified without randvar(), a uniform r.v. will be generated and randcut() must be in (0,1)"
|
890 |
+
exit 198
|
891 |
+
}
|
892 |
+
}
|
893 |
+
|
894 |
+
* Mark observations used to calculate quantile boundaries
|
895 |
+
if ("`randvar'"!="") {
|
896 |
+
tempvar randsample
|
897 |
+
mark `randsample' `wt' if `touse' & `randvar'<=`randcut'
|
898 |
+
}
|
899 |
+
else {
|
900 |
+
local randsample `touse'
|
901 |
+
}
|
902 |
+
|
903 |
+
* Error checks
|
904 |
+
qui count if `randsample'
|
905 |
+
local samplesize=r(N)
|
906 |
+
if (`nquantiles' > r(N) + 1) {
|
907 |
+
if ("`randvar'"=="") di as error "nquantiles() must be less than or equal to the number of observations [`r(N)'] plus one"
|
908 |
+
else di as error "nquantiles() must be less than or equal to the number of sampled observations [`r(N)'] plus one"
|
909 |
+
exit 198
|
910 |
+
}
|
911 |
+
else if (`nquantiles' < 2) {
|
912 |
+
di as error "nquantiles() must be greater than or equal to 2"
|
913 |
+
exit 198
|
914 |
+
}
|
915 |
+
|
916 |
+
* Compute quantile boundaries
|
917 |
+
_pctile `exp' if `randsample' `wt', nq(`nquantiles') `altdef'
|
918 |
+
|
919 |
+
* Store quantile boundaries in list
|
920 |
+
forvalues i=1/`=`nquantiles'-1' {
|
921 |
+
local cutvallist `cutvallist' r(r`i')
|
922 |
+
}
|
923 |
+
}
|
924 |
+
else if "`cutpoints'"!="" { /***** CUTPOINTS *****/
|
925 |
+
|
926 |
+
* Parameter checks
|
927 |
+
if "`cutvalues'"!="" {
|
928 |
+
di as error "cannot specify both cutpoints() and cutvalues()"
|
929 |
+
exit 198
|
930 |
+
}
|
931 |
+
if "`wt'"!="" | "`randvar'"!="" | "`ALTdef'"!="" | `randcut'!=1 | `nquantiles'!=2 | `randn'!=-1 {
|
932 |
+
di as error "cutpoints() cannot be used with nquantiles(), altdef, randvar(), randcut(), randn() or weights"
|
933 |
+
exit 198
|
934 |
+
}
|
935 |
+
|
936 |
+
tempname cutvals
|
937 |
+
qui tab `cutpoints', matrow(`cutvals')
|
938 |
+
|
939 |
+
if r(r)==0 {
|
940 |
+
di as error "cutpoints() all missing"
|
941 |
+
exit 2000
|
942 |
+
}
|
943 |
+
else {
|
944 |
+
local nquantiles = r(r) + 1
|
945 |
+
|
946 |
+
forvalues i=1/`r(r)' {
|
947 |
+
local cutvallist `cutvallist' `cutvals'[`i',1]
|
948 |
+
}
|
949 |
+
}
|
950 |
+
}
|
951 |
+
else { /***** CUTVALUES *****/
|
952 |
+
if "`wt'"!="" | "`randvar'"!="" | "`ALTdef'"!="" | `randcut'!=1 | `nquantiles'!=2 | `randn'!=-1 {
|
953 |
+
di as error "cutvalues() cannot be used with nquantiles(), altdef, randvar(), randcut(), randn() or weights"
|
954 |
+
exit 198
|
955 |
+
}
|
956 |
+
|
957 |
+
* parse numlist
|
958 |
+
numlist "`cutvalues'"
|
959 |
+
local cutvallist `"`r(numlist)'"'
|
960 |
+
local nquantiles=wordcount(`"`r(numlist)'"')+1
|
961 |
+
}
|
962 |
+
|
963 |
+
* Pick data type for quantile variable
|
964 |
+
if (`nquantiles'<=100) local qtype byte
|
965 |
+
else if (`nquantiles'<=32,740) local qtype int
|
966 |
+
else local qtype long
|
967 |
+
|
968 |
+
* Create quantile variable
|
969 |
+
local cutvalcommalist : subinstr local cutvallist " " ",", all
|
970 |
+
qui gen `qtype' `varlist'=1+irecode(`exp',`cutvalcommalist') if `touse'
|
971 |
+
label var `varlist' "`nquantiles' quantiles of `exp'"
|
972 |
+
|
973 |
+
* Return values
|
974 |
+
if ("`samplesize'"!="") return scalar n = `samplesize'
|
975 |
+
else return scalar n = .
|
976 |
+
|
977 |
+
return scalar N = `popsize'
|
978 |
+
|
979 |
+
tokenize `"`cutvallist'"'
|
980 |
+
forvalues i=`=`nquantiles'-1'(-1)1 {
|
981 |
+
return scalar r`i' = ``i''
|
982 |
+
}
|
983 |
+
|
984 |
+
end
|
985 |
+
|
986 |
+
|
987 |
+
version 12.1
|
988 |
+
set matastrict on
|
989 |
+
|
990 |
+
mata:
|
991 |
+
|
992 |
+
void characterize_unique_vals_sorted(string scalar var, real scalar first, real scalar last, real scalar maxuq) {
|
993 |
+
// Inputs: a numeric variable, a starting & ending obs #, and a maximum number of unique values
|
994 |
+
// Requires: the data to be sorted on the specified variable within the observation boundaries given
|
995 |
+
// (no check is made that this requirement is satisfied)
|
996 |
+
// Returns: the number of unique values found
|
997 |
+
// the unique values found
|
998 |
+
// the observation boundaries of each unique value in the dataset
|
999 |
+
|
1000 |
+
|
1001 |
+
// initialize returned results
|
1002 |
+
real scalar Nunique
|
1003 |
+
Nunique=0
|
1004 |
+
|
1005 |
+
real matrix values
|
1006 |
+
values=J(maxuq,1,.)
|
1007 |
+
|
1008 |
+
real matrix boundaries
|
1009 |
+
boundaries=J(maxuq,2,.)
|
1010 |
+
|
1011 |
+
// initialize computations
|
1012 |
+
real scalar var_index
|
1013 |
+
var_index=st_varindex(var)
|
1014 |
+
|
1015 |
+
real scalar curvalue
|
1016 |
+
real scalar prevvalue
|
1017 |
+
|
1018 |
+
// perform computations
|
1019 |
+
real scalar obs
|
1020 |
+
for (obs=first; obs<=last; obs++) {
|
1021 |
+
curvalue=_st_data(obs,var_index)
|
1022 |
+
|
1023 |
+
if (curvalue!=prevvalue) {
|
1024 |
+
Nunique++
|
1025 |
+
if (Nunique<=maxuq) {
|
1026 |
+
prevvalue=curvalue
|
1027 |
+
values[Nunique,1]=curvalue
|
1028 |
+
boundaries[Nunique,1]=obs
|
1029 |
+
if (Nunique>1) boundaries[Nunique-1,2]=obs-1
|
1030 |
+
}
|
1031 |
+
else {
|
1032 |
+
exit(error(134))
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
}
|
1036 |
+
}
|
1037 |
+
boundaries[Nunique,2]=last
|
1038 |
+
|
1039 |
+
// return results
|
1040 |
+
stata("return clear")
|
1041 |
+
|
1042 |
+
st_numscalar("r(r)",Nunique)
|
1043 |
+
st_matrix("r(values)",values[1..Nunique,.])
|
1044 |
+
st_matrix("r(boundaries)",boundaries[1..Nunique,.])
|
1045 |
+
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/b/binscatter.sthlp
ADDED
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* *! version 7.02 24nov2013}{...}
|
3 |
+
{viewerjumpto "Syntax" "binscatter##syntax"}{...}
|
4 |
+
{viewerjumpto "Description" "binscatter##description"}{...}
|
5 |
+
{viewerjumpto "Options" "binscatter##options"}{...}
|
6 |
+
{viewerjumpto "Examples" "binscatter##examples"}{...}
|
7 |
+
{viewerjumpto "Saved results" "binscatter##saved_results"}{...}
|
8 |
+
{viewerjumpto "Author" "binscatter##author"}{...}
|
9 |
+
{viewerjumpto "Acknowledgements" "binscatter##acknowledgements"}{...}
|
10 |
+
{title:Title}
|
11 |
+
|
12 |
+
{p2colset 5 19 21 2}{...}
|
13 |
+
{p2col :{hi:binscatter} {hline 2}}Binned scatterplots{p_end}
|
14 |
+
{p2colreset}{...}
|
15 |
+
|
16 |
+
|
17 |
+
{marker syntax}{title:Syntax}
|
18 |
+
|
19 |
+
{p 8 15 2}
|
20 |
+
{cmd:binscatter}
|
21 |
+
{varlist} {ifin}
|
22 |
+
{weight}
|
23 |
+
[{cmd:,} {it:options}]
|
24 |
+
|
25 |
+
|
26 |
+
{pstd}
|
27 |
+
where {it:varlist} is
|
28 |
+
{p_end}
|
29 |
+
{it:y_1} [{it:y_2} [...]] {it:x}
|
30 |
+
|
31 |
+
{synoptset 26 tabbed}{...}
|
32 |
+
{synopthdr :options}
|
33 |
+
{synoptline}
|
34 |
+
{syntab :Main}
|
35 |
+
{synopt :{opth by(varname)}}plot separate series for each group (see {help binscatter##by_notes:important notes below}){p_end}
|
36 |
+
{synopt :{opt med:ians}}plot within-bin medians instead of means{p_end}
|
37 |
+
|
38 |
+
{syntab :Bins}
|
39 |
+
{synopt :{opth n:quantiles(#)}}number of equal-sized bins to be created; default is {bf:20}{p_end}
|
40 |
+
{synopt :{opth gen:xq(varname)}}generate quantile variable containing the bins{p_end}
|
41 |
+
{synopt :{opt discrete}}each x-value to be used as a separate bin{p_end}
|
42 |
+
{synopt :{opth xq(varname)}}variable which already contains bins; bins therefore not recomputed{p_end}
|
43 |
+
|
44 |
+
{syntab :Controls}
|
45 |
+
{synopt :{opth control:s(varlist)}}residualize the x & y variables on controls before plotting{p_end}
|
46 |
+
{synopt :{opth absorb(varname)}}residualize the x & y variables on a categorical variable{p_end}
|
47 |
+
{synopt :{opt noa:ddmean}}do not add the mean of each variable back to its residuals{p_end}
|
48 |
+
|
49 |
+
{syntab :Fit Line}
|
50 |
+
{synopt :{opth line:type(binscatter##linetype:linetype)}}type of fit line; default is {bf:lfit}, may also be {bf:qfit}, {bf:connect}, or {bf:none}{p_end}
|
51 |
+
{synopt :{opth rd(numlist)}}create regression discontinuity at x-values{p_end}
|
52 |
+
{synopt :{opt reportreg}}display the regressions used to estimate the fit lines{p_end}
|
53 |
+
|
54 |
+
{syntab :Graph Style}
|
55 |
+
{synopt :{cmdab:col:ors(}{it:{help colorstyle}list}{cmd:)}}ordered list of colors{p_end}
|
56 |
+
{synopt :{cmdab:mc:olors(}{it:{help colorstyle}list}{cmd:)}}overriding ordered list of colors for the markers{p_end}
|
57 |
+
{synopt :{cmdab:lc:olors(}{it:{help colorstyle}list}{cmd:)}}overriding ordered list of colors for the lines{p_end}
|
58 |
+
{synopt :{cmdab:m:symbols(}{it:{help symbolstyle}list}{cmd:)}}ordered list of symbols{p_end}
|
59 |
+
{synopt :{it:{help twoway_options}}}{help title options:titles}, {help legend option:legends}, {help axis options:axes}, added {help added line options:lines} and {help added text options:text},
|
60 |
+
{help region options:regions}, {help name option:name}, {help aspect option:aspect ratio}, etc.{p_end}
|
61 |
+
|
62 |
+
{syntab :Save Output}
|
63 |
+
{synopt :{opt savegraph(filename)}}save graph to file; format automatically detected from extension [ex: .gph .jpg .png]{p_end}
|
64 |
+
{synopt :{opt savedata(filename)}}save {it:filename}.csv containg scatterpoint data, and {it:filename}.do to process data into graph{p_end}
|
65 |
+
{synopt :{opt replace}}overwrite existing files{p_end}
|
66 |
+
|
67 |
+
{syntab :fastxtile options}
|
68 |
+
{synopt :{opt nofastxtile}}use xtile instead of fastxtile{p_end}
|
69 |
+
{synopt :{opth randvar(varname)}}use {it:varname} to sample observations when computing quantile boundaries{p_end}
|
70 |
+
{synopt :{opt randcut(#)}}upper bound on {cmd:randvar()} used to cut the sample; default is {cmd:randcut(1)}{p_end}
|
71 |
+
{synopt :{opt randn(#)}}number of observations to sample when computing quantile boundaries{p_end}
|
72 |
+
{synoptline}
|
73 |
+
{p 4 6 2}
|
74 |
+
{opt aweight}s and {opt fweight}s are allowed;
|
75 |
+
see {help weight}.
|
76 |
+
{p_end}
|
77 |
+
|
78 |
+
|
79 |
+
{marker description}{...}
|
80 |
+
{title:Description}
|
81 |
+
|
82 |
+
{pstd}
|
83 |
+
{opt binscatter} generates binned scatterplots, and is optimized for speed in large datasets.
|
84 |
+
|
85 |
+
{pstd}
|
86 |
+
Binned scatterplots provide a non-parametric way of visualizing the relationship between two variables.
|
87 |
+
With a large number of observations, a scatterplot that plots every data point would become too crowded
|
88 |
+
to interpret visually. {cmd:binscatter} groups the x-axis variable into equal-sized bins, computes the
|
89 |
+
mean of the x-axis and y-axis variables within each bin, then creates a scatterplot of these data points.
|
90 |
+
The result is a non-parametric visualization of the conditional expectation function.
|
91 |
+
|
92 |
+
{pstd}
|
93 |
+
{opt binscatter} provides built-in options to control for covariates before plotting the relationship
|
94 |
+
(see {help binscatter##controls:Controls}). Additionally, {cmd:binscatter} will plot fit lines based
|
95 |
+
on the underlying data, and can automatically handle regression discontinuities (see {help binscatter##fit_line:Fit Line}).
|
96 |
+
|
97 |
+
|
98 |
+
{marker options}{...}
|
99 |
+
{title:Options}
|
100 |
+
|
101 |
+
{dlgtab:Main}
|
102 |
+
|
103 |
+
{marker by_notes}{...}
|
104 |
+
{phang}{opth by(varname)} plots a separate series for each by-value. Both numeric and string by-variables
|
105 |
+
are supported, but numeric by-variables will have faster run times.
|
106 |
+
|
107 |
+
{pmore}Users should be aware of the two ways in which {cmd:binscatter} does not condition on by-values:
|
108 |
+
|
109 |
+
{phang3}1) When combined with {opt controls()} or {opt absorb()}, the program residualizes using the restricted model in which each covariate
|
110 |
+
has the same coefficient in each by-value sample. It does not run separate regressions for each by-value. If you wish to control for
|
111 |
+
covariates using a different model, you can residualize your x- and y-variables beforehand using your desired model then run {cmd:binscatter}
|
112 |
+
on the residuals you constructed.
|
113 |
+
|
114 |
+
{phang3}2) When not combined with {opt discrete} or {opt xq()}, the program constructs a single set of bins
|
115 |
+
using the unconditional quantiles of the x-variable. It does not bin the x-variable separately for each by-value.
|
116 |
+
If you wish to use a different binning procedure (such as constructing equal-sized bins separately for each
|
117 |
+
by-value), you can construct a variable containing your desired bins beforehand, then run {cmd:binscatter} with {opt xq()}.
|
118 |
+
|
119 |
+
{phang}{opt med:ians} creates the binned scatterplot using the median x- and y-value within each bin, rather than the mean.
|
120 |
+
This option only affects the scatter points; it does not, for instance, cause {opt linetype(lfit)}
|
121 |
+
to use quantile regression instead of OLS when drawing a fit line.
|
122 |
+
|
123 |
+
{dlgtab:Bins}
|
124 |
+
|
125 |
+
{phang}{opth n:quantiles(#)} specifies the number of equal-sized bins to be created. This is equivalent to the number of
|
126 |
+
points in each series. The default is {bf:20}. If the x-variable has fewer
|
127 |
+
unique values than the number of bins specified, then {opt discrete} will be automatically invoked, and no
|
128 |
+
binning will be performed.
|
129 |
+
This option cannot be combined with {opt discrete} or {opt xq()}.
|
130 |
+
|
131 |
+
{pmore}
|
132 |
+
Binning is performed after residualization when combined with {opt controls()} or {opt absorb()}.
|
133 |
+
Note that the binning procedure is equivalent to running xtile, which in certain cases will generate
|
134 |
+
fewer quantile categories than specified. (e.g. {stata sysuse auto}; {stata xtile temp=mpg, nq(20)}; {stata tab temp})
|
135 |
+
|
136 |
+
{phang}{opth gen:xq(varname)} creates a categorical variable containing the computed bins.
|
137 |
+
This option cannot be combined with {opt discrete} or {opt xq()}.
|
138 |
+
|
139 |
+
{phang}{opt discrete} specifies that the x-variable is discrete and that each x-value is to be treated as
|
140 |
+
a separate bin. {cmd:binscatter} will therefore plot the mean y-value associated with each x-value.
|
141 |
+
This option cannot be combined with {opt nquantiles()}, {opt genxq()} or {opt xq()}.
|
142 |
+
|
143 |
+
{pmore}
|
144 |
+
In most cases, {opt discrete} should not be combined with {opt controls()} or {opt absorb()}, since residualization occurs before binning,
|
145 |
+
and in general the residual of a discrete variable will not be discrete.
|
146 |
+
|
147 |
+
{phang}{opth xq(varname)} specifies a categorical variable that contains the bins to be used, instead of {cmd:binscatter} generating them.
|
148 |
+
This option is typically used to avoid recomputing the bins needlessly when {cmd:binscatter} is being run repeatedly on the same sample
|
149 |
+
and with the same x-variable.
|
150 |
+
It may be convenient to use {opt genxq(binvar)} in the first iteration, and specify {opt xq(binvar)} in subsequent iterations.
|
151 |
+
Computing quantiles is computationally intensive in large datasets, so avoiding repetition can reduce run times considerably.
|
152 |
+
This option cannot be combined with {opt nquantiles()}, {opt genxq()} or {opt discrete}.
|
153 |
+
|
154 |
+
{pmore}
|
155 |
+
Care should be taken when combining {opt xq()} with {opt controls()} or {opt absorb()}. Binning takes place after residualization,
|
156 |
+
so if the sample changes or the control variables change, the bins ought to be recomputed as well.
|
157 |
+
|
158 |
+
{marker controls}{...}
|
159 |
+
{dlgtab:Controls}
|
160 |
+
|
161 |
+
{phang}{opth control:s(varlist)} residualizes the x-variable and y-variables on the specified controls before binning and plotting.
|
162 |
+
To do so, {cmd:binscatter} runs a regression of each variable on the controls, generates the residuals, and adds the sample mean of
|
163 |
+
each variable back to its residuals.
|
164 |
+
|
165 |
+
{phang}{opth absorb(varname)} absorbs fixed effects in the categorical variable from the x-variable and y-variables before binning and plotting,
|
166 |
+
To do so, {cmd:binscatter} runs an {helpb areg} of each variable with {it:absorb(varname)} and any {opt controls()} specified. It then generates the
|
167 |
+
residuals and adds the sample mean of each variable back to its residuals.
|
168 |
+
|
169 |
+
{phang}{opt noa:ddmean} prevents the sample mean of each variable from being added back to its residuals, when combined with {opt controls()} or {opt absorb()}.
|
170 |
+
|
171 |
+
{marker fit_line}{...}
|
172 |
+
{dlgtab:Fit Line}
|
173 |
+
|
174 |
+
{marker linetype}{...}
|
175 |
+
{phang}{opth line:type(binscatter##linetype:linetype)} specifies the type of line plotted on each series.
|
176 |
+
The default is {bf:lfit}, which plots a linear fit line. Other options are {bf:qfit} for a quadratic fit line,
|
177 |
+
{bf:connect} for connected points, and {bf:none} for no line.
|
178 |
+
|
179 |
+
{pmore}Linear or quadratic fit lines are estimated using the underlying data, not the binned scatter points. When combined with
|
180 |
+
{opt controls()} or {opt absorb()}, the fit line is estimated after the variables have been residualized.
|
181 |
+
|
182 |
+
{phang}{opth rd(numlist)} draws a dashed vertical line at the specified x-values and generates regression discontinuities when combined with {opt line(lfit|qfit)}.
|
183 |
+
Separate fit lines will be estimated below and above each discontinuity. These estimations are performed using the underlying data, not the binned scatter points.
|
184 |
+
|
185 |
+
{pmore}The regression discontinuities do not affect the binned scatter points in any way.
|
186 |
+
Specifically, a bin may contain a discontinuity within its range, and therefore include data from both sides of the discontinuity.
|
187 |
+
|
188 |
+
{phang}{opt reportreg} displays the regressions used to estimate the fit lines in the results window.
|
189 |
+
|
190 |
+
{dlgtab:Graph Style}
|
191 |
+
|
192 |
+
{phang}{cmdab:col:ors(}{it:{help colorstyle}list}{cmd:)} specifies an ordered list of colors for each series
|
193 |
+
|
194 |
+
{phang}{cmdab:mc:olors(}{it:{help colorstyle}list}{cmd:)} specifies an ordered list of colors for the markers of each series, which overrides any list provided in {opt colors()}
|
195 |
+
|
196 |
+
{phang}{cmdab:lc:olors(}{it:{help colorstyle}list}{cmd:)} specifies an ordered list of colors for the line of each series, which overrides any list provided in {opt colors()}
|
197 |
+
|
198 |
+
{phang}{cmdab:m:symbols(}{it:{help symbolstyle}list}{cmd:)} specifies an ordered list of symbols for each series
|
199 |
+
|
200 |
+
{phang}{it:{help twoway_options}}:
|
201 |
+
|
202 |
+
{pmore}Any unrecognized options added to {cmd:binscatter} are appended to the end of the twoway command which generates the
|
203 |
+
binned scatter plot.
|
204 |
+
|
205 |
+
{pmore}These can be used to control the graph {help title options:titles},
|
206 |
+
{help legend option:legends}, {help axis options:axes}, added {help added line options:lines} and {help added text options:text},
|
207 |
+
{help region options:regions}, {help name option:name}, {help aspect option:aspect ratio}, etc.
|
208 |
+
|
209 |
+
{dlgtab:Save Output}
|
210 |
+
|
211 |
+
{phang}{opt savegraph(filename)} saves the graph to a file. The format is automatically detected from the extension specified [ex: {bf:.gph .jpg .png}],
|
212 |
+
and either {cmd:graph save} or {cmd:graph export} is run. If no file extension is specified {bf:.gph} is assumed.
|
213 |
+
|
214 |
+
{phang}{opt savedata(filename)} saves {it:filename}{bf:.csv} containing the binned scatterpoint data, and {it:filename}{bf:.do} which
|
215 |
+
loads the scatterpoint data, labels the variables, and plots the binscatter graph.
|
216 |
+
|
217 |
+
{pmore}Note that the saved result {bf:e(cmd)} provides an alternative way of capturing the binscatter graph and editing it.
|
218 |
+
|
219 |
+
{phang}{opt replace} specifies that files be overwritten if they alredy exist
|
220 |
+
|
221 |
+
{dlgtab:fastxtile options}
|
222 |
+
|
223 |
+
{phang}{opt nofastxtile} forces the use of {cmd:xtile} instead of {cmd:fastxtile} to compute bins. There is no situation where this should
|
224 |
+
be necessary or useful. The {cmd:fastxile} program generates identical results to {cmd:xtile}, but runs faster on large datasets, and has
|
225 |
+
additional options for random sampling which may be useful to increase speed.
|
226 |
+
|
227 |
+
{pmore}{cmd:fastxtile} is built into the {cmd:binscatter} code, but may also be installed
|
228 |
+
separately from SSC ({stata ssc install fastxtile:click here to install}) for use outside of {cmd:binscatter}.
|
229 |
+
|
230 |
+
{phang}{opth randvar(varname)} requests that {it:varname} be used to select a
|
231 |
+
sample of observations when computing the quantile boundaries. Sampling increases
|
232 |
+
the speed of the binning procedure, but generates bins which are only approximately equal-sized
|
233 |
+
due to sampling error. It is possible to omit this option and still perform random sampling from U[0,1]
|
234 |
+
as described below in {opt randcut()} and {opt randn()}.
|
235 |
+
|
236 |
+
{phang}{opt randcut(#)} specifies the upper bound on the variable contained
|
237 |
+
in {opt randvar(varname)}. Quantile boundaries are approximated using observations for which
|
238 |
+
{opt randvar()} <= #. If no variable is specified in {opt randvar()},
|
239 |
+
a standard uniform random variable is generated. The default is {cmd:randcut(1)}.
|
240 |
+
This option cannot be combined with {opt randn()}.
|
241 |
+
|
242 |
+
{phang}{opt randn(#)} specifies an approximate number of observations to sample when
|
243 |
+
computing the quantile boundaries. Quantile boundaries are approximated using observations
|
244 |
+
for which a uniform random variable is <= #/N. The exact number of observations
|
245 |
+
sampled may therefore differ from #, but it equals # in expectation. When this option is
|
246 |
+
combined with {opth randvar(varname)}, {it:varname} ought to be distributed U[0,1].
|
247 |
+
Otherwise, a standard uniform random variable is generated. This option cannot be combined
|
248 |
+
with {opt randcut()}.
|
249 |
+
|
250 |
+
|
251 |
+
{marker examples}{...}
|
252 |
+
{title:Examples}
|
253 |
+
|
254 |
+
{pstd}Load the 1988 extract of the National Longitudinal Survey of Young Women and Mature Women.{p_end}
|
255 |
+
{phang2}. {stata sysuse nlsw88}{p_end}
|
256 |
+
{phang2}. {stata keep if inrange(age,35,44) & inrange(race,1,2)}{p_end}
|
257 |
+
|
258 |
+
{pstd}What is the relationship between job tenure and wages?{p_end}
|
259 |
+
{phang2}. {stata scatter wage tenure}{p_end}
|
260 |
+
{phang2}. {stata binscatter wage tenure}{p_end}
|
261 |
+
|
262 |
+
{pstd}The scatter was too crowded to be easily interpetable. The binscatter is cleaner, but a linear fit looks unreasonable.{p_end}
|
263 |
+
|
264 |
+
{pstd}Try a quadratic fit.{p_end}
|
265 |
+
{phang2}. {stata binscatter wage tenure, line(qfit)}{p_end}
|
266 |
+
|
267 |
+
{pstd}We can also plot a linear regression discontinuity.{p_end}
|
268 |
+
{phang2}. {stata binscatter wage tenure, rd(2.5)}{p_end}
|
269 |
+
|
270 |
+
{pstd} What is the relationship between age and wages?{p_end}
|
271 |
+
{phang2}. {stata scatter wage age}{p_end}
|
272 |
+
{phang2}. {stata binscatter wage age}{p_end}
|
273 |
+
|
274 |
+
{pstd} The binscatter is again much easier to interpret. (Note that {cmd:binscatter} automatically
|
275 |
+
used each age as a discrete bin, since there are fewer than 20 unique values.){p_end}
|
276 |
+
|
277 |
+
{pstd}How does the relationship vary by race?{p_end}
|
278 |
+
{phang2}. {stata binscatter wage age, by(race)}{p_end}
|
279 |
+
|
280 |
+
{pstd} The relationship between age and wages is very different for whites and blacks. But what if we control for occupation?{p_end}
|
281 |
+
{phang2}. {stata binscatter wage age, by(race) absorb(occupation)}{p_end}
|
282 |
+
|
283 |
+
{pstd} A very different picture emerges. Let's label this graph nicely.{p_end}
|
284 |
+
{phang2}. {stata binscatter wage age, by(race) absorb(occupation) msymbols(O T) xtitle(Age) ytitle(Hourly Wage) legend(lab(1 White) lab(2 Black))}{p_end}
|
285 |
+
|
286 |
+
|
287 |
+
{marker saved_results}{...}
|
288 |
+
{title:Saved Results}
|
289 |
+
|
290 |
+
{pstd}
|
291 |
+
{cmd:binscatter} saves the following in {cmd:e()}:
|
292 |
+
|
293 |
+
{synoptset 20 tabbed}{...}
|
294 |
+
{p2col 5 20 24 2: Scalars}{p_end}
|
295 |
+
{synopt:{cmd:e(N)}}number of observations{p_end}
|
296 |
+
|
297 |
+
{synoptset 20 tabbed}{...}
|
298 |
+
{p2col 5 20 24 2: Macros}{p_end}
|
299 |
+
{synopt:{cmd:e(graphcmd)}}twoway command used to generate graph, which does not depend on loaded data{p_end}
|
300 |
+
{p 30 30 2}Note: it is often important to reference this result using `"`{bf:e(graphcmd)}'"'
|
301 |
+
rather than {bf:e(graphcmd)} in order to avoid truncation due to Stata's character limit for strings.
|
302 |
+
|
303 |
+
{synoptset 20 tabbed}{...}
|
304 |
+
{p2col 5 20 24 2: Matrices}{p_end}
|
305 |
+
{synopt:{cmd:e(byvalues)}}ordered list of by-values {it:(if numeric by-variable specified)}{p_end}
|
306 |
+
{synopt:{cmd:e(rdintervals)}}ordered list of rd intervals {it:(if rd specified)}{p_end}
|
307 |
+
{synopt:{cmd:e(y#_coefs)}}fit line coefficients for #th y-variable {it:(if lfit or qfit specified)}{p_end}
|
308 |
+
|
309 |
+
{synoptset 20 tabbed}{...}
|
310 |
+
{p2col 5 20 24 2: Functions}{p_end}
|
311 |
+
{synopt:{cmd:e(sample)}}marks sample{p_end}
|
312 |
+
{p2colreset}{...}
|
313 |
+
|
314 |
+
|
315 |
+
{marker author}{...}
|
316 |
+
{title:Author}
|
317 |
+
|
318 |
+
{pstd}Michael Stepner{p_end}
|
319 |
+
{pstd}[email protected]{p_end}
|
320 |
+
|
321 |
+
|
322 |
+
{marker acknowledgements}{...}
|
323 |
+
{title:Acknowledgements}
|
324 |
+
|
325 |
+
{pstd}The present version of {cmd:binscatter} is based on a program first written by Jessica Laird.
|
326 |
+
|
327 |
+
{pstd}This program was developed under the guidance and direction of Raj Chetty and John
|
328 |
+
Friedman. Laszlo Sandor provided suggestions which improved the program considerably, and offered abundant help
|
329 |
+
testing it.
|
330 |
+
|
331 |
+
{pstd}Thank you also to the users of early versions of the program who devoted time to reporting
|
332 |
+
the bugs that they encountered.
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/backup.trk
ADDED
@@ -0,0 +1,447 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
* 00000021
|
2 |
+
*! version 1.0.0
|
3 |
+
* Do not erase or edit this file
|
4 |
+
* It is used by Stata to track the ado and help
|
5 |
+
* files you have installed.
|
6 |
+
|
7 |
+
S http://fmwww.bc.edu/repec/bocode/l
|
8 |
+
N listtab.pkg
|
9 |
+
D 12 Feb 2014
|
10 |
+
U 1
|
11 |
+
d 'LISTTAB': module to list variables as rows of a TeX, HTML or word processor table
|
12 |
+
d
|
13 |
+
d listtab outputs a list of variables to the Stata log or to a
|
14 |
+
d file as TeX, HTML or word processor table rows, which can then be
|
15 |
+
d inserted into a TeX, HTML or word processor table by cutting and
|
16 |
+
d pasting and/or file linking and/or embedding (eg using the TeX
|
17 |
+
d \input command). listtab produces the table rows, but may also
|
18 |
+
d produce a set of header lines before the table rows and/or footer
|
19 |
+
d lines after the table rows, containing preambles and/or table
|
20 |
+
d definitions and/or table headers and/or table footers, as
|
21 |
+
d specified by the user.
|
22 |
+
d
|
23 |
+
d KW: output
|
24 |
+
d KW: LaTeX
|
25 |
+
d KW: HTML
|
26 |
+
d KW: RTF
|
27 |
+
d
|
28 |
+
d Requires: Stata version 11.0
|
29 |
+
d
|
30 |
+
d Distribution-Date: 20121105
|
31 |
+
d
|
32 |
+
d Author: Roger Newson, National Heart and Lung Institute at Imperial College London
|
33 |
+
d Support: email r.newson@@imperial.ac.uk
|
34 |
+
d
|
35 |
+
f l/listtab.ado
|
36 |
+
f l/listtab.sthlp
|
37 |
+
f l/listtab_rstyle.ado
|
38 |
+
f l/listtab_rstyle.sthlp
|
39 |
+
f l/listtab_vars.ado
|
40 |
+
f l/listtab_vars.sthlp
|
41 |
+
e
|
42 |
+
S http://fmwww.bc.edu/repec/bocode/e
|
43 |
+
N estout.pkg
|
44 |
+
D 13 Feb 2015
|
45 |
+
U 4
|
46 |
+
d 'ESTOUT': module to make regression tables
|
47 |
+
d
|
48 |
+
d estout produces a table of regression results from one or
|
49 |
+
d several models for use with spreadsheets, LaTeX, HTML, or a
|
50 |
+
d word-processor table. eststo stores a quick copy of the active
|
51 |
+
d estimation results for later tabulation. esttab is a wrapper for
|
52 |
+
d estout. It displays a pretty looking publication-style regression
|
53 |
+
d table without much typing. estadd adds additional results to the
|
54 |
+
d e()-returns for one or several models previously fitted and
|
55 |
+
d stored. This package subsumes the previously circulated esto,
|
56 |
+
d esta, estadd, and estadd_plus. An earlier version of estout is
|
57 |
+
d available as estout1.
|
58 |
+
d
|
59 |
+
d KW: estimates
|
60 |
+
d KW: LaTeX
|
61 |
+
d KW: HTML
|
62 |
+
d KW: word processor
|
63 |
+
d KW: output
|
64 |
+
d
|
65 |
+
d Requires: Stata version 8.2
|
66 |
+
d
|
67 |
+
d Distribution-Date: 20140604
|
68 |
+
d
|
69 |
+
d Author: Ben Jann, University of Bern
|
70 |
+
d Support: email jann@@soz.unibe.ch
|
71 |
+
d
|
72 |
+
f _/_eststo.ado
|
73 |
+
f _/_eststo.hlp
|
74 |
+
f e/estadd.ado
|
75 |
+
f e/estadd.hlp
|
76 |
+
f e/estout.ado
|
77 |
+
f e/estout.hlp
|
78 |
+
f e/eststo.ado
|
79 |
+
f e/eststo.hlp
|
80 |
+
f e/estpost.ado
|
81 |
+
f e/estpost.hlp
|
82 |
+
f e/esttab.ado
|
83 |
+
f e/esttab.hlp
|
84 |
+
e
|
85 |
+
S http://fmwww.bc.edu/repec/bocode/t
|
86 |
+
N tabout.pkg
|
87 |
+
D 13 Feb 2015
|
88 |
+
U 5
|
89 |
+
d 'TABOUT': module to export publication quality cross-tabulations
|
90 |
+
d
|
91 |
+
d tabout is a table building program for oneway and twoway
|
92 |
+
d tables of frequencies and percentages, and for summary tables. It
|
93 |
+
d produces publication quality tables for export to a text file.
|
94 |
+
d These tables can then be used with spreadsheets, word processors,
|
95 |
+
d web browsers or compilers like LaTeX. The tables produced by
|
96 |
+
d tabout allow multiple panels so that a number of variables can be
|
97 |
+
d included in the one table. tabout also provides standard errors
|
98 |
+
d and confidence intervals, as well as a range of table statistics
|
99 |
+
d (chi2 etc). The output from tabout matches Stata's tabulate, most
|
100 |
+
d of tabstat and some of table.
|
101 |
+
d
|
102 |
+
d KW: tables
|
103 |
+
d KW: latex
|
104 |
+
d KW: html
|
105 |
+
d KW: delimited text
|
106 |
+
d
|
107 |
+
d Requires: Stata version 9.2
|
108 |
+
d
|
109 |
+
d Distribution-Date: 20150112
|
110 |
+
d
|
111 |
+
d Author: Ian Watson , Macquarie University, Australia
|
112 |
+
d Support: email mail@@ianwatson.com.au
|
113 |
+
d
|
114 |
+
f t/tabout.ado
|
115 |
+
f t/tabstatout.ado
|
116 |
+
f t/tabout.hlp
|
117 |
+
f f/figout.ado
|
118 |
+
f f/figout.hlp
|
119 |
+
e
|
120 |
+
S http://www.econ.hit-u.ac.jp/~kan/research/ztree2stata
|
121 |
+
N ztree2stata.pkg
|
122 |
+
D 12 Jun 2015
|
123 |
+
U 6
|
124 |
+
d ztree2stata. Imports a z-Tree data file and converts it into Stata format.
|
125 |
+
d Program by Kan Takeuchi.
|
126 |
+
d Instruction manual in PDF is also available at my website.
|
127 |
+
d ({browse "http://www.econ.hit-u.ac.jp/~kan/research/ztree2stata/ztree2stata.pdf":http://www.econ.hit-u.ac.jp/~kan/research/ztree2stata/ztree2stata.pdf}).
|
128 |
+
f z/ztree2stata.ado
|
129 |
+
f z/ztree2stata.hlp
|
130 |
+
e
|
131 |
+
S http://fmwww.bc.edu/RePEc/bocode/s
|
132 |
+
N strdist.pkg
|
133 |
+
D 25 Apr 2016
|
134 |
+
U 7
|
135 |
+
d 'STRDIST': module to calculate the Levenshtein distance, or edit distance, between strings
|
136 |
+
d
|
137 |
+
d strdist calculates the Levenshtein distance, or edit distance,
|
138 |
+
d between strings. It is implemented in Mata, and does not require
|
139 |
+
d a C plugin.
|
140 |
+
d
|
141 |
+
d KW: edit distance
|
142 |
+
d KW: Levenshtein distance
|
143 |
+
d KW: string comparison
|
144 |
+
d KW: data management
|
145 |
+
d
|
146 |
+
d Requires: Stata version 10
|
147 |
+
d
|
148 |
+
d Distribution-Date: 20121111
|
149 |
+
d
|
150 |
+
d Author: Michael Barker, Georgetown University
|
151 |
+
d Support: email michael.barker96@@gmail.com
|
152 |
+
d
|
153 |
+
f s/strdist.ado
|
154 |
+
f s/strdist.sthlp
|
155 |
+
e
|
156 |
+
S http://www.stata-journal.com/software/sj15-1
|
157 |
+
N st0381.pkg
|
158 |
+
D 10 Jun 2016
|
159 |
+
U 8
|
160 |
+
d SJ15-1 st0381. Dunn's test of multiple...
|
161 |
+
d Dunn's test of multiple comparisons using rank
|
162 |
+
d sums
|
163 |
+
d by Alexis Dinno, School of Community Health,
|
164 |
+
d Portland State University, Portland, OR
|
165 |
+
d Support: alexis.dinno@@pdx.edu
|
166 |
+
d After installation, type help ^dunntest^
|
167 |
+
f d/dunntest.ado
|
168 |
+
f d/dunntest.sthlp
|
169 |
+
e
|
170 |
+
S http://fmwww.bc.edu/RePEc/bocode/f
|
171 |
+
N fmm.pkg
|
172 |
+
D 5 Sep 2016
|
173 |
+
U 9
|
174 |
+
d 'FMM': module to estimate finite mixture models
|
175 |
+
d
|
176 |
+
d fmm fits a finite mixture regression model using maximum
|
177 |
+
d likelihood estimation. The model is a J-component finite mixture
|
178 |
+
d of densities, with the density within a class (j) allowed to
|
179 |
+
d vary in location and scale. Optionally, the mixing probabilities
|
180 |
+
d may be specified with covariates. fmm currently fits mixtures
|
181 |
+
d of the following distributions: Gamma, Normal (Gaussian),
|
182 |
+
d Lognormal, Negative binomial 1 & 2 (mean and constant
|
183 |
+
d dispersion), Poisson, Student-t (with fixed degrees of freedom)
|
184 |
+
d
|
185 |
+
d KW: Finite mixture model
|
186 |
+
d KW: maximum likelihood estimation
|
187 |
+
d KW: mixture of densities
|
188 |
+
d
|
189 |
+
d Requires: Stata version 9.2
|
190 |
+
d
|
191 |
+
d Distribution-Date: 20120212
|
192 |
+
d
|
193 |
+
d Author: Partha Deb, Hunter College
|
194 |
+
d Support: email partha.deb@@hunter.cuny.edu
|
195 |
+
d
|
196 |
+
f f/fmm.ado
|
197 |
+
f f/fmm.hlp
|
198 |
+
f f/fmm_postestimation.hlp
|
199 |
+
f f/fmm_gamma_lf.ado
|
200 |
+
f f/fmm_gamma_p.ado
|
201 |
+
f f/fmm_lognormal_lf.ado
|
202 |
+
f f/fmm_lognormal_p.ado
|
203 |
+
f f/fmm_negbin1_lf.ado
|
204 |
+
f f/fmm_negbin1_p.ado
|
205 |
+
f f/fmm_negbin2_lf.ado
|
206 |
+
f f/fmm_negbin2_p.ado
|
207 |
+
f f/fmm_normal_lf.ado
|
208 |
+
f f/fmm_normal_p.ado
|
209 |
+
f f/fmm_poisson_lf.ado
|
210 |
+
f f/fmm_poisson_p.ado
|
211 |
+
f f/fmm_studentt_lf.ado
|
212 |
+
f f/fmm_studentt_p.ado
|
213 |
+
f g/gammareg_lf.ado
|
214 |
+
f l/lognormalreg_lf.ado
|
215 |
+
f n/normalreg_lf.ado
|
216 |
+
f s/studenttreg_lf.ado
|
217 |
+
e
|
218 |
+
S http://www.stata-journal.com/software/sj7-2
|
219 |
+
N gr0001_3.pkg
|
220 |
+
D 9 Sep 2016
|
221 |
+
U 10
|
222 |
+
d SJ7-2 gr0001_3. Update: Generalized Lorenz curves and...
|
223 |
+
d Update: Generalized Lorenz curves and related graphs
|
224 |
+
d by Philippe Van Kerm, CEPS/INSEAD G.-D. Luxembourg,
|
225 |
+
d University of Namur, Belgium
|
226 |
+
d Stephen P. Jenkins, University of Essex, UK
|
227 |
+
d Support: philippe.vankerm@@ceps.lu, stephenj@@essex.ac.uk
|
228 |
+
d After installation, type help ^glcurve^
|
229 |
+
f g/glcurve.ado
|
230 |
+
f g/glcurve.hlp
|
231 |
+
e
|
232 |
+
S http://fmwww.bc.edu/repec/bocode/c
|
233 |
+
N coefplot.pkg
|
234 |
+
D 15 Sep 2017
|
235 |
+
U 12
|
236 |
+
d 'COEFPLOT': module to plot regression coefficients and other results
|
237 |
+
d
|
238 |
+
d coefplot plots results from estimation commands or Stata
|
239 |
+
d matrices. Results from multiple models or matrices can be
|
240 |
+
d combined in a single graph. The default behavior of coefplot is
|
241 |
+
d to draw markers for coefficients and horizontal spikes for
|
242 |
+
d confidence intervals. However, coefplot can also produce various
|
243 |
+
d other types of graphs.
|
244 |
+
d
|
245 |
+
d KW: graphics
|
246 |
+
d KW: coefficients
|
247 |
+
d KW: estimation
|
248 |
+
d
|
249 |
+
d Requires: Stata version 11
|
250 |
+
d
|
251 |
+
d Distribution-Date: 20170216
|
252 |
+
d
|
253 |
+
d Author: Ben Jann, University of Bern
|
254 |
+
d Support: email jann@@soz.unibe.ch
|
255 |
+
d
|
256 |
+
f c/coefplot.ado
|
257 |
+
f c/coefplot.sthlp
|
258 |
+
e
|
259 |
+
S http://fmwww.bc.edu/repec/bocode/l
|
260 |
+
N latab.pkg
|
261 |
+
D 4 Oct 2017
|
262 |
+
U 13
|
263 |
+
d 'LATAB': module to generate LaTeX output from tabulate
|
264 |
+
d
|
265 |
+
d latab tabulates the varlist (max of 2 variables) and produces a
|
266 |
+
d display with LaTeX code embedded in the output. The user may then
|
267 |
+
d copy from this display (or copy from a log file) and paste into a
|
268 |
+
d LaTeX document. Companion program latabstat produces LaTeX output
|
269 |
+
d from the tabstat command.
|
270 |
+
d
|
271 |
+
d Distribution-Date: 20030119
|
272 |
+
d
|
273 |
+
d Author: Ian Watson , ACIRRT, University of Sydney
|
274 |
+
d Support: email iangwatson@@pnc.com.au
|
275 |
+
d
|
276 |
+
f l/latab.ado
|
277 |
+
f l/latab.hlp
|
278 |
+
f l/latabstat.ado
|
279 |
+
f l/latabstat.hlp
|
280 |
+
e
|
281 |
+
S http://fmwww.bc.edu/repec/bocode/b
|
282 |
+
N binscatter.pkg
|
283 |
+
D 4 Oct 2017
|
284 |
+
U 14
|
285 |
+
d 'BINSCATTER': module to generate binned scatterplots
|
286 |
+
d
|
287 |
+
d binscatter generates binned scatterplots, and is optimized for
|
288 |
+
d speed in large datasets. Binned scatterplots provide a
|
289 |
+
d non-parametric way of visualizing the relationship between two
|
290 |
+
d variables. With a large number of observations, a scatterplot
|
291 |
+
d that plots every data point would become too crowded to interpret
|
292 |
+
d visually. binscatter groups the x-axis variable into equal-sized
|
293 |
+
d bins, computes the mean of the x-axis and y-axis variables within
|
294 |
+
d each bin, then creates a scatterplot of these data points. It
|
295 |
+
d provides built-in options to control for covariates before
|
296 |
+
d plotting the relationship. It will also plot fit lines based on
|
297 |
+
d the underlying data, and can automatically handle regression
|
298 |
+
d discontinuities.
|
299 |
+
d
|
300 |
+
d KW: scatterplot
|
301 |
+
d KW: data description
|
302 |
+
d KW: regression discontinuity
|
303 |
+
d
|
304 |
+
d Requires: Stata version 12.1
|
305 |
+
d
|
306 |
+
d Distribution-Date: 20131124
|
307 |
+
d
|
308 |
+
d Author: Michael Stepner
|
309 |
+
d Support: email michaelstepner@@gmail.com
|
310 |
+
d
|
311 |
+
f b/binscatter.ado
|
312 |
+
f b/binscatter.sthlp
|
313 |
+
e
|
314 |
+
S http://fmwww.bc.edu/repec/bocode/c
|
315 |
+
N center.pkg
|
316 |
+
D 14 Nov 2017
|
317 |
+
U 15
|
318 |
+
d 'CENTER': module to center (or standardize) variables
|
319 |
+
d
|
320 |
+
d center centers variables to have zero sample mean (and,
|
321 |
+
d optionally, unit sample variance). center is byable and may also
|
322 |
+
d be used for quasi-demeaning.
|
323 |
+
d
|
324 |
+
d KW: centering
|
325 |
+
d KW: demeaning
|
326 |
+
d KW: z-score
|
327 |
+
d
|
328 |
+
d Requires: Stata version 7.0
|
329 |
+
d
|
330 |
+
d Distribution-Date: 20170413
|
331 |
+
d
|
332 |
+
d Author: Ben Jann, University of Bern
|
333 |
+
d Support: email jann@@soz.unibe.ch
|
334 |
+
d
|
335 |
+
f c/center.ado
|
336 |
+
f c/center.hlp
|
337 |
+
e
|
338 |
+
S http://www.stata.com/stb/stb61
|
339 |
+
N gr42_1.pkg
|
340 |
+
D 29 Nov 2017
|
341 |
+
U 16
|
342 |
+
d STB-61 gr42_1. Quantile plots, generalized: update to Stata 7.0
|
343 |
+
d STB insert by Nicholas J. Cox, University of Durham, UK
|
344 |
+
d Support: n.j.cox@@durham.ac.uk
|
345 |
+
d After installation, see help ^quantil2^
|
346 |
+
f _/_gpp.ado
|
347 |
+
f q/quantil2.ado
|
348 |
+
f q/quantil2.hlp
|
349 |
+
e
|
350 |
+
S http://fmwww.bc.edu/repec/bocode/c
|
351 |
+
N cdfplot.pkg
|
352 |
+
D 5 Dec 2017
|
353 |
+
U 17
|
354 |
+
d 'CDFPLOT': module to plot a cumulative distribution function
|
355 |
+
d
|
356 |
+
d cdfplot plots the sample cumulative distribution function.
|
357 |
+
d Distributions can be compared within subgroups defined by a
|
358 |
+
d second variable. The best fitting normal (Gaussian) model may be
|
359 |
+
d superimposed over the sample c.d.f.
|
360 |
+
d
|
361 |
+
d KW: graph
|
362 |
+
d KW: CDF
|
363 |
+
d KW: Gaussian
|
364 |
+
d
|
365 |
+
d Requires: Stata version 9
|
366 |
+
d
|
367 |
+
d Distribution-Date: 20080714
|
368 |
+
d
|
369 |
+
d Author: Adrian Mander
|
370 |
+
d Support: email Adrian.Mander@@mrc-hnr.cam.ac.uk
|
371 |
+
d
|
372 |
+
f c/cdfplot.ado
|
373 |
+
f c/cdfplot.hlp
|
374 |
+
e
|
375 |
+
S http://www.stata-journal.com/software/sj8-4
|
376 |
+
N st0151.pkg
|
377 |
+
D 9 Mar 2018
|
378 |
+
U 18
|
379 |
+
d SJ8-4 st0151. The Blinder-Oaxaca decomposition for linear...
|
380 |
+
d The Blinder-Oaxaca decomposition for linear regression
|
381 |
+
d models
|
382 |
+
d by Ben Jann, ETH Zurich
|
383 |
+
d Support: jannb@@ethz.ch
|
384 |
+
d After installation, type help ^oaxaca^
|
385 |
+
f o/oaxaca.ado
|
386 |
+
f o/oaxaca.hlp
|
387 |
+
f _/_oaxaca.ado
|
388 |
+
e
|
389 |
+
S http://www.stata.com/users/vwiggins
|
390 |
+
N grc1leg.pkg
|
391 |
+
D 30 Jul 2018
|
392 |
+
U 19
|
393 |
+
d grc1leg. Combine graphs into one graph with a common legend.
|
394 |
+
d Program by Vince Wiggins, StataCorp <vwiggins@@stata.com>.
|
395 |
+
d Statalist distribution, 16 June 2003.
|
396 |
+
d
|
397 |
+
d Exactly like -graph combine- but shows a single common legend for all
|
398 |
+
d combined graphs.
|
399 |
+
d
|
400 |
+
d Distribution-Date: 02jun2010
|
401 |
+
f g/grc1leg.ado
|
402 |
+
f g/grc1leg.hlp
|
403 |
+
e
|
404 |
+
S http://www.stata-journal.com/software/sj19-1
|
405 |
+
N gr41_5.pkg
|
406 |
+
D 18 Nov 2019
|
407 |
+
U 20
|
408 |
+
d SJ19-1 gr41_5. Update: Distribution function plots
|
409 |
+
d Update: Distribution function plots
|
410 |
+
d by Nicholas J. Cox, Durham University, UK
|
411 |
+
d Support: [email protected]
|
412 |
+
d After installation, type help {cmd:displot}
|
413 |
+
d DOI: 10.1177/1536867X19833285
|
414 |
+
f d/distplot.ado
|
415 |
+
f d/distplot.hlp
|
416 |
+
e
|
417 |
+
S http://fmwww.bc.edu/repec/bocode/d
|
418 |
+
N distplot.pkg
|
419 |
+
D 18 Nov 2019
|
420 |
+
U 21
|
421 |
+
d 'DISTPLOT': module to generate distribution function plot
|
422 |
+
d
|
423 |
+
d distplot produces a plot of cumulative distribution function(s).
|
424 |
+
d This shows the proportion (or if desired the frequency) of values
|
425 |
+
d less than or equal to each value. With the reverse option,
|
426 |
+
d distplot produces a plot of the complementary function. This
|
427 |
+
d version is for Stata 8 or later. Also included in this package
|
428 |
+
d are distplot7 files, a clone of the last version of this program
|
429 |
+
d written for Stata 7.
|
430 |
+
d
|
431 |
+
d KW: graphics
|
432 |
+
d KW: frequency distributions
|
433 |
+
d KW: cumulative distribution function
|
434 |
+
d
|
435 |
+
d Requires: Stata version 8.0 (7.0 for distplot7)
|
436 |
+
d
|
437 |
+
d
|
438 |
+
d Author: Nicholas J. Cox, University of Durham
|
439 |
+
d Support: email N.J.Cox@@durham.ac.uk
|
440 |
+
d
|
441 |
+
d Distribution-Date: 20170916
|
442 |
+
d
|
443 |
+
f d/distplot.ado
|
444 |
+
f d/distplot.sthlp
|
445 |
+
f d/distplot7.ado
|
446 |
+
f d/distplot7.hlp
|
447 |
+
e
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/cdfplot.ado
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! Date : 10 July 2008
|
2 |
+
*! Version : 1.04
|
3 |
+
*! Author : Adrian Mander
|
4 |
+
*! Email : [email protected]
|
5 |
+
|
6 |
+
*! ADAPTED from version 1.0.1 David Clayton/Michael Hills Oct-95 STB-49 gr37
|
7 |
+
|
8 |
+
/*
|
9 |
+
29/03/07 version 1.03 - Remove a describe at the end of the program
|
10 |
+
10/07/08 version 1.04 - Add an option to stop the cdf being plotted
|
11 |
+
*/
|
12 |
+
|
13 |
+
program define cdfplot
|
14 |
+
version 9.0
|
15 |
+
syntax varname [aweight fweight iweight pweight] [if] [in] [,BY(varname) opt1(string) opt2(string) NOCDF NORMal SAMEsd XLOG * ]
|
16 |
+
local goptions `"`options'"'
|
17 |
+
|
18 |
+
/* Check options */
|
19 |
+
if "`nocdf'"~="" & "`normal'"=="" {
|
20 |
+
di "{err}WARNING the nocdf option can only be used when the normal option is specified"
|
21 |
+
exit(198)
|
22 |
+
}
|
23 |
+
|
24 |
+
preserve
|
25 |
+
|
26 |
+
local yv "`varlist'"
|
27 |
+
local yvlab : variable label `yv'
|
28 |
+
|
29 |
+
/* Log-transformation -- need for change?*/
|
30 |
+
tempvar yvar w touse
|
31 |
+
if "`xlog'"=="" {
|
32 |
+
qui gen `yvar' = `yv'
|
33 |
+
lab var `yvar' "`yvlab'"
|
34 |
+
}
|
35 |
+
else {
|
36 |
+
qui gen `yvar' = log(`yv')
|
37 |
+
lab var `yvar' "Log `yvlab'"
|
38 |
+
local yvlab "Log `yvlab'"
|
39 |
+
}
|
40 |
+
|
41 |
+
/* All the weights required.. */
|
42 |
+
if "`weight'"=="" qui gen `w' = 1
|
43 |
+
else qui gen `w' `exp'
|
44 |
+
|
45 |
+
/* The missing data steps */
|
46 |
+
qui egen int `touse' = rmiss(`varlist' `w') `if' `in'
|
47 |
+
qui drop if `touse'>0
|
48 |
+
qui replace `touse'= 0
|
49 |
+
qui replace `touse'=1 `if' `in'
|
50 |
+
keep if `touse'
|
51 |
+
keep `yv' `yvar' `w' `by'
|
52 |
+
tempvar cw ccw grp sy ssy
|
53 |
+
|
54 |
+
/* now calculations... */
|
55 |
+
|
56 |
+
if "`by'"=="" {
|
57 |
+
|
58 |
+
/* cw is the cumulative probabilities sy is the normalised version */
|
59 |
+
|
60 |
+
sort `yvar'
|
61 |
+
qui gen `cw' = sum(`w')
|
62 |
+
if "`normal'"~="" {
|
63 |
+
qui gen `sy' = sum(`w'*`yvar')
|
64 |
+
qui replace `sy' = `yvar' - `sy'[_N]/`cw'[_N]
|
65 |
+
qui gen `ssy' = sum(`w'*(`sy'^2))
|
66 |
+
if "`weight'"=="" | "`weight'"=="`fweight'" qui replace `sy' = `sy'/sqrt(`ssy'[_N]/(`cw'[_N]-1))
|
67 |
+
else qui replace `sy' = `sy'/sqrt(`ssy'[_N]/`cw'[_N])
|
68 |
+
qui replace `sy' = normprob(`sy')
|
69 |
+
qui replace `cw' = `cw'/`cw'[_N]
|
70 |
+
|
71 |
+
lab var `sy' "Normal c.d.f."
|
72 |
+
lab var `cw' "c.d.f."
|
73 |
+
|
74 |
+
local vlist "`cw'"
|
75 |
+
local nlist "`sy'"
|
76 |
+
}
|
77 |
+
else {
|
78 |
+
qui replace `cw' = `cw'/`cw'[_N]
|
79 |
+
local vlist "`cw'"
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
else {
|
85 |
+
qui levelsof `by'
|
86 |
+
local bylevs "`r(levels)'"
|
87 |
+
|
88 |
+
sort `by' `yvar'
|
89 |
+
qui by `by': gen `cw' = sum(`w')
|
90 |
+
qui by `by': gen `grp' = (_n==1)
|
91 |
+
qui replace `grp' = sum(`grp')
|
92 |
+
|
93 |
+
if "`normal'"~="" {
|
94 |
+
qui by `by': gen `sy' = sum(`w'*`yvar')
|
95 |
+
qui by `by': replace `sy' = `yvar' - `sy'[_N]/`cw'[_N]
|
96 |
+
if "`samesd'"=="" {
|
97 |
+
qui by `by': gen `ssy' = sum(`w'*(`sy'^2))
|
98 |
+
if "`weight'"=="`fweight'"|"`weight'"=="" qui by `by':replace `sy'=`sy'/sqrt(`ssy'[_N]/(`cw'[_N]-1))
|
99 |
+
else qui by `by':replace `sy'=`sy'/sqrt(`ssy'[_N]/`cw'[_N])
|
100 |
+
}
|
101 |
+
else {
|
102 |
+
qui gen `ccw' = sum(`w')
|
103 |
+
qui gen `ssy' = sum(`w'*(`sy'^2))
|
104 |
+
if "`weight'"=="`fweight'"|"`weight'"=="" qui replace `sy'=`sy'/sqrt(`ssy'[_N]/(`ccw'[_N]-`grp'[_N]))
|
105 |
+
else qui replace `sy'=`sy'/sqrt(`ssy'[_N]/`ccw'[_N])
|
106 |
+
}
|
107 |
+
}
|
108 |
+
qui by `by': replace `cw' = `cw'/`cw'[_N]
|
109 |
+
|
110 |
+
/* now the loop by the different groups */
|
111 |
+
|
112 |
+
local group 1
|
113 |
+
while `group' <= `grp'[_N] {
|
114 |
+
tempvar gsc
|
115 |
+
qui gen `gsc' = `cw' if `group'==`grp'
|
116 |
+
|
117 |
+
/* Check whether the variable has a value label and then label accordingly */
|
118 |
+
local test: value label `by'
|
119 |
+
local bylevval: word `group' of `bylevs'
|
120 |
+
if "`test'"~="" local bylevname: label (`by') `bylevval'
|
121 |
+
else local bylevname `"`bylevval'"'
|
122 |
+
lab var `gsc' "c.d.f. of `bylevname' "
|
123 |
+
|
124 |
+
if "`normal'"=="" {
|
125 |
+
local vlist "`vlist' `gsc'"
|
126 |
+
local group = `group'+1
|
127 |
+
}
|
128 |
+
else {
|
129 |
+
tempvar gsd
|
130 |
+
qui gen `gsd' = normprob(`sy') if `group'==`grp'
|
131 |
+
lab var `gsd' "Normal c.d.f. for `bylevname' "
|
132 |
+
local vlist "`vlist' `gsc' "
|
133 |
+
local nlist "`nlist' `gsd' "
|
134 |
+
local group = `group'+1
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
|
139 |
+
}
|
140 |
+
qui replace `yv' = . if _n<_N & `yvar'[_n]==`yvar'[_n+1]
|
141 |
+
|
142 |
+
local n: list sizeof vlist
|
143 |
+
local connect: di _dup(`n') "J "
|
144 |
+
|
145 |
+
local plot1 `" (line `vlist' `yv', c(`connect') cmissing(y) `opt1') "'
|
146 |
+
if "`normal'"~="" local plot2 "|| (line `nlist' `yv', `opt2')"
|
147 |
+
|
148 |
+
if "`nocdf'"~="" & "`normal'"~="" cap twoway `plot2', ylabel(, angle(0)) ytitle(Cumulative Probability) `goptions'
|
149 |
+
else cap twoway `plot1' `plot2', ylabel(, angle(0)) ytitle(Cumulative Probability) `goptions'
|
150 |
+
|
151 |
+
if _rc~=0 {
|
152 |
+
di as error "WARNING: problem with the twoway command "
|
153 |
+
twoway `plot1' `plot2', ylabel(, angle(0)) ytitle(Cumulative Probability) `goptions'
|
154 |
+
}
|
155 |
+
|
156 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/cdfplot.hlp
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 9 July 2008}{...}
|
3 |
+
{cmd:help cdfplot}
|
4 |
+
{hline}
|
5 |
+
|
6 |
+
{title:Title}
|
7 |
+
|
8 |
+
{hi:Plots the cumulative distribution function}
|
9 |
+
|
10 |
+
{title:Syntax}
|
11 |
+
|
12 |
+
{p 8 27 2}
|
13 |
+
{cmdab:cdfplot} {help varname} [{help if}] [{help in}] [{help weight}]
|
14 |
+
[{cmd:,} {it:options}]
|
15 |
+
|
16 |
+
{synoptset 20 tabbed}{...}
|
17 |
+
{synopthdr}
|
18 |
+
{synoptline}
|
19 |
+
{syntab:Main}
|
20 |
+
{synopt:{opt by}(varname)} specifies a separate c.d.f. to be drawn for each value of varname. {p_end}
|
21 |
+
{synopt:{opt norm:al}} specifies that a Gaussian probability curve with the same mean and standard
|
22 |
+
deviation to be superimposed over the c.d.f. {p_end}
|
23 |
+
{synopt:{opt same:sd}} specifies that the normal c.d.f.s use the same same standard deviation. {p_end}
|
24 |
+
{synopt:{opt nocdf}} specifies that the empirical c.d.f. is not drawn. {p_end}
|
25 |
+
{synopt:{opt opt1}(twoway_options)} specifies the additional graph options for the c.d.f. plot. {p_end}
|
26 |
+
{synopt:{opt opt2}(twoway_options)} specifies the additional graph options for the Gaussian c.d.f. plots . {p_end}
|
27 |
+
{synopt:{opt {help twoway_options}}} any twoway options are applied to the final graph. {p_end}
|
28 |
+
{synoptline}
|
29 |
+
{p2colreset}{...}
|
30 |
+
|
31 |
+
|
32 |
+
{title:Description}
|
33 |
+
|
34 |
+
{pstd}
|
35 |
+
{hi:cdfplot} plots the sample cumulative distribution function. Distributions can
|
36 |
+
be compared within subgroups defined by a second variable. The best fitting
|
37 |
+
normal (Gaussian) model may be superimposed over the sample c.d.f.
|
38 |
+
|
39 |
+
{title:Updating this command using SSC}
|
40 |
+
|
41 |
+
{pstd}
|
42 |
+
To obtain the latest version click the following to uninstall the old version
|
43 |
+
|
44 |
+
{pstd}
|
45 |
+
{stata ssc uninstall cdfplot}
|
46 |
+
|
47 |
+
{pstd}
|
48 |
+
And click here to install the new version
|
49 |
+
|
50 |
+
{pstd}
|
51 |
+
{stata ssc install cdfplot}
|
52 |
+
|
53 |
+
{title:Options}
|
54 |
+
|
55 |
+
{phang}
|
56 |
+
{opt by}(varname) specifies a separate c.d.f. to be drawn for each value
|
57 |
+
of varname. These are plotted on the same graph for easier comparison.
|
58 |
+
|
59 |
+
{phang}
|
60 |
+
{opt norm:al} specifies that a normal probability curve with the same mean and standard
|
61 |
+
deviation to be superimposed over the c.d.f.
|
62 |
+
|
63 |
+
{phang}
|
64 |
+
{opt same:sd} is relevant only when {hi:by} and {hi:normal} options are used together.
|
65 |
+
It specifies that the normal curves with different means have the same standard deviations.
|
66 |
+
This demonstrates the fit of the conventional Gaussian location shift model.
|
67 |
+
|
68 |
+
{phang}
|
69 |
+
{opt nocdf} specifies that the empirical c.d.f. is not drawn but this option will not work unless
|
70 |
+
the normal option is specified, hence only the smoothed Gaussian c.d.f will be drawn. {p_end}
|
71 |
+
|
72 |
+
{phang}
|
73 |
+
{cmdab:opt1}{cmd:(}{it:twoway_options}{cmd:)} specifies additional graph options for the c.d.f. plots.
|
74 |
+
|
75 |
+
{phang}
|
76 |
+
{cmdab:opt2}{cmd:(}{it:twoway_options}{cmd:)} specifies additional graph options for the Gaussian c.d.f. plots.
|
77 |
+
|
78 |
+
{phang}
|
79 |
+
If the {hi:xlog} option is used, the {hi:normal} option causes log-normal distributions
|
80 |
+
to be fitted.
|
81 |
+
|
82 |
+
{title:Examples}
|
83 |
+
|
84 |
+
{pstd}
|
85 |
+
Using the variable {hi:length} from the {hi:auto} data (click on the following commands in order):
|
86 |
+
|
87 |
+
{pstd}
|
88 |
+
{hi: NOTE DATA will be lost when loading new data}
|
89 |
+
|
90 |
+
{pstd}
|
91 |
+
{stata sysuse auto,replace}{p_end}
|
92 |
+
{pstd}
|
93 |
+
{stata cdfplot length, normal}{p_end}
|
94 |
+
{pstd}
|
95 |
+
{stata cdfplot length, by(foreign)}{p_end}
|
96 |
+
{pstd}
|
97 |
+
{stata cdfplot length, by(foreign) norm saving(mygraph)}{p_end}
|
98 |
+
{pstd}
|
99 |
+
{stata cdfplot length [fw=rep78], by(foreign) norm saving(mygraph,replace)}{p_end}
|
100 |
+
|
101 |
+
{pstd}
|
102 |
+
Using the variable {hi:bp} from the {hi:bplong} data
|
103 |
+
|
104 |
+
{pstd}
|
105 |
+
{stata sysuse bplong,replace}{p_end}
|
106 |
+
{pstd}
|
107 |
+
{stata cdfplot bp, norm}{p_end}
|
108 |
+
{pstd}
|
109 |
+
{stata cdfplot bp, by(agegrp)}{p_end}
|
110 |
+
{pstd}
|
111 |
+
{stata cdfplot bp, by(agegrp) norm}{p_end}
|
112 |
+
|
113 |
+
{pstd}
|
114 |
+
Now to show the use of the options in the individual graphs, {hi:opt1} alters the line colours
|
115 |
+
for the c.d.f. graphs and {hi:opt2} alters the line pattern for the Gaussian c.d.f.
|
116 |
+
|
117 |
+
{pstd}
|
118 |
+
{stata cdfplot bp, by(agegrp) opt1( lc(red green olive) ) opt2( lp(dash dash dash) ) norm }
|
119 |
+
|
120 |
+
{title:Author}
|
121 |
+
|
122 |
+
{pstd}
|
123 |
+
Adrian Mander, MRC Human Nutrition Research Unit, Cambridge, UK.
|
124 |
+
|
125 |
+
{pstd}
|
126 |
+
Email {browse "mailto:[email protected]":[email protected]}
|
127 |
+
|
128 |
+
|
129 |
+
{title:Acknowledgement}
|
130 |
+
|
131 |
+
{pstd}
|
132 |
+
This command is nearly a direct port of the {hi:cdf} command that was written by
|
133 |
+
{bf: David Clayton} and {bf:Michael Hills} in STB-49.
|
134 |
+
|
135 |
+
{title:Also see}
|
136 |
+
|
137 |
+
{pstd}
|
138 |
+
{help cdf} (if installed)
|
139 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/coefplot.ado
ADDED
The diff for this file is too large to render.
See raw diff
|
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/c/coefplot.sthlp
ADDED
@@ -0,0 +1,1751 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* *! version 1.4.9 13feb2017 Ben Jann}{...}
|
3 |
+
{vieweralsosee "[G-2] graph" "help graph"}{...}
|
4 |
+
{vieweralsosee "[R] estimates" "help estimates"}{...}
|
5 |
+
{vieweralsosee "[R] marginsplot" "help marginsplot"}{...}
|
6 |
+
{vieweralsosee "[R] margins" "help margins"}{...}
|
7 |
+
{viewerjumpto "Syntax" "coefplot##syntax"}{...}
|
8 |
+
{viewerjumpto "Description" "coefplot##description"}{...}
|
9 |
+
{viewerjumpto "Options" "coefplot##options"}{...}
|
10 |
+
{viewerjumpto "Examples" "coefplot##examples"}{...}
|
11 |
+
{viewerjumpto "Remarks" "coefplot##remarks"}{...}
|
12 |
+
{viewerjumpto "Saved results" "coefplot##saved_results"}{...}
|
13 |
+
{viewerjumpto "References" "coefplot##references"}{...}
|
14 |
+
{viewerjumpto "Author" "coefplot##author"}{...}
|
15 |
+
{viewerjumpto "History" "coefplot##history"}{...}
|
16 |
+
{hi:help coefplot}{...}
|
17 |
+
{right: Also see: {browse "http://repec.sowi.unibe.ch/stata/coefplot"}}
|
18 |
+
{hline}
|
19 |
+
|
20 |
+
{title:Title}
|
21 |
+
|
22 |
+
{pstd}
|
23 |
+
{hi:coefplot} {hline 2} Plotting regression coefficients and other
|
24 |
+
results
|
25 |
+
|
26 |
+
{marker syntax}{...}
|
27 |
+
{title:Syntax}
|
28 |
+
|
29 |
+
{p 8 15 2}
|
30 |
+
{cmd:coefplot} {it:subgraph} [ || {it:subgraph} || ... ]
|
31 |
+
[{cmd:,} {help coefplot##globalopts:{it:globalopts}} ]
|
32 |
+
|
33 |
+
{pstd}
|
34 |
+
where {it:subgraph} is defined as
|
35 |
+
|
36 |
+
{p 8 16 2}
|
37 |
+
{cmd:(}{it:plot}{cmd:)} [ {cmd:(}{it:plot}{cmd:)} ... ]
|
38 |
+
[, {help coefplot##subgropts:{it:subgropts}} ]
|
39 |
+
|
40 |
+
{pstd}
|
41 |
+
and {it:plot} is either {cmd:_skip} (to skip a plot) or
|
42 |
+
|
43 |
+
{p 8 16 2}
|
44 |
+
{it:model} [ \ {it:model} \ ... ]
|
45 |
+
[, {help coefplot##plotopts:{it:plotopts}} ]
|
46 |
+
|
47 |
+
{pstd}
|
48 |
+
and {it:model} is
|
49 |
+
|
50 |
+
{p 8 16 2}
|
51 |
+
{it:name} [{cmd:,} {help coefplot##modelopts:{it:modelopts}} ]
|
52 |
+
|
53 |
+
{pstd}
|
54 |
+
where {it:name} is the name of a stored model
|
55 |
+
(see help {helpb estimates}; type {cmd:.} or leave blank to refer to
|
56 |
+
the active model). The {cmd:*} and {cmd:?} wildcards are allowed
|
57 |
+
in {it:name}; see
|
58 |
+
{help coefplot##wildcards:{it:Using wildcards in model names}}. Furthermore,
|
59 |
+
{it:model} may also be
|
60 |
+
|
61 |
+
{p 8 16 2}
|
62 |
+
{helpb coefplot##matrix:{ul:m}atrix({it:mspec})} [{cmd:,} {help coefplot##modelopts:{it:modelopts}} ]
|
63 |
+
|
64 |
+
{pstd}
|
65 |
+
to plot results from a matrix (see
|
66 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below).
|
67 |
+
Parentheses around {it:plot} can be omitted if {it:plot} does not contain
|
68 |
+
spaces.
|
69 |
+
|
70 |
+
{synoptset 25 tabbed}{...}
|
71 |
+
{marker modelopts}{synopthdr:modelopts}
|
72 |
+
{synoptline}
|
73 |
+
{syntab:Main}
|
74 |
+
{synopt:{helpb coefplot##omitted:{ul:omit}ted}}include omitted
|
75 |
+
coefficients
|
76 |
+
{p_end}
|
77 |
+
{synopt:{helpb coefplot##baselevels:{ul:base}levels}}include base levels
|
78 |
+
{p_end}
|
79 |
+
{synopt:{helpb coefplot##b:b({it:mspec})}}specify source to be plotted; default is to
|
80 |
+
plot {cmd:e(b)}
|
81 |
+
{p_end}
|
82 |
+
{synopt:{helpb coefplot##at:at{sf:[}({it:spec}){sf:]}}}get plot positions from
|
83 |
+
{cmd:e(at)}, or as specified by {it:spec}
|
84 |
+
{p_end}
|
85 |
+
{synopt:{helpb coefplot##keep:keep({it:coeflist})}}keep specified coefficients
|
86 |
+
{p_end}
|
87 |
+
{synopt:{helpb coefplot##drop:drop({it:coeflist})}}drop specified coefficients
|
88 |
+
{p_end}
|
89 |
+
|
90 |
+
{syntab:Confidence intervals}
|
91 |
+
{synopt:{helpb coefplot##noci:noci}}omit confidence intervals
|
92 |
+
{p_end}
|
93 |
+
{synopt:{helpb coefplot##levels:{ul:l}evels({it:numlist})}}set level(s) for
|
94 |
+
conficence intervals
|
95 |
+
{p_end}
|
96 |
+
{synopt:{helpb coefplot##ci:ci({it:spec})}}provide confidence intervals
|
97 |
+
{p_end}
|
98 |
+
{synopt:{helpb coefplot##v:v({it:name})}}provide variances; default is to use
|
99 |
+
{cmd:e(V)}
|
100 |
+
{p_end}
|
101 |
+
{synopt:{helpb coefplot##se:se({it:mspec})}}provide standard errors
|
102 |
+
{p_end}
|
103 |
+
{synopt:{helpb coefplot##df:df({it:spec})}}provide degrees of freedom
|
104 |
+
{p_end}
|
105 |
+
{synopt:{helpb coefplot##citype:citype(logit|{ul:norm}al)}}method to compute
|
106 |
+
confidence intervals; default is {cmd:citype(normal)}
|
107 |
+
{p_end}
|
108 |
+
|
109 |
+
{syntab:Transform results}
|
110 |
+
{synopt:{helpb coefplot##eform:eform{sf:[}({it:coeflist}){sf:]}}}plot
|
111 |
+
exponentiated point estimates and confidence intervals
|
112 |
+
{p_end}
|
113 |
+
{synopt:{helpb coefplot##rescale:rescale({it:spec})}}rescale point estimates
|
114 |
+
and confidence intervals
|
115 |
+
{p_end}
|
116 |
+
{synopt:{helpb coefplot##transform:{ul:trans}form({it:matchlist})}}transform
|
117 |
+
point estimates and confidence intervals
|
118 |
+
{p_end}
|
119 |
+
|
120 |
+
{syntab:Names and labels}
|
121 |
+
{synopt:{helpb coefplot##rename:rename({it:spec})}}rename coefficients
|
122 |
+
{p_end}
|
123 |
+
{synopt:{helpb coefplot##eqrename:{ul:eqren}ame({it:spec})}}rename
|
124 |
+
equations
|
125 |
+
{p_end}
|
126 |
+
{synopt:{helpb coefplot##asequation:{ul:aseq}uation{sf:[}({it:string}){sf:]}}}set equation
|
127 |
+
to model name or {it:string}
|
128 |
+
{p_end}
|
129 |
+
{synopt:{helpb coefplot##swapnames:{ul:swap}names}}swap coefficient names and
|
130 |
+
equation names
|
131 |
+
{p_end}
|
132 |
+
{synopt:{helpb coefplot##mlabels:mlabels({it:matchlist})}}specify marker labels
|
133 |
+
{p_end}
|
134 |
+
|
135 |
+
{syntab:Auxiliary results}
|
136 |
+
{synopt:{helpb coefplot##aux:aux({sf:{it:mspec} [{it:mspec} ...]})}}make
|
137 |
+
additional results available as {cmd:@aux1}, {cmd:@aux2}, etc.
|
138 |
+
{p_end}
|
139 |
+
{synoptline}
|
140 |
+
|
141 |
+
{synoptset 25 tabbed}{...}
|
142 |
+
{marker plotopts}{synopthdr:plotopts}
|
143 |
+
{synoptline}
|
144 |
+
{syntab:Passthru}
|
145 |
+
{synopt:{help coefplot##modelopts:{it:modelopts}}}plot-specific model options;
|
146 |
+
see {help coefplot##place:{it:Placement of options}}
|
147 |
+
{p_end}
|
148 |
+
|
149 |
+
{syntab:Main}
|
150 |
+
{synopt:{helpb coefplot##label:{ul:lab}el({it:string})}}label to be used for
|
151 |
+
the plot in the legend
|
152 |
+
{p_end}
|
153 |
+
{synopt:{helpb coefplot##key:key{sf:[}(ci {sf:[}#{sf:]}){sf:]}}}key
|
154 |
+
symbol to be used for the plot in the legend
|
155 |
+
{p_end}
|
156 |
+
{synopt:{helpb coefplot##nokey:nokey}}do not include the plot in the legend
|
157 |
+
{p_end}
|
158 |
+
{synopt:{helpb coefplot##pstyle:{ul:psty}le({it:pstyle})}}overall
|
159 |
+
style of the plot
|
160 |
+
{p_end}
|
161 |
+
{synopt:{helpb coefplot##axis:{ul:ax}is({it:#})}}choice of axis for the plot, {cmd:1} {ul:<} {it:#} {ul:<} {cmd:9}
|
162 |
+
{p_end}
|
163 |
+
{synopt:{helpb coefplot##offset:offset({it:#})}}provide offset for plot
|
164 |
+
positions
|
165 |
+
{p_end}
|
166 |
+
{synopt:{helpb coefplot##ifopt:if({it:exp})}}restrict the contents of the plot
|
167 |
+
{p_end}
|
168 |
+
{synopt:{helpb coefplot##weight:{ul:w}eight({it:exp})}}scale size of markers
|
169 |
+
{p_end}
|
170 |
+
|
171 |
+
{syntab:Markers}
|
172 |
+
{synopt:{it:{help marker_options}}}change look of
|
173 |
+
markers (color, size, etc.)
|
174 |
+
{p_end}
|
175 |
+
{synopt:{helpb coefplot##mlabel:{ul:ml}abel}}add coefficient values as marker
|
176 |
+
labels
|
177 |
+
{p_end}
|
178 |
+
{synopt:{it:{help marker_label_options}}}change the look and position of marker
|
179 |
+
labels
|
180 |
+
{p_end}
|
181 |
+
{synopt:{helpb coefplot##recast:recast({it:plottype})}}plot results using
|
182 |
+
{it:plottype}
|
183 |
+
{p_end}
|
184 |
+
|
185 |
+
{syntab:Confidence spikes}
|
186 |
+
{synopt:{helpb coefplot##cionly:cionly}}plot confidence spikes only
|
187 |
+
{p_end}
|
188 |
+
{synopt:{helpb coefplot##citop:citop}}draw confidence spikes in front
|
189 |
+
of markers
|
190 |
+
{p_end}
|
191 |
+
{synopt:{helpb coefplot##ciopts:{ul:ciop}ts({it:options})}}affect rendition
|
192 |
+
of confidence spikes
|
193 |
+
{p_end}
|
194 |
+
{synopt:{helpb coefplot##cismooth:{ul:cis}mooth{sf:[}({it:options}){sf:]}}}add smoothed
|
195 |
+
confidence intervals
|
196 |
+
{p_end}
|
197 |
+
{synoptline}
|
198 |
+
|
199 |
+
{synoptset 25 tabbed}{...}
|
200 |
+
{marker subgropts}{synopthdr:subgropts}
|
201 |
+
{synoptline}
|
202 |
+
{syntab:Passthru}
|
203 |
+
{synopt:{help coefplot##modelopts:{it:modelopts}}}subgraph-specific model
|
204 |
+
options; see {help coefplot##place:{it:Placement of options}}
|
205 |
+
{p_end}
|
206 |
+
{synopt:{help coefplot##plotopts:{it:plotopts}}}subgraph-specific plot
|
207 |
+
options; see {help coefplot##place:{it:Placement of options}}
|
208 |
+
{p_end}
|
209 |
+
|
210 |
+
{syntab:Main}
|
211 |
+
{synopt:{helpb coefplot##bylabel:{ul:bylab}el({it:string})}}label to be used
|
212 |
+
for the subgraph
|
213 |
+
{p_end}
|
214 |
+
{synoptline}
|
215 |
+
|
216 |
+
{synoptset 25 tabbed}{...}
|
217 |
+
{marker globalopts}{synopthdr:globalopts}
|
218 |
+
{synoptline}
|
219 |
+
{syntab:Passthru}
|
220 |
+
{synopt:{help coefplot##modelopts:{it:modelopts}}}global model options; see
|
221 |
+
{help coefplot##place:{it:Placement of options}}
|
222 |
+
{p_end}
|
223 |
+
{synopt:{help coefplot##plotopts:{it:plotopts}}}global plot options; see
|
224 |
+
{help coefplot##place:{it:Placement of options}}
|
225 |
+
{p_end}
|
226 |
+
{synopt:{help coefplot##subgropts:{it:subgropts}}}global subgraph options;
|
227 |
+
see {help coefplot##place:{it:Placement of options}}
|
228 |
+
{p_end}
|
229 |
+
|
230 |
+
{syntab:Main}
|
231 |
+
{synopt:{helpb coefplot##horizontal:{ul:hor}izontal}}coefficient values are
|
232 |
+
on x axis; general default
|
233 |
+
{p_end}
|
234 |
+
{synopt:{helpb coefplot##vertical:{ul:vert}ical}}coefficient values are on y
|
235 |
+
axis; default with {cmd:at()}
|
236 |
+
{p_end}
|
237 |
+
{synopt:{helpb coefplot##eqstrict:eqstrict}}be strict about equations
|
238 |
+
{p_end}
|
239 |
+
{synopt:{helpb coefplot##order:order({it:coeflist})}}order coefficients
|
240 |
+
{p_end}
|
241 |
+
{synopt:{helpb coefplot##orderby:orderby({it:spec})}}order coefficients by
|
242 |
+
specific model
|
243 |
+
{p_end}
|
244 |
+
{synopt:{helpb coefplot##sort:sort{sf:[}({it:spec}){sf:]}}}sort coefficients
|
245 |
+
{p_end}
|
246 |
+
{synopt:{helpb coefplot##relocate:{ul:reloc}ate({it:spec})}}assign
|
247 |
+
specific positions to coefficients
|
248 |
+
{p_end}
|
249 |
+
{synopt:{helpb coefplot##bycoefs:{ul:byc}oefs}}arrange subgraphs by
|
250 |
+
coefficients
|
251 |
+
{p_end}
|
252 |
+
{synopt:{helpb coefplot##norecycle:{ul:norec}ycle}}increment plot styles across
|
253 |
+
subgraphs
|
254 |
+
{p_end}
|
255 |
+
{synopt:{helpb coefplot##nooffsets:{ul:nooff}sets}}do not offset plot
|
256 |
+
positions
|
257 |
+
{p_end}
|
258 |
+
{synopt:{helpb coefplot##format:format({it:format})}}set the display format for
|
259 |
+
numeric labels
|
260 |
+
{p_end}
|
261 |
+
{synopt:{helpb coefplot##pnum:p{it:#}({it:plotopts})}}options for {it:#}th plot
|
262 |
+
{p_end}
|
263 |
+
|
264 |
+
{syntab:Labels and grid lines}
|
265 |
+
{synopt:{helpb coefplot##nolabels:{ul:nolab}els}}use variable names instead of
|
266 |
+
labels
|
267 |
+
{p_end}
|
268 |
+
{synopt:{helpb coefplot##coeflabels:{ul:coefl}abels({it:spec})}}specify
|
269 |
+
custom labels for coefficients
|
270 |
+
{p_end}
|
271 |
+
{synopt:{helpb coefplot##noeqlabels:{ul:noeql}abels}}suppress equation labels
|
272 |
+
{p_end}
|
273 |
+
{synopt:{helpb coefplot##eqlabels:{ul:eql}abels({it:spec})}}specify labels
|
274 |
+
for equations
|
275 |
+
{p_end}
|
276 |
+
{synopt:{helpb coefplot##headings:{ul:head}ings({it:spec})}}add headings between
|
277 |
+
coefficients
|
278 |
+
{p_end}
|
279 |
+
{synopt:{helpb coefplot##groups:groups({it:spec})}}add labels for groups of
|
280 |
+
coefficients
|
281 |
+
{p_end}
|
282 |
+
{synopt:{helpb coefplot##plotlabels:{ul:plotl}abels({it:spec})}}(re)set plot
|
283 |
+
labels
|
284 |
+
{p_end}
|
285 |
+
{synopt:{helpb coefplot##bylabels:bylabels({it:spec})}}(re)set subgraph
|
286 |
+
labels
|
287 |
+
{p_end}
|
288 |
+
{synopt:{helpb coefplot##grid:grid({it:options})}}affect rendition of grid lines
|
289 |
+
{p_end}
|
290 |
+
|
291 |
+
{syntab:Save results}
|
292 |
+
{synopt:{helpb coefplot##generate:{ul:gen}erate{sf:[}({it:prefix}){sf:]}}}generate
|
293 |
+
variables containing the graph data
|
294 |
+
{p_end}
|
295 |
+
{synopt:{helpb coefplot##replace:replace}}overwrite existing variables
|
296 |
+
{p_end}
|
297 |
+
|
298 |
+
{syntab:Add plots}
|
299 |
+
{synopt:{helpb addplot_option:addplot({it:plot})}}add other plots to the
|
300 |
+
graph
|
301 |
+
{p_end}
|
302 |
+
{synopt:{helpb coefplot##nodrop:nodrop}}do not drop observations
|
303 |
+
{p_end}
|
304 |
+
|
305 |
+
{syntab:Y axis, X axis, Titles, Legend, Overall, By}
|
306 |
+
{synopt:{it:{help twoway_options}}}twoway options, other than {cmd:by()}
|
307 |
+
{p_end}
|
308 |
+
{synopt:{cmdab:byop:ts(}{it:{help by_option:byopts}}{cmd:)}}how subgraphs
|
309 |
+
are combined
|
310 |
+
{p_end}
|
311 |
+
{synoptline}
|
312 |
+
|
313 |
+
|
314 |
+
{marker description}{...}
|
315 |
+
{title:Description}
|
316 |
+
|
317 |
+
{pstd}
|
318 |
+
{cmd:coefplot} plots results from estimation commands or Stata matrices.
|
319 |
+
Results from multiple models or matrices can be combined in a single
|
320 |
+
graph. The default behavior of {cmd:coefplot} is to draw markers for
|
321 |
+
coefficients and horizontal spikes for confidence intervals. However,
|
322 |
+
{cmd:coefplot} can also produce various other types of graphs.
|
323 |
+
|
324 |
+
|
325 |
+
{marker options}{...}
|
326 |
+
{title:Options}
|
327 |
+
{dlgtab:Model options}
|
328 |
+
|
329 |
+
{marker omitted}{...}
|
330 |
+
{phang}
|
331 |
+
{cmd:omitted} includes omitted coefficients. This may be useful if a model
|
332 |
+
contains coefficients that have been dropped due to collinearity.
|
333 |
+
|
334 |
+
{marker baselevels}{...}
|
335 |
+
{phang}
|
336 |
+
{cmd:baselevels} includes base levels of factor variables.
|
337 |
+
|
338 |
+
{marker b}{...}
|
339 |
+
{phang}
|
340 |
+
{cmd:b(}{it:mspec}{cmd:)} specifies the source from which the point
|
341 |
+
estimates and coefficient names are to be collected. The default is to use
|
342 |
+
(the first row of) {cmd:e(b)} (or {cmd:e(b_mi)} if plotting results from
|
343 |
+
{helpb mi estimate}). {cmd:b()} is discarded in matrix mode (see
|
344 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below).
|
345 |
+
{it:mspec} may be:
|
346 |
+
|
347 |
+
{p2colset 13 25 27 2}{...}
|
348 |
+
{p2col:{it:name}}use first row of {cmd:e(}{it:name}{cmd:)}
|
349 |
+
{p_end}
|
350 |
+
{p2col:{it:name}{cmd:[}#{cmd:,.]}}use #th row of
|
351 |
+
{cmd:e(}{it:name}{cmd:)}; may also type {it:name}{cmd:[}#{cmd:,]}
|
352 |
+
or {it:name}{cmd:[}#{cmd:]}
|
353 |
+
{p_end}
|
354 |
+
{p2col:{it:name}{cmd:[.,}#{cmd:]}}use #th column of
|
355 |
+
{cmd:e(}{it:name}{cmd:)}; may also type {it:name}{cmd:[,}#{cmd:]}
|
356 |
+
{p_end}
|
357 |
+
{p2colreset}{...}
|
358 |
+
|
359 |
+
{marker at}{...}
|
360 |
+
{phang}
|
361 |
+
{cmd:at}[{cmd:(}{it:spec}{cmd:)}] causes plot positions to be determined
|
362 |
+
by the values in {cmd:e(at)} (or matrix {cmd:at}) or as specified by
|
363 |
+
{it:spec}. The default is to create a categorical axis with coefficients
|
364 |
+
matched by their names. However, if {cmd:at} is specified, the axis is
|
365 |
+
treated as continuous. Note that labeling options
|
366 |
+
{cmd:coeflabels()}, {cmd:eqlabels()}, {cmd:headings()}, or {cmd:groups()}
|
367 |
+
are not allowed if {cmd:at} is specified. Also not allowed with {cmd:at}
|
368 |
+
are options {cmd:bycoefs}, {cmd:order()}, and {cmd:relocate()}.
|
369 |
+
Furthermore, note that {cmd:at} has to be specified for all models or
|
370 |
+
for none. {it:spec} is
|
371 |
+
|
372 |
+
[{it:atspec}] [{cmd:,} {opt t:ransform(exp)}]
|
373 |
+
|
374 |
+
{pmore}
|
375 |
+
where {it:atspec} may be
|
376 |
+
|
377 |
+
{p2colset 13 27 29 2}{...}
|
378 |
+
{p2col:{it:mspec}}as above for {helpb coefplot##b:b()}
|
379 |
+
{p_end}
|
380 |
+
{p2col:#}use #th at-dimension ({helpb margins}) or #th row/column of main matrix
|
381 |
+
{p_end}
|
382 |
+
{p2col:{opt m:atrix(mspec)}}read from matrix instead of {cmd:e()}
|
383 |
+
{p_end}
|
384 |
+
{p2col:{opt _coef}}use coefficient names as plot positions
|
385 |
+
{p_end}
|
386 |
+
{p2col:{opt _eq}}use equation names as plot positions
|
387 |
+
{p_end}
|
388 |
+
{p2colreset}{...}
|
389 |
+
|
390 |
+
{pmore}
|
391 |
+
If {cmd:at} is specified without argument, the plot positions are taken from the first row
|
392 |
+
of {cmd:e(at)} (or matrix {cmd:at}). A special case are results from
|
393 |
+
{helpb margins} where recovering the plot positions is more
|
394 |
+
complicated. The default in this case is to use the first
|
395 |
+
at-dimension. Type, e.g., {cmd:at(2)} if multiple at-dimension were specified
|
396 |
+
with {helpb margins} and you want to use the second dimension. Furthermore,
|
397 |
+
in matrix mode (see
|
398 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below), {cmd:at(2)}
|
399 |
+
would read the plot positions from the 2nd row (or column) of the main matrix.
|
400 |
+
|
401 |
+
{pmore}
|
402 |
+
When plotting results from {cmd:e()} it is sometimes convenient to
|
403 |
+
maintain an external matrix with the plot positions instead of
|
404 |
+
adding plot positions to each {cmd:e()}-set. In this case you can use
|
405 |
+
syntax {cmd:at(matrix(}{it:mspec}{cmd:))} to read the plot positions. Note
|
406 |
+
that the vector of plot positions must have the same length as the
|
407 |
+
coefficient vectors of the plotted models; elements are matched by position,
|
408 |
+
not by name.
|
409 |
+
|
410 |
+
{pmore}
|
411 |
+
Furthermore, {cmd:at(_coef)} or {cmd:at(_eq)} will use the coefficient names or
|
412 |
+
the equation names as plot positions, respectively. This is useful only if
|
413 |
+
the coefficient names or the equation names are numeric. Note that you may
|
414 |
+
use {helpb coefplot##rename:rename()} and
|
415 |
+
{helpb coefplot##eqrename:eqrename()} to strip a non-numeric prefix or suffix
|
416 |
+
from coefficient names or equation names.
|
417 |
+
|
418 |
+
{pmore}
|
419 |
+
Suboption {cmd:transform()} transforms the plot positions before creating
|
420 |
+
the graph. Within the transformation expression, use {cmd:@} as a
|
421 |
+
placeholder for the value to be transformed. For example, to take the
|
422 |
+
antilogarithm of the plot positions type {cmd:transform(exp(@))}.
|
423 |
+
|
424 |
+
{marker keep}{...}
|
425 |
+
{phang}
|
426 |
+
{cmd:keep(}{it:coeflist}{cmd:)} specifies the coefficients to be
|
427 |
+
plotted. The default is to include all coefficients from the
|
428 |
+
first (nonzero) equation of a model (and discard further equations).
|
429 |
+
{it:coeflist} is a space-separated list of
|
430 |
+
elements such as:
|
431 |
+
|
432 |
+
{p2colset 13 25 27 2}{...}
|
433 |
+
{p2col:{it:coef}}keep coefficient {it:coef}
|
434 |
+
{p_end}
|
435 |
+
{p2col:{it:eq}{cmd::}}keep all coefficients from equation {it:eq}
|
436 |
+
{p_end}
|
437 |
+
{p2col:{it:eq}{cmd::}{it:coef}}keep coefficient {it:coef} from equation {it:eq}
|
438 |
+
{p_end}
|
439 |
+
{p2colreset}{...}
|
440 |
+
|
441 |
+
{pmore}
|
442 |
+
where {it:eq} and {it:coef} may contain "{cmd:*}" (any string) and
|
443 |
+
"{cmd:?}" (any nonzero character) wildcards. For example, type {cmd:keep(*:)} or
|
444 |
+
{cmd:keep(*:*)} to plot all coefficients from all equations.
|
445 |
+
|
446 |
+
{pmore}
|
447 |
+
If {it:eq} is specified, it is applied to all subsequent
|
448 |
+
names until a new {it:eq} is specified. For example,
|
449 |
+
{cmd:keep(3:mpg price 4:weight)} will plot coefficients "{cmd:mpg}" and
|
450 |
+
"{cmd:price}" from equation "{cmd:3}" and coefficient "{cmd:weight}" from
|
451 |
+
equation "{cmd:4}".
|
452 |
+
|
453 |
+
{marker drop}{...}
|
454 |
+
{phang}
|
455 |
+
{cmd:drop(}{it:coeflist}{cmd:)} drops the specified coefficients, where
|
456 |
+
{it:coeflist} is as above for {helpb coefplot##keep:keep()}.
|
457 |
+
|
458 |
+
{marker noci}{...}
|
459 |
+
{phang}
|
460 |
+
{cmd:noci} omits confidence intervals.
|
461 |
+
|
462 |
+
{marker levels}{...}
|
463 |
+
{phang}
|
464 |
+
{cmd:levels(}{it:{help numlist}}{cmd:)} sets the level(s), as percentages,
|
465 |
+
for confidence intervals. Specified values may be between 10.00 and 99.99
|
466 |
+
and can have at most two digits after the decimal point. The default is
|
467 |
+
{cmd:levels(95)} or as set by {helpb set level}. If multiple values are
|
468 |
+
specified, multiple confidence intervals are plotted. For example, type
|
469 |
+
{cmd:levels(99.9 99 95)} to plot the 99.9%, 99%, and 95% confidence
|
470 |
+
intervals. The default is to use (logarithmically) increasing line widths
|
471 |
+
for multiple confidence intervals. This behavior is disabled as soon as
|
472 |
+
{cmd:lwidth()} or {cmd:recast()} is specified within
|
473 |
+
{helpb coefplot##ciopts:ciopts()}.
|
474 |
+
|
475 |
+
{marker ci}{...}
|
476 |
+
{phang}
|
477 |
+
{cmd:ci(}{it:spec}{cmd:)} specifies the source from which to collect
|
478 |
+
confidence intervals. Default is to compute confidence intervals for the
|
479 |
+
levels specified in {cmd:levels()} using variances/standard errors (and,
|
480 |
+
possibly, degrees of freedom). The {cmd:ci()} option is useful to
|
481 |
+
plot confidence intervals that have been provided by the estimation
|
482 |
+
command (such as, e.g., {helpb bootstrap}). {it:spec} is
|
483 |
+
|
484 |
+
{it:cispec} [{it:cispec} ...]
|
485 |
+
|
486 |
+
{pmore}
|
487 |
+
where {it:cispec} is {it:name} to get the lower and upper confidence limits
|
488 |
+
from rows 1 and 2 of {cmd:e(}{it:name}{cmd:)} (or matrix {it:name}),
|
489 |
+
respectively. Alternatively, {it:cispec} may be {cmd:(}{it:mspec}
|
490 |
+
{it:mspec}{cmd:)} to identify the lower and upper confidence limits, with
|
491 |
+
{it:mspec} as above for {helpb coefplot##b:b()}. For example, after
|
492 |
+
{helpb bootstrap}, {cmd:ci(ci_bc)} would get bias-corrected confidence intervals
|
493 |
+
from rows 1 and 2 of {cmd:e(ci_bc)}. The same could be achieved by
|
494 |
+
{cmd:ci((ci_bc[1] ci_bc[2]))}.
|
495 |
+
|
496 |
+
{pmore}
|
497 |
+
{it:cispec} may also be # for a specific confidence level as in
|
498 |
+
{helpb coefplot##levels:levels()}. Hence, you may type, e.g.,
|
499 |
+
{cmd:ci(95 myci)} to plot the usual 95% confidence intervals along with
|
500 |
+
custom confidence intervals provided in {cmd:e(myci)}. Levels specified
|
501 |
+
in {cmd:ci()} take precedence over levels specified in {cmd:levels()}),
|
502 |
+
however, you may also type {cmd:""} within {cmd:ci()} to leave a
|
503 |
+
position blank an use the specified level from {cmd:levels()}.
|
504 |
+
|
505 |
+
{pmore}
|
506 |
+
In matrix mode (see
|
507 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below),
|
508 |
+
{it:cispec} may also be {cmd:(}# #{cmd:)}. For example, {cmd:ci((2 3))} would
|
509 |
+
read the lower confidence limit from the 2nd row (or column) and
|
510 |
+
the upper confidence limit from the 3rd row (or column) of the main matrix.
|
511 |
+
|
512 |
+
{marker v}{...}
|
513 |
+
{phang}
|
514 |
+
{cmd:v(}{it:name}{cmd:)} specifies that the variances for confidence interval
|
515 |
+
computation are to be taken from the diagonal of {cmd:e(}{it:name}{cmd:)}
|
516 |
+
(or matrix {it:name}). Default is {cmd:e(V)} (or {cmd:e(V_mi)} if plotting
|
517 |
+
results from {helpb mi estimate}).
|
518 |
+
|
519 |
+
{marker se}{...}
|
520 |
+
{phang}
|
521 |
+
{cmd:se(}{it:mspec}{cmd:)} provides standard errors to be used for
|
522 |
+
computation of confidence intervals. Default is to compute confidence
|
523 |
+
intervals based on the variances in {cmd:e(V)}
|
524 |
+
(see {helpb coefplot##v:v()} above). {it:mspec} is as above for
|
525 |
+
{helpb coefplot##b:b()}.
|
526 |
+
In matrix mode (see
|
527 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below), you may
|
528 |
+
also specify {cmd:se(}#{cmd:)} to read the standard errors from the #th
|
529 |
+
row (or column) of the main matrix.
|
530 |
+
|
531 |
+
{marker df}{...}
|
532 |
+
{phang}
|
533 |
+
{cmd:df(}{it:spec}{cmd:)} specifies degrees of freedom (DF) to be taken into
|
534 |
+
account for confidence interval computation. Default is to obtain DF
|
535 |
+
from scalar {cmd:e(df_r)} if defined (as in, e.g., {helpb regress})
|
536 |
+
or, for results from {helpb mi estimate}, from matrix {cmd:e(df_mi)}. Otherwise,
|
537 |
+
no DF are taken into account. Specify {cmd:df(}{it:spec}{cmd:)} to provide
|
538 |
+
custom DF. {it:spec} may be:
|
539 |
+
|
540 |
+
{p2colset 13 25 27 2}{...}
|
541 |
+
{p2col:#}set DF for all coefficients to #
|
542 |
+
{p_end}
|
543 |
+
{p2col:{it:mspec}}as above for {helpb coefplot##b:b()}
|
544 |
+
{p_end}
|
545 |
+
{p2colreset}{...}
|
546 |
+
|
547 |
+
{marker citype}{...}
|
548 |
+
{phang}
|
549 |
+
{cmd:citype()} specifies the method to be used to compute the limits of
|
550 |
+
confidence intervals. {cmd:citype(normal)}, the default, computes confidence
|
551 |
+
limits based on untransformed coefficients and standard errors. Let {it:b} be
|
552 |
+
the point estimate, {it:se} the standard error, and {it:t} the (1-{it:a}/2)
|
553 |
+
quantile of the standard normal distribution or the t-distribution (if degrees
|
554 |
+
of freedom are available; see above), where {it:a} is 1 minus the
|
555 |
+
confidence level (e.g. {it:a}=5% for a 95% confidence interval). Then the
|
556 |
+
limits of the {cmd:citype(normal)} confidence interval are defined as
|
557 |
+
|
558 |
+
{it:b} +/- {it:t} * {it:se}
|
559 |
+
|
560 |
+
{pmore}
|
561 |
+
{cmd:citype(logit)} uses the logit transformation to compute the limits
|
562 |
+
of confidence intervals. This is useful if the estimates to be plotted are
|
563 |
+
proportions and the confidence limits are supposed to lie between 0 and 1.
|
564 |
+
The limits of the {cmd:citype(logit)} confidence interval are computed as
|
565 |
+
|
566 |
+
invlogit(logit({it:b}) +/- {it:t} * {it:se} / ({it:b} * (1 - {it:b})))
|
567 |
+
|
568 |
+
{pmore}
|
569 |
+
(see the "Methods and formulas" section in
|
570 |
+
{mansection R proportion:{bf:[R] proportion}}).
|
571 |
+
|
572 |
+
{marker eform}{...}
|
573 |
+
{phang}
|
574 |
+
{cmd:eform}[{cmd:(}{it:coeflist}{cmd:)}] causes point estimates and
|
575 |
+
confidence intervals to be exponentiated. This is useful
|
576 |
+
if you want to plot hazard ratios (HR), incidence-rate ratios (IRR),
|
577 |
+
odds ratios (OR), or relative-risk ratios (RRR). If {cmd:eform} is
|
578 |
+
specified without arguments, then all coefficients of the model are
|
579 |
+
exponentiated. To exponentiate only selected coefficients, specify
|
580 |
+
{it:coeflist} as above for {helpb coefplot##keep:keep()}.
|
581 |
+
|
582 |
+
{marker rescale}{...}
|
583 |
+
{phang}
|
584 |
+
{cmd:rescale(}{it:spec}{cmd:)} rescales point estimates and confidence
|
585 |
+
intervals. Type {cmd:rescale(}#{cmd:)} to rescale all coefficients
|
586 |
+
by a constant factor. For example, {cmd:rescale(100)} will multiply all
|
587 |
+
coefficients by 100. Alternatively, {it:spec} may be
|
588 |
+
|
589 |
+
{it:coeflist} {cmd:=} # [{it:coeflist} {cmd:=} # ...]
|
590 |
+
|
591 |
+
{pmore}
|
592 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()}.
|
593 |
+
|
594 |
+
{marker transform}{...}
|
595 |
+
{phang}
|
596 |
+
{cmd:transform(}{it:matchlist}{cmd:)} transforms point estimates and confidence
|
597 |
+
intervals. {it:machlist} is:
|
598 |
+
|
599 |
+
{it:coeflist} {cmd:= "}{it:{help exp}}{cmd:"} [{it:coeflist} {cmd:= "}{it:{help exp}}{cmd:"} ...]
|
600 |
+
|
601 |
+
{pmore}
|
602 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()}. Within the
|
603 |
+
transformation expression, use {cmd:@} as a placeholder for
|
604 |
+
the value to be transformed. For example, to take the square root of all
|
605 |
+
coefficients type {cmd:transform(* = sqrt(@))}. In addition, internal
|
606 |
+
variables may be used as explained in
|
607 |
+
{help coefplot##tempvar:Accessing internal temporary variables}. The
|
608 |
+
transformation expression must be enclosed in double quotes if it contains
|
609 |
+
spaces. If specified, {cmd:eform()} and {cmd:rescale()} are applied before applying
|
610 |
+
{cmd:transform()}.
|
611 |
+
|
612 |
+
{marker rename}{...}
|
613 |
+
{phang}
|
614 |
+
{cmd:rename(}{it:spec}{cmd:)} renames coefficients. {it:spec} is:
|
615 |
+
|
616 |
+
{it:coeflist} {cmd:=} {it:newname} [{it:coeflist} {cmd:=} {it:newname} ...] [{cmd:,} {cmdab:r:egex}]
|
617 |
+
|
618 |
+
{pmore}
|
619 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()} except that
|
620 |
+
wildcards are only allowed in equation names, and coefficient names may
|
621 |
+
be specified as {it:prefix}{cmd:*} to replace a prefix or
|
622 |
+
{cmd:*}{it:suffix} to replace a suffix. For example,
|
623 |
+
{cmd:rename(*.foreign = .cartype)} will rename coefficients such as
|
624 |
+
{cmd:0.foreign} and {cmd:1.foreign} to {cmd:0.cartype} and
|
625 |
+
{cmd:1.cartype}. {it:newname} must be enclosed in double quotes if it
|
626 |
+
contains spaces. For labeling coefficients, also see
|
627 |
+
{helpb coefplot##coeflabels:coeflabels()}.
|
628 |
+
|
629 |
+
{pmore}
|
630 |
+
Apply option {cmd:regex} to cause coefficient specifications (but not
|
631 |
+
equation specifications) to be interpreted as
|
632 |
+
{browse "https://en.wikipedia.org/wiki/Regular_expression":regular expressions}. In this
|
633 |
+
case, {it:newname} may contain {cmd:\1}, ..., {cmd:\9} to reference back to
|
634 |
+
matched subexpressions (and {cmd:\0} for the entire match). For example, type
|
635 |
+
{cmd:rename(^AA([0-9]+)BB$ = YY\1ZZ, regex)} to rename
|
636 |
+
coefficients such as {cmd:AA123BB}, {cmd:AA0BB}, or {cmd:AA99BB} to
|
637 |
+
{cmd:YY123ZZ}, {cmd:YY0ZZ}, or {cmd:YY99ZZ}. If the leading {cmd:^} or the
|
638 |
+
tailing {cmd:$} is omitted, only the matched part of a coefficient name is
|
639 |
+
subject to substitution; the rest of the name will remain unchanged. Include
|
640 |
+
the regular expressions in quotes or compound double quotes if they contain
|
641 |
+
funny characters (such as, e.g., quotes, equal signs, or commas).
|
642 |
+
|
643 |
+
{marker eqrename}{...}
|
644 |
+
{phang}
|
645 |
+
{cmd:eqrename(}{it:spec}{cmd:)} renames equations. {it:spec} is:
|
646 |
+
|
647 |
+
{it:eqlist} {cmd:=} {it:newname} [{it:eqlist} {cmd:=} {it:newname} ...] [{cmd:,} {cmdab:r:egex}]
|
648 |
+
|
649 |
+
{pmore}
|
650 |
+
where {it:eqlist} is a space separated list of equation names. Equation
|
651 |
+
names may be {it:prefix}{cmd:*} to replace a prefix or
|
652 |
+
{cmd:*}{it:suffix} to replace a suffix. For example,
|
653 |
+
{cmd:eqrename(rep78* = reprec)} will rename equations such as
|
654 |
+
{cmd:rep78_3} and {cmd:rep78_4} to {cmd:reprec_3} and
|
655 |
+
{cmd:reprec_4}. {it:newname} must be enclosed in double quotes if it
|
656 |
+
contains spaces. For labeling equations, also see
|
657 |
+
{helpb coefplot##eqlabels:eqlabels()}.
|
658 |
+
|
659 |
+
{pmore}
|
660 |
+
Apply option {cmd:regex} to cause equation specifications to be interpreted as
|
661 |
+
{browse "https://en.wikipedia.org/wiki/Regular_expression":regular expressions}. In this
|
662 |
+
case, {it:newname} may contain {cmd:\1}, ..., {cmd:\9} to reference back to
|
663 |
+
matched subexpressions (and {cmd:\0} for the entire match). For example, type
|
664 |
+
{cmd:eqrename(^eq([0-9])0$ = Outcome_\1, regex)} to rename
|
665 |
+
equations such as {cmd:eq20} or {cmd:eq90} to
|
666 |
+
{cmd:Outcome_1} or {cmd:Outcome_9}. If the leading {cmd:^} or the
|
667 |
+
tailing {cmd:$} is omitted, only the matched part of an equation name is
|
668 |
+
subject to substitution; the rest of the name will remain unchanged. Include the regular expressions in
|
669 |
+
quotes or compound double quotes if they contain funny characters (such as, e.g., quotes,
|
670 |
+
equal signs, or commas).
|
671 |
+
|
672 |
+
{marker asequation}{...}
|
673 |
+
{phang}
|
674 |
+
{cmd:asequation}[{cmd:(}{it:string}{cmd:)}] sets the equation name for all
|
675 |
+
included coefficients from the model to {it:string}. This is useful if you
|
676 |
+
want to assign an equation name to results that have been stored without
|
677 |
+
information on equations. If {cmd:asequation} is specified without
|
678 |
+
argument, the name of the model is used. If you apply the
|
679 |
+
{cmd:asequation()} option you may also want to specify
|
680 |
+
{helpb coefplot##eqstrict:eqstrict}.
|
681 |
+
|
682 |
+
{marker swapnames}{...}
|
683 |
+
{phang}
|
684 |
+
{cmd:swapnames} swaps coefficient names and equation names after collecting
|
685 |
+
the model's results. The names are swapped after applying model options
|
686 |
+
such as {cmd:keep()}, {cmd:drop()}, or {cmd:rename()} but
|
687 |
+
before applying global options such as {cmd:coeflabel()}, {cmd:order()},
|
688 |
+
or {cmd:eqlabels()}.
|
689 |
+
|
690 |
+
{marker mlabels}{...}
|
691 |
+
{phang}
|
692 |
+
{cmd:mlabels(}{it:matchlist}{cmd:)} specifies marker labels for
|
693 |
+
coefficients. {it:matchlist} is:
|
694 |
+
|
695 |
+
{it:coeflist} {cmd:=} # "{it:label}" [{it:coeflist} {cmd:=} # "{it:label}" ...]
|
696 |
+
|
697 |
+
{pmore}
|
698 |
+
where {it:coeflist} is as above for {helpb coefplot##keep:keep()} and # is a
|
699 |
+
number 0--12 for the location of the marker label (see
|
700 |
+
{manhelpi clockposstyle G-4}). Not all of Stata's plot types
|
701 |
+
support marker labels. For example, if you use
|
702 |
+
{helpb coefplot##recast:recast(bar)} to change the plot type to
|
703 |
+
{helpb twoway_bar:bar}, no marker labels will be displayed.
|
704 |
+
|
705 |
+
{marker aux}{...}
|
706 |
+
{phang}
|
707 |
+
{cmd:aux(}{it:mspec} [{it:mspec} ...]{cmd:)} collects additional results
|
708 |
+
and makes them available as internal variables. {it:mspec} is as above for
|
709 |
+
{helpb coefplot##b:b()}. The internal variables
|
710 |
+
are named {cmd:@aux1}, {cmd:@aux2}, ..., and can be used within
|
711 |
+
{helpb coefplot##ifopt:if()},
|
712 |
+
{helpb coefplot##weight:weight()},
|
713 |
+
{helpb coefplot##transform:transform()},
|
714 |
+
{helpb marker_label_options:mlabel()},
|
715 |
+
{helpb marker_label_options:mlabvposition()}, and
|
716 |
+
{helpb addplot_option:addplot()} (see
|
717 |
+
{help coefplot##tempvar:Accessing internal temporary variables}
|
718 |
+
below). In matrix mode (see
|
719 |
+
{help coefplot##matrix:{it:Plotting results from matrices}} below), you may
|
720 |
+
also specify {cmd:aux(}# [# ...]{cmd:)} to read the from corresponding
|
721 |
+
rows (or column) of the main matrix.
|
722 |
+
|
723 |
+
{dlgtab:Plot options}
|
724 |
+
|
725 |
+
{marker label}{...}
|
726 |
+
{phang}
|
727 |
+
{cmd:label(}{it:string}{cmd:)} provides a label for the plot to be used
|
728 |
+
in the legend. Use double quotes to create multiline labels. For example,
|
729 |
+
{cmd:label("This is a" "long label")} would create a two-line label. For
|
730 |
+
text effects (bold, italics, greek letters, etc.) use SMCL tags as
|
731 |
+
described in {it:{help graph_text}}.
|
732 |
+
|
733 |
+
{marker key}{...}
|
734 |
+
{phang}
|
735 |
+
{cmd:key}[{cmd:(ci} [{cmd:#}]{cmd:)}] determines the key symbol
|
736 |
+
to be used for the plot in the legend. {cmd:key} without argument uses
|
737 |
+
the plot's marker symbol; this is the default. {cmd:key(ci)} determines
|
738 |
+
the key symbol from the (first) confidence interval. {cmd:key(ci #)}
|
739 |
+
determines the key symbol from the #th confidence interval; this is only
|
740 |
+
useful if multiple confidence intervals are included in the plot.
|
741 |
+
|
742 |
+
{marker nokey}{...}
|
743 |
+
{phang}
|
744 |
+
{cmd:nokey} prevents including the plot in the legend.
|
745 |
+
|
746 |
+
{marker pstyle}{...}
|
747 |
+
{phang}{cmd:pstyle(}{it:pstyle}{cmd:)} sets the overall style of the
|
748 |
+
plot; see help {it:{help pstyle}}. {cmd:pstyle()} affects both,
|
749 |
+
coefficient markers and confidence spikes. To use a different plot style
|
750 |
+
for confidence spikes, add {cmd:pstyle()} within
|
751 |
+
{helpb coefplot##ciopts:ciopts()}.
|
752 |
+
|
753 |
+
{marker axis}{...}
|
754 |
+
{phang}{cmd:axis(}{it:#}{cmd:)} specifies the scale axis to be used for the
|
755 |
+
plot, where {cmd:1} {ul:<} {it:#} {ul:<} {cmd:9}. The default is to place
|
756 |
+
all plots on the same scale axis.
|
757 |
+
|
758 |
+
{marker offset}{...}
|
759 |
+
{phang}
|
760 |
+
{cmd:offset(}{it:#}{cmd:)} specifies a custom offset for the plot
|
761 |
+
positions. The default is to create automatic offsets to prevent
|
762 |
+
overlap of confidence spikes as soon as there are
|
763 |
+
multiple plots. The spacing between coefficients is one unit, so
|
764 |
+
# should usually be within -0.5 and 0.5.
|
765 |
+
|
766 |
+
{marker ifopt}{...}
|
767 |
+
{phang}
|
768 |
+
{cmd:if(}{it:exp}{cmd:)} restricts the contents of the plot to coefficients
|
769 |
+
satisfying {it:exp}. The option is useful when you want to select
|
770 |
+
coefficients, e.g., based on their values, plot positions, or confidence
|
771 |
+
limits. Within {it:exp} refer to internal temporary variables as explained
|
772 |
+
in {help coefplot##tempvar:Accessing internal temporary variables} below.
|
773 |
+
For example, to include positive coefficients only, you could type
|
774 |
+
{cmd:if(@b>=0)}. Note that {cmd:if()} does not affect the rendition of the
|
775 |
+
categorical axis (unless {helpb coefplot##at:at} is specified). That is, a
|
776 |
+
complete categorical axis is created including labels for all collected
|
777 |
+
coefficients, even for the ones that have been removed from the plot by
|
778 |
+
{cmd:if()}.
|
779 |
+
|
780 |
+
{marker weight}{...}
|
781 |
+
{phang}
|
782 |
+
{cmd:weight(}{it:exp}{cmd:)} scales the size of the markers according to
|
783 |
+
the size of the specified weights (see
|
784 |
+
{help scatter##remarks14:Weighted markers} in help {helpb scatter}). Within
|
785 |
+
{it:exp} refer to internal temporary variables as explained in
|
786 |
+
{help coefplot##tempvar:Accessing internal temporary variables} below. For
|
787 |
+
example, to scale markers according to the inverse of standard errors, you
|
788 |
+
could type {cmd:weight(1/@se)}. {cmd:weight()} has no effect if marker
|
789 |
+
labels are specified.
|
790 |
+
|
791 |
+
{phang}
|
792 |
+
{it:marker_options} change the look of the coefficient markers (color,
|
793 |
+
size, etc.); see help {it:{help marker_options}}.
|
794 |
+
|
795 |
+
{marker mlabel}{...}
|
796 |
+
{phang}
|
797 |
+
{cmd:mlabel} adds point estimates as marker labels. Use global option
|
798 |
+
{helpb coefplot##format:format()} to set the display format. For adding
|
799 |
+
custom labels to specific markers see model option
|
800 |
+
{helpb coefplot##mlabels:mlabels()} above. Not all of Stata's plot types
|
801 |
+
support marker labels. For example, if you use
|
802 |
+
{helpb coefplot##recast:recast(bar)} to change the plot type to
|
803 |
+
{helpb twoway_bar:bar}, no marker labels will be displayed.
|
804 |
+
|
805 |
+
{phang}
|
806 |
+
{it:marker_label_options} change the look and
|
807 |
+
position of marker labels: see help {it:{help marker_label_options}}.
|
808 |
+
|
809 |
+
{marker recast}{...}
|
810 |
+
{phang}
|
811 |
+
{cmd:recast(}{it:plottype}{cmd:)} plots the coefficients using
|
812 |
+
{it:plottype}; supported plot types are
|
813 |
+
{helpb scatter},
|
814 |
+
{helpb line},
|
815 |
+
{helpb twoway_connected:connected},
|
816 |
+
{helpb twoway_area:area},
|
817 |
+
{helpb twoway_bar:bar},
|
818 |
+
{helpb twoway_spike:spike},
|
819 |
+
{helpb twoway_dropline:dropline}, and
|
820 |
+
{helpb twoway_dot:dot}. The default {it:plottype} is {helpb scatter}. The
|
821 |
+
chosen plot type affects the available plot options. For example, if
|
822 |
+
the plot type is {helpb twoway_bar:bar} then {it:{help barlook_options}}
|
823 |
+
will be available. See the plot type's help file for details.
|
824 |
+
|
825 |
+
{marker cionly}{...}
|
826 |
+
{phang}
|
827 |
+
{cmd:cionly} causes markers for point estimates to be suppressed.
|
828 |
+
|
829 |
+
{marker citop}{...}
|
830 |
+
{phang}
|
831 |
+
{cmd:citop} specifies that confidence intervals be drawn in front of
|
832 |
+
the markers for point estimates; the default is to draw confidence intervals
|
833 |
+
behind the markers.
|
834 |
+
|
835 |
+
{marker ciopts}{...}
|
836 |
+
{phang}
|
837 |
+
{cmd:ciopts(}{it:options}{cmd:)} affect the rendition of confidence
|
838 |
+
intervals. {it:options} are:
|
839 |
+
|
840 |
+
{p2colset 13 31 33 2}{...}
|
841 |
+
{p2col:{it:{help line_options}}}change look of spikes
|
842 |
+
{p_end}
|
843 |
+
{p2col:{cmd:recast(}{it:plottype}{cmd:)}}plot the confidence intervals using
|
844 |
+
{it:plottype}
|
845 |
+
{p_end}
|
846 |
+
{p2colreset}{...}
|
847 |
+
|
848 |
+
{pmore}
|
849 |
+
Supported plot types are
|
850 |
+
{helpb twoway_rarea:rarea},
|
851 |
+
{helpb twoway_rbar:rbar},
|
852 |
+
{helpb twoway_rspike:rspike},
|
853 |
+
{helpb twoway_rcap:rcap},
|
854 |
+
{helpb twoway_rcapsym:rcapsym},
|
855 |
+
{helpb twoway_rscatter:rscatter},
|
856 |
+
{helpb twoway_rline:rline},
|
857 |
+
{helpb twoway_rconnected:rconnected},
|
858 |
+
{helpb twoway_pcspike:pcspike},
|
859 |
+
{helpb twoway_pcspike:pccapsym},
|
860 |
+
{helpb twoway_pcarrow:pcarrow} (or {cmd:pcrarrow} for the reverse),
|
861 |
+
{helpb twoway_pcbarrow:pcbarrow}, and
|
862 |
+
{helpb twoway_pcscatter:pcscatter}. The default {it:plottype} is
|
863 |
+
{helpb twoway_rspike:rspike}. The chosen plot type affects the available
|
864 |
+
options within {cmd:ciopts()}. For example, if the plot type is
|
865 |
+
{helpb twoway_rbar:rbar} then {it:{help barlook_options}} will be
|
866 |
+
available. See the plot type's help file for details.
|
867 |
+
|
868 |
+
{pmore}
|
869 |
+
If multiple confidence intervals are requested, then
|
870 |
+
{it:{help stylelists}} may be specified in the options within
|
871 |
+
{cmd:ciopts()}. For example, {cmd:recast(rspike rcap ..)} would use
|
872 |
+
{helpb twoway_rspike:rspike} for the first confidence interval and
|
873 |
+
{helpb twoway_rcap:rcap} for the remaining confidence intervals;
|
874 |
+
{cmd:lwidth(thin medium thick)} would use thin lines for the first
|
875 |
+
confidence interval, medium width lines for the second, and thick lines
|
876 |
+
for the third.
|
877 |
+
|
878 |
+
{marker cismooth}{...}
|
879 |
+
{phang}
|
880 |
+
{cmd:cismooth}[{cmd:(}{it:options}{cmd:)}] adds smoothed confidence
|
881 |
+
intervals. {it:options} are:
|
882 |
+
|
883 |
+
{p2colset 13 33 35 2}{...}
|
884 |
+
{p2col:{cmd:n(}{it:n}{cmd:)}}number of (equally spaced) confidence levels;
|
885 |
+
default is {cmd:n(50)}; levels are placed in steps of 100/{it:n} from 100/2{it:n} to
|
886 |
+
100-100/2{it:n} (e.g., 1, 3, 5, ..., 99 for {it:n}=50)
|
887 |
+
{p_end}
|
888 |
+
{p2col:{cmdab:lw:idth(}{it:min max}{cmd:)}}set range of
|
889 |
+
(relative) line widths; the default is {cmd:range(2 15)}
|
890 |
+
({it:max} is exact only for {it:n}=50)
|
891 |
+
{p_end}
|
892 |
+
{p2col:{cmdab:i:ntensity(}{it:min max}{cmd:)}}set range of
|
893 |
+
color intensities, as percentages; the default is {cmd:intensity(}{it:min} {cmd:100)}
|
894 |
+
where {it:min} is determined as 4/(ceil({it:n}/2)+3)*100 (about 14 for n=50)
|
895 |
+
{p_end}
|
896 |
+
{p2col:{cmdab:c:olor(}{help colorstyle:{it:color}}{cmd:)}}set the color (without
|
897 |
+
intensity multiplier); the default color is determined by the graph scheme
|
898 |
+
{p_end}
|
899 |
+
{p2col:{cmdab:psty:le(}{help pstyle:{it:pstyle}}{cmd:)}}set the overall style;
|
900 |
+
this mainly affects the color
|
901 |
+
{p_end}
|
902 |
+
{p2colreset}{...}
|
903 |
+
|
904 |
+
{pmore}
|
905 |
+
The confidence intervals produced by {cmd:cismooth} are placed behind
|
906 |
+
confidence intervals requested in {helpb coefplot##levels:levels()} and
|
907 |
+
{helpb coefplot##ci:ci()}. {helpb coefplot##ciopts:ciopts()} do not
|
908 |
+
apply to them.
|
909 |
+
|
910 |
+
{dlgtab:Subgraph options}
|
911 |
+
|
912 |
+
{marker bylabel}{...}
|
913 |
+
{phang}
|
914 |
+
{cmd:bylabel(}{it:string}{cmd:)} provides a label for the subgraph. Use
|
915 |
+
double quotes to create multiline labels. For example,
|
916 |
+
{cmd:bylabel("This is a" "long label")} would create a two-line label. For
|
917 |
+
text effects (bold, italics, greek letters, etc.) use SMCL tags as
|
918 |
+
described in {it:{help graph_text}}.
|
919 |
+
|
920 |
+
{pmore}
|
921 |
+
Subgraphs are implemented in terms of {helpb graph}'s {cmd:by()} option; see
|
922 |
+
{helpb coefplot##byopts:byopts()} below for options on how to combine and
|
923 |
+
render the subgraphs.
|
924 |
+
|
925 |
+
{dlgtab:Global options}
|
926 |
+
|
927 |
+
{marker horizontal}{...}
|
928 |
+
{phang}
|
929 |
+
{cmd:horizontal} places coefficient values on the x axis. This is the
|
930 |
+
default unless {helpb coefplot##at:at} is specified.
|
931 |
+
|
932 |
+
{marker vertical}{...}
|
933 |
+
{phang}
|
934 |
+
{cmd:vertical} places coefficient values on the y axis. This is the
|
935 |
+
default if {helpb coefplot##at:at} is specified.
|
936 |
+
|
937 |
+
{marker eqstrict}{...}
|
938 |
+
{phang}
|
939 |
+
{cmd:eqstrict} causes equation names to be taken into account (i.e. match coefficients by
|
940 |
+
equation names and plot equation labels) even if there is only one equation per model.
|
941 |
+
|
942 |
+
{marker order}{...}
|
943 |
+
{phang}
|
944 |
+
{cmd:order(}{it:coeflist}{cmd:)} specifies the order of coefficients
|
945 |
+
(not allowed with {helpb coefplot##at:at}). The default is to use
|
946 |
+
the order as found in the input models (and place {cmd:_cons} last, within
|
947 |
+
equations). {it:coeflist} is a
|
948 |
+
space-separated list of elements such as:
|
949 |
+
|
950 |
+
{p2colset 13 25 27 2}{...}
|
951 |
+
{p2col:{cmd:.}}insert a gap
|
952 |
+
{p_end}
|
953 |
+
{p2col:{it:eq}{cmd::.}}insert a gap within equation {it:eq}
|
954 |
+
{p_end}
|
955 |
+
{p2col:{it:coef}}coefficient {it:coef}
|
956 |
+
{p_end}
|
957 |
+
{p2col:{it:eq}{cmd::}}all coefficients from equation {it:eq}, in their current order
|
958 |
+
{p_end}
|
959 |
+
{p2col:{it:eq}{cmd::}{it:coef}}coefficient {it:coef} from equation {it:eq}
|
960 |
+
{p_end}
|
961 |
+
{p2colreset}{...}
|
962 |
+
|
963 |
+
{pmore}
|
964 |
+
where {it:coef} may contain "{cmd:*}" (any string) and "{cmd:?}"
|
965 |
+
(any nonzero character) wildcards.
|
966 |
+
|
967 |
+
{pmore}
|
968 |
+
If no equations are specified, then the requested order of coefficients
|
969 |
+
is repeated within each equation (keeping the existing order of
|
970 |
+
equations). Otherwise, the requested order is applied across equations.
|
971 |
+
Note that in the later case the first element in {cmd:order()} must be an
|
972 |
+
equation name. {it:eq} is applied to all subsequent elements until a
|
973 |
+
new {it:eq} is specified. For example,
|
974 |
+
{cmd:order(5:weight mpg * 4:turn *)} would yield the following order:
|
975 |
+
"{cmd:weight}" from equation "{cmd:5}", "{cmd:mpg}" from equation "{cmd:5}",
|
976 |
+
remaining coefficients from equation "{cmd:5}",
|
977 |
+
"{cmd:turn}" from equation "{cmd:4}", remaining coefficients from equation
|
978 |
+
"{cmd:4}", remaining equations if any.
|
979 |
+
|
980 |
+
{marker orderby}{...}
|
981 |
+
{phang}
|
982 |
+
{cmd:orderby(}[{it:subgraph}{cmd::}][{it:plot}]{cmd:)} orders the
|
983 |
+
coefficients by a specific model. By default, the coefficients are ordered
|
984 |
+
according to how they are provided to {cmd:coefplot}, with earlier plots
|
985 |
+
and subgraphs taking precedence over later ones (and placing {cmd:_cons}
|
986 |
+
last). This means that coefficients that only appear in later models will
|
987 |
+
be placed after the coefficients that appear in earlier models. Specify the
|
988 |
+
{cmd:orderby()} option if you want to change the default behavior and
|
989 |
+
arrange the coefficients according to their order in a specific model
|
990 |
+
(and, within each equation, place the other coefficients after these coefficients, but
|
991 |
+
before {cmd:_cons}). Arguments {it:subgraph} and {it:plot} select the relevant
|
992 |
+
model. For example, {cmd:orderby(2:3)} will order coefficients according to
|
993 |
+
the model that is displayed in the third plot of the second subgraph. If one
|
994 |
+
of the arguments is omitted, it defaults to one. Hence, {cmd:orderby(3)} will
|
995 |
+
order the coefficients according to the model displayed in the third plot
|
996 |
+
of the first subgraph; {cmd:orderby(2:)} will use the model displayed in the first
|
997 |
+
plot of the second subgraph. {cmd:orderby()} will do nothing if a specified subgraph or
|
998 |
+
plot does not exist. Furthermore, note that the {it:subgraph} argument
|
999 |
+
is not allowed if the {helpb coefplot##norecycle:norecycle} option has been
|
1000 |
+
specified; plots are numbered uniquely across subgraphs in this case.
|
1001 |
+
|
1002 |
+
{marker sort}{...}
|
1003 |
+
{phang}
|
1004 |
+
{cmd:sort}[{cmd:(}{it:spec}{cmd:)}] sorts the coefficients by size. {it:spec} is
|
1005 |
+
|
1006 |
+
[{it:subgraph}{cmd::}][{it:plot}] [, {cmdab:d:escending} {cmd:by(}{it:stat}{cmd:)} ]
|
1007 |
+
|
1008 |
+
{pmore}
|
1009 |
+
where {it:subgraph} and {it:plot}, being equal to {cmd:.} or a positive
|
1010 |
+
integer, identify the subgraph and plot to be used
|
1011 |
+
to establish the sort order. For example, to sort based on all values in
|
1012 |
+
the second subgraph (possibly including multiple plots), type
|
1013 |
+
{cmd:sort(2:)} or {cmd:sort(2:.)}; to sort based on all values in the third
|
1014 |
+
plot (possibly spanning multiple subgraphs), type {cmd:sort(3)} or
|
1015 |
+
{cmd:sort(.:3)}; to sort based on the values of the third plot in the
|
1016 |
+
second subgraph, type {cmd:sort(2:3)}. Specifying {cmd:sort} without
|
1017 |
+
argument is equivalent to {cmd:sort(.:.)}, that is, to sort based on the
|
1018 |
+
values in all available subgraphs and plots. If you specify a subgraph or
|
1019 |
+
plot that does not exist, {cmd:sort()} will do nothing. Furthermore, if the
|
1020 |
+
{helpb coefplot##norecycle:norecycle} option is specified, the {it:subgraph}
|
1021 |
+
argument can be omitted as the plots will be uniquely numbered across
|
1022 |
+
subgraphs.
|
1023 |
+
|
1024 |
+
{pmore}
|
1025 |
+
By default, the coefficients are sorted in ascending order of the values of
|
1026 |
+
the point estimates. Specify suboption {cmd:descending} to use a
|
1027 |
+
descending sort order. Furthermore, use {cmd:by(}{it:stat}{cmd:)} to change
|
1028 |
+
the relevant statistic, where {it:stat} may be:
|
1029 |
+
|
1030 |
+
{p2colset 13 25 27 2}{...}
|
1031 |
+
{p2col:{cmd:b}}sort by point estimate (the default){p_end}
|
1032 |
+
{p2col:{cmd:v} (or {cmd:se})}sort by variance (or standard error){p_end}
|
1033 |
+
{p2col:{cmd:t}}sort by t (or z) statistic{p_end}
|
1034 |
+
{p2col:{cmd:tabs}}sort by absolute t (or z) statistic{p_end}
|
1035 |
+
{p2col:{cmd:p}}sort by p-value{p_end}
|
1036 |
+
{p2col:{cmd:df}}sort by degrees of freedom{p_end}
|
1037 |
+
{p2col:{cmd:ll} [#]}sort by (#th) lower confidence limit; # defaults to 1{p_end}
|
1038 |
+
{p2col:{cmd:ul} [#]}sort by (#th) upper confidence limit; # defaults to 1{p_end}
|
1039 |
+
{p2col:{cmd:aux} [#]}sort by (#th) auxiliary variable (see the
|
1040 |
+
{helpb coefplot##aux:aux()} option); # defaults to 1{p_end}
|
1041 |
+
{p2colreset}{...}
|
1042 |
+
|
1043 |
+
{pmore}
|
1044 |
+
In case of multiple equations, coefficients will be sorted separately
|
1045 |
+
within each equation, keeping the original order of equations. Use the
|
1046 |
+
{helpb coefplot##order:order()} option the change the order of the equations.
|
1047 |
+
|
1048 |
+
{marker relocate}{...}
|
1049 |
+
{phang}
|
1050 |
+
{cmd:relocate(}{it:spec}{cmd:)} assigns specific positions to the
|
1051 |
+
coefficients on the category axis. {it:spec} is:
|
1052 |
+
|
1053 |
+
[{it:eq}{cmd::}]{it:coef} {cmd:=} # [[{it:eq}{cmd::}]{it:coef} {cmd:=} # ...]
|
1054 |
+
|
1055 |
+
{pmore}
|
1056 |
+
where {it:eq} and {it:coef} may contain "{cmd:*}" (any string) and
|
1057 |
+
"{cmd:?}" (any nonzero character) wildcards. If {helpb coefplot##bycoefs:bycoefs} is
|
1058 |
+
specified, use numbers (1, 2, ...) instead of {it:eq} and {it:coef}
|
1059 |
+
to address the elements on the categorical axis.
|
1060 |
+
|
1061 |
+
{pmore}The default for {cmd:coefplot} is to place coefficients
|
1062 |
+
at integer values 1, 2, 3, ... (from top to bottom in horizontal mode,
|
1063 |
+
from left to right in vertical mode). The {cmd:relocate()} option gives
|
1064 |
+
you the possibility to specify alternative values. If, for example, you
|
1065 |
+
want to place coefficient {cmd:mpg} at value 2.5 on the category axis, you
|
1066 |
+
could type {cmd:relocate(mpg = 2.5)}. If you only want to change the
|
1067 |
+
order of coefficients and are fine with integer positions, then use the
|
1068 |
+
{helpb coefplot##order:order()} option. Note that the specified positions
|
1069 |
+
are assigned before inserting gaps between equations, headings, and
|
1070 |
+
groups (see {helpb coefplot##eqlabels:eqlabels()},
|
1071 |
+
{helpb coefplot##headings:headings()}, and
|
1072 |
+
{helpb coefplot##groups:groups()}). Hence, the final plot positions might
|
1073 |
+
deviate from the specified positions if there are equation labels, headings,
|
1074 |
+
or group labels.
|
1075 |
+
|
1076 |
+
{marker bycoefs}{...}
|
1077 |
+
{phang}
|
1078 |
+
{cmd:bycoefs} flips subgraphs and coefficients (not allowed with
|
1079 |
+
{helpb coefplot##at:at}). If {cmd:bycoefs} is specified, a
|
1080 |
+
separate subgraph is produced for each coefficient. In this
|
1081 |
+
case, use integer numbers (1, 2, ...) instead of coefficient names
|
1082 |
+
to address the elements on the categorical axis within options
|
1083 |
+
{helpb coefplot##relocate:relocate()},
|
1084 |
+
{helpb coefplot##headings:headings()}, and
|
1085 |
+
{helpb coefplot##groups:groups()}.
|
1086 |
+
|
1087 |
+
{marker norecycle}{...}
|
1088 |
+
{phang}
|
1089 |
+
{cmd:norecycle} increments plot styles across subgraphs. The default is
|
1090 |
+
to start over with each new subgraph.
|
1091 |
+
|
1092 |
+
{marker nooffsets}{...}
|
1093 |
+
{phang}
|
1094 |
+
{cmd:nooffsets} suppresses automatic offsets for plot positions.
|
1095 |
+
|
1096 |
+
{marker format}{...}
|
1097 |
+
{phang}
|
1098 |
+
{cmd:format(}{it:format}{cmd:)} sets the display format for
|
1099 |
+
coefficients. This affects the rendition of the axis and marker
|
1100 |
+
labels. {it:format} may be a numeric format or a date format
|
1101 |
+
(see help {helpb format}).
|
1102 |
+
|
1103 |
+
{marker pnum}{...}
|
1104 |
+
{phang}
|
1105 |
+
{cmd:p{it:#}(}{help coefplot##plotopts:{it:plotopts}}{cmd:)} specifies
|
1106 |
+
options for the {it:#}th plot. For example, type {cmd:p2(nokey)} to exclude
|
1107 |
+
plot 2 from the legend (see {helpb coefplot##nokey:nokey}). Use the {cmd:p#()}
|
1108 |
+
options as an alternative to specifying options directly within a plot; in
|
1109 |
+
case of conflict, options specified within a plot take precedence
|
1110 |
+
over options specified via {cmd:p#()}.
|
1111 |
+
|
1112 |
+
{marker nolabels}{...}
|
1113 |
+
{phang}
|
1114 |
+
{cmd:nolabels} causes coefficient names to be used as labels instead of
|
1115 |
+
variable labels or value labels.
|
1116 |
+
|
1117 |
+
{marker coeflabels}{...}
|
1118 |
+
{phang}
|
1119 |
+
{cmd:coeflabels(}{it:spec}{cmd:)} specifies custom labels for
|
1120 |
+
coefficients (not allowed with {helpb coefplot##at:at}). {it:spec} is
|
1121 |
+
|
1122 |
+
{p 12 14 2}
|
1123 |
+
[{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} [{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} ...]]
|
1124 |
+
[{cmd:,} {cmdab:t:runcate(}#{cmd:)} {cmdab:w:rap(}#{cmd:)} {cmdab:nob:reak}
|
1125 |
+
{cmdab:i:nteraction(}{it:string}{cmd:)}
|
1126 |
+
{it:{help axis_label_options:suboptions}}]
|
1127 |
+
|
1128 |
+
{pmore}
|
1129 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()}. Enclose
|
1130 |
+
{it:label} in double quotes
|
1131 |
+
if it contains spaces, e.g. {bind:{cmd:coeflabels(foreign = "Car Type")}}.
|
1132 |
+
Enclose {it:label} in compound double quotes to create a multiline
|
1133 |
+
label, e.g. {bind:{cmd:coeflabels(foreign = `""This is a" "long label""')}};
|
1134 |
+
alternatively, apply the {cmd:wrap()} option. For text effects
|
1135 |
+
(bold, italics, greek letters, etc.) use SMCL tags as described in
|
1136 |
+
{it:{help graph_text}}.
|
1137 |
+
|
1138 |
+
{pmore}
|
1139 |
+
Option {cmd:truncate(}#{cmd:)} truncates coefficient labels to
|
1140 |
+
a maximum length of # characters. Option {cmd:wrap(}#{cmd:)} divides
|
1141 |
+
coefficient labels into multiple lines, where each line has a maximum
|
1142 |
+
length of # characters. {cmd:truncate()} and {cmd:wrap()} operate on
|
1143 |
+
words. That is, they try to fill to the maximum length without breaking
|
1144 |
+
in the middle of a word. However, if a word is longer than # characters,
|
1145 |
+
it will be split or truncated. Specify {cmd:nobreak} to prevent
|
1146 |
+
{cmd:truncate()} and {cmd:wrap()} from splitting or truncating words
|
1147 |
+
that are longer than # characters. If {cmd:truncate()} and {cmd:wrap()}
|
1148 |
+
are both specified, {cmd:truncate()} is applied first.
|
1149 |
+
{cmdab:interaction()} specifies the string to be used as
|
1150 |
+
delimiter in labels for interaction terms; the default is
|
1151 |
+
{cmd:interaction(" # ")}. {it:suboptions} are axis label suboptions as
|
1152 |
+
described in {it:{help axis_label_options}}.
|
1153 |
+
|
1154 |
+
{pmore}
|
1155 |
+
Note: Labels containing multiple lines are left unchanged by {cmd:truncate()}
|
1156 |
+
and {cmd:wrap()}. Therefore, if you don't like how {cmd:wrap()} breaks a
|
1157 |
+
specific label, you can provide a custom variant of it in {cmd:coeflabels()}
|
1158 |
+
while still using {cmd:wrap()} for the other labels. {cmd:truncate()}
|
1159 |
+
and {cmd:wrap()} may fail to process a label if it contains compound
|
1160 |
+
double quotes; the label will be left unchanged in this case.
|
1161 |
+
|
1162 |
+
{marker noeqlabels}{...}
|
1163 |
+
{phang}
|
1164 |
+
{cmd:noeqlabels} suppresses equation labels.
|
1165 |
+
|
1166 |
+
{marker eqlabels}{...}
|
1167 |
+
{phang}
|
1168 |
+
{cmd:eqlabels(}{it:spec}{cmd:)} specifies custom labels for equations, one after
|
1169 |
+
the other (not allowed with {helpb coefplot##at:at}). {it:spec} is:
|
1170 |
+
|
1171 |
+
{p 12 14 2}
|
1172 |
+
[{cmd:"}{it:label}{cmd:"} [{cmd:"}{it:label}{cmd:"} ...]] [{cmd:,}
|
1173 |
+
{cmdab:lab:els}[{cmd:(}{it:string}{cmd:)}]
|
1174 |
+
[{cmd:{ul:no}}]{cmdab:g:ap}[{cmd:(}#{cmd:)}] {cmdab:ashead:ings}
|
1175 |
+
{cmdab:off:set(}#{cmd:)} {cmdab:t:runcate(}#{cmd:)} {cmdab:w:rap(}#{cmd:)}
|
1176 |
+
{cmdab:nob:reak} {it:{help axis_label_options:suboptions}} ]
|
1177 |
+
|
1178 |
+
{pmore}
|
1179 |
+
Enclose labels in double quotes if they contain spaces,
|
1180 |
+
e.g. {bind:{cmd:eqlabels("EQ one" "EQ two")}}. Enclose labels in compound
|
1181 |
+
double quotes to create multiline labels,
|
1182 |
+
e.g. {bind:{cmd:eqlabels(`""This is a" "long label""')}}. Alternatively,
|
1183 |
+
apply the {cmd:wrap()} option. For text effects
|
1184 |
+
(bold, italics, greek letters, etc.) use SMCL tags as described in
|
1185 |
+
{it:{help graph_text}}.
|
1186 |
+
|
1187 |
+
{pmore}
|
1188 |
+
Option {cmd:label} causes the equation names to be treated as
|
1189 |
+
variable names; {cmd:coefplot} will then use the corresponding variable labels
|
1190 |
+
(and, depending on context, value labels) to label the equations. Specify
|
1191 |
+
{cmd:label(}{it:string}{cmd:)} to set the string to be used as
|
1192 |
+
delimiter in labels for interaction terms; typing {cmd:label} without argument
|
1193 |
+
is equivalent to {cmd:label(" # ")}. {cmd:gap()} specifies the size of the
|
1194 |
+
gap between equations. The
|
1195 |
+
default is {cmd:gap(1)}. {cmd:nogap} suppresses the gap between
|
1196 |
+
equations. {cmdab:asheadings} treats equation labels as headings;
|
1197 |
+
see {helpb coefplot##headings:headings()}. {cmd:offset()}, only
|
1198 |
+
allowed with {cmd:asheadings}, offsets the labels. {cmd:truncate()},
|
1199 |
+
{cmd:wrap()}, {cmd:nobreak}, and {it:suboptions} are as above for
|
1200 |
+
{helpb coefplot##coeflabels:coeflabels()}.
|
1201 |
+
|
1202 |
+
{marker headings}{...}
|
1203 |
+
{phang}
|
1204 |
+
{cmd:headings(}{it:spec}{cmd:)} adds headings between
|
1205 |
+
coefficients (not allowed with {helpb coefplot##at:at}). {it:spec} is:
|
1206 |
+
|
1207 |
+
{p 12 14 2}
|
1208 |
+
{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} [{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} ...]
|
1209 |
+
[{cmd:,} [{cmd:{ul:no}}]{cmdab:g:ap}[{cmd:(}#{cmd:)}]
|
1210 |
+
{cmdab:off:set(}#{cmd:)} {cmdab:t:runcate(}#{cmd:)}
|
1211 |
+
{cmdab:w:rap(}#{cmd:)} {cmdab:nob:reak}
|
1212 |
+
{it:{help axis_label_options:suboptions}} ]
|
1213 |
+
|
1214 |
+
{pmore}
|
1215 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()}. If
|
1216 |
+
{helpb coefplot##bycoefs:bycoefs} is specified, use numbers 1, 2,
|
1217 |
+
... instead of {it:coeflist} to address the elements on the categorical
|
1218 |
+
axis. Enclose {it:label} in double quotes if it contains
|
1219 |
+
spaces. For example, {bind:{cmd:headings(0.foreign = "Car Type")}} will
|
1220 |
+
print the heading "{cmd:Car Type}" before coefficient "{cmd:0.foreign}".
|
1221 |
+
Enclose {it:label} in compound double quotes to create a multiline
|
1222 |
+
label, e.g. {bind:{cmd:headings(foreign = `""This is a" "long heading""')}}.
|
1223 |
+
Alternatively, apply the {cmd:wrap()} option. For text effects (bold,
|
1224 |
+
italics, greek letters, etc.) use SMCL tags as
|
1225 |
+
described in {it:{help graph_text}}.
|
1226 |
+
|
1227 |
+
{pmore}
|
1228 |
+
{cmd:gap()} and {cmdab:offset()} are as above for
|
1229 |
+
{helpb coefplot##eqlabels:eqlabels()}. {cmd:truncate()}, {cmd:wrap()},
|
1230 |
+
{cmd:nobreak}, and {it:suboptions} are as above for
|
1231 |
+
{helpb coefplot##coeflabels:coeflabels()}.
|
1232 |
+
|
1233 |
+
{marker groups}{...}
|
1234 |
+
{phang}
|
1235 |
+
{cmd:groups(}{it:spec}{cmd:)} adds labels for groups of
|
1236 |
+
coefficients (not allowed with {helpb coefplot##at:at}). The specified
|
1237 |
+
label will be printed beside (or, in vertical mode, below) the identified
|
1238 |
+
group of coefficients. {it:spec} is:
|
1239 |
+
|
1240 |
+
{p 12 14 2}
|
1241 |
+
{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} [{it:coeflist} {cmd:=} {cmd:"}{it:label}{cmd:"} ...]
|
1242 |
+
[{cmd:,} [{cmd:{ul:no}}]{cmdab:g:ap}[{cmd:(}#{cmd:)}]
|
1243 |
+
{cmdab:t:runcate(}#{cmd:)} {cmdab:w:rap(}#{cmd:)}
|
1244 |
+
{cmdab:nob:reak} {it:{help axis_label_options:suboptions}} ]
|
1245 |
+
|
1246 |
+
{pmore}
|
1247 |
+
with {it:coeflist} as above for {helpb coefplot##keep:keep()}. If
|
1248 |
+
{helpb coefplot##bycoefs:bycoefs} is specified, use numbers 1, 2,
|
1249 |
+
... instead of {it:coeflist} to address the elements on the categorical
|
1250 |
+
axis. Enclose {it:label} in double quotes if
|
1251 |
+
it contains spaces. Enclose {it:label} in compound double quotes to create
|
1252 |
+
a multiline label. Alternatively, apply the {cmd:wrap()} option. For text
|
1253 |
+
effects (bold, italics, greek letters, etc.) use SMCL tags as described in
|
1254 |
+
{it:{help graph_text}}.
|
1255 |
+
|
1256 |
+
{pmore}
|
1257 |
+
{cmd:gap()} is as above for
|
1258 |
+
{helpb coefplot##eqlabels:eqlabels()}. {cmd:truncate()}, {cmd:wrap()},
|
1259 |
+
{cmd:nobreak}, and {it:suboptions} are as above for
|
1260 |
+
{helpb coefplot##coeflabels:coeflabels()}.
|
1261 |
+
|
1262 |
+
{marker plotlabels}{...}
|
1263 |
+
{phang}
|
1264 |
+
{cmd:plotlabels(}{it:spec}{cmd:)} specifies labels for the plots to be
|
1265 |
+
used in the legend. Labels specified via {cmd:plotlabels()}
|
1266 |
+
take precedence over labels specified in the
|
1267 |
+
{helpb coefplot##label:label()} plot option. {it:spec} is:
|
1268 |
+
|
1269 |
+
{p 12 14 2}
|
1270 |
+
[{cmd:"}{it:label}{cmd:"} [{cmd:"}{it:label}{cmd:"} ...]] [{cmd:,} {cmdab:t:runcate(}#{cmd:)}
|
1271 |
+
{cmdab:w:rap(}#{cmd:)} {cmdab:nob:reak} ]
|
1272 |
+
|
1273 |
+
{pmore}
|
1274 |
+
Enclose labels in double quotes if they contain spaces. Enclose labels in
|
1275 |
+
compound double quotes to create multiline labels. Alternatively,
|
1276 |
+
apply the {cmd:wrap()} option. For text effects
|
1277 |
+
(bold, italics, greek letters, etc.) use SMCL tags as described in
|
1278 |
+
{it:{help graph_text}}. Options {cmd:truncate()}, {cmd:wrap()}, and {cmd:nobreak} are as
|
1279 |
+
above for {helpb coefplot##coeflabels:coeflabels()}.
|
1280 |
+
|
1281 |
+
{marker bylabels}{...}
|
1282 |
+
{phang}
|
1283 |
+
{cmd:bylabels(}{it:spec}{cmd:)} specifies labels for the subgraphs. Labels
|
1284 |
+
specified via {cmd:bylabels()}
|
1285 |
+
take precedence over labels specified in the
|
1286 |
+
{helpb coefplot##bylabel:bylabel()} subgraph option. {it:spec} is:
|
1287 |
+
|
1288 |
+
{p 12 14 2}
|
1289 |
+
[{cmd:"}{it:label}{cmd:"} [{cmd:"}{it:label}{cmd:"} ...]] [{cmd:,} {cmdab:t:runcate(}#{cmd:)}
|
1290 |
+
{cmdab:w:rap(}#{cmd:)} {cmdab:nob:reak} ]
|
1291 |
+
|
1292 |
+
{pmore}
|
1293 |
+
Enclose labels in double quotes if they contain spaces. Enclose labels in
|
1294 |
+
compound double quotes to create multiline labels. Alternatively,
|
1295 |
+
apply the {cmd:wrap()} option. For text effects
|
1296 |
+
(bold, italics, greek letters, etc.) use SMCL tags as described in
|
1297 |
+
{it:{help graph_text}}. Options {cmd:truncate()}, {cmd:wrap()}, and {cmd:nobreak} are as
|
1298 |
+
above for {helpb coefplot##coeflabels:coeflabels()}.
|
1299 |
+
|
1300 |
+
{marker grid}{...}
|
1301 |
+
{phang}
|
1302 |
+
{cmd:grid(}{it:options}{cmd:)} affects the rendition of grid lines on the
|
1303 |
+
category axis (not allowed with {helpb coefplot##at:at}). {it:options} are:
|
1304 |
+
|
1305 |
+
{p 12 14 2}
|
1306 |
+
{ {cmdab:b:etween} | {cmdab:w:ithin} | {cmdab:n:one} } {it:{help axis_label_options:suboptions}}
|
1307 |
+
|
1308 |
+
{pmore}
|
1309 |
+
{cmdab:b:etween} places grid lines between coefficient labels;
|
1310 |
+
{cmdab:w:ithin} places grid lines at the center of coefficient labels;
|
1311 |
+
{cmdab:n:one} suppress grid lines. {it:suboptions} are axis label suboptions
|
1312 |
+
as described in {it:{help axis_label_options}}. In horizontal mode, the
|
1313 |
+
default is {cmd:within} for single plots and {cmd:between} for multiple
|
1314 |
+
plots. In vertical mode, the default is {cmd:none}. Alternatively, use
|
1315 |
+
{helpb axis_label_options:ytick()} and {helpb axis_label_options:xtick()}
|
1316 |
+
to set grid lines.
|
1317 |
+
|
1318 |
+
{marker generate}{...}
|
1319 |
+
{phang}
|
1320 |
+
{cmd:generate}[{cmd:(}{it:prefix}{cmd:)}] generates variables containing
|
1321 |
+
the graph data. The variable names will be prefixed by "{cmd:__}"
|
1322 |
+
or as specified by {it:prefix}.
|
1323 |
+
|
1324 |
+
{marker replace}{...}
|
1325 |
+
{phang}
|
1326 |
+
{cmd:replace} allows {cmd:coefplot} to overwrite existing variables.
|
1327 |
+
|
1328 |
+
{marker addplot}{...}
|
1329 |
+
{phang}
|
1330 |
+
{cmd:addplot(}{it:plot}{cmd:)} adds other plots to the graph. See help
|
1331 |
+
{it:{help addplot_option}}. By default {cmd:addplot()} has access only to
|
1332 |
+
the first {it:r} observations in the dataset, where {it:r} is the number of
|
1333 |
+
observations used by {cmd:coefplot} to store its internal results. If the
|
1334 |
+
graph does not contain multiple subgraphs and
|
1335 |
+
{helpb coefplot##generate:generate()} or {helpb coefplot##nodrop:nodrop} is
|
1336 |
+
specified, {cmd:addplot()} has access to all observations.
|
1337 |
+
|
1338 |
+
{marker nodrop}{...}
|
1339 |
+
{phang}
|
1340 |
+
{cmd:nodrop} causes {cmd:coefplot} to keep all observations when generating
|
1341 |
+
the graph. The default is to eliminate unused observations temporarily
|
1342 |
+
to increase speed. {cmd:nodrop} may be useful in connection with the
|
1343 |
+
{helpb coefplot##addplot:addplot()} option, if the graph does not contain
|
1344 |
+
multiple subgraphs. {cmd:nodrop} has no effect if
|
1345 |
+
{helpb coefplot##generate:generate()} is specified.
|
1346 |
+
{p_end}
|
1347 |
+
|
1348 |
+
{phang}
|
1349 |
+
{it:twoway_options} are general twoway options, other than
|
1350 |
+
{cmd:by()}, as documented in help {it:{help twoway_options}}.
|
1351 |
+
|
1352 |
+
{marker byopts}{...}
|
1353 |
+
{phang}
|
1354 |
+
{cmd:byopts(}{it:byopts}{cmd:)} determines how subgraphs
|
1355 |
+
are combined. {it:byopts} are as described in help {it:{help by_option}}.
|
1356 |
+
|
1357 |
+
|
1358 |
+
{marker examples}{...}
|
1359 |
+
{title:Examples}
|
1360 |
+
|
1361 |
+
. {stata sysuse auto}
|
1362 |
+
. {stata regress price mpg headroom trunk length turn}
|
1363 |
+
. {stata coefplot, drop(_cons) xline(0)}
|
1364 |
+
|
1365 |
+
. {stata regress price mpg headroom trunk length turn if foreign==0}
|
1366 |
+
. {stata estimates store domestic}
|
1367 |
+
. {stata regress price mpg headroom trunk length turn if foreign==1}
|
1368 |
+
. {stata estimates store foreign}
|
1369 |
+
. {stata coefplot domestic foreign, drop(_cons) xline(0)}
|
1370 |
+
|
1371 |
+
. {stata coefplot domestic || foreign, drop(_cons) xline(0)}
|
1372 |
+
|
1373 |
+
. {stata coefplot domestic || foreign, yline(0) bycoefs vertical byopts(yrescale)}
|
1374 |
+
|
1375 |
+
{pstd}
|
1376 |
+
For further examples see the {browse "http://repec.sowi.unibe.ch/stata/coefplot":website},
|
1377 |
+
the {browse "http://www.stata-journal.com/article.html?article=gr0059":Stata Journal article}, or the
|
1378 |
+
{browse "http://ideas.repec.org/p/bss/wpaper/1.html":working paper}.
|
1379 |
+
|
1380 |
+
|
1381 |
+
{marker remarks}{...}
|
1382 |
+
{title:Remarks}
|
1383 |
+
|
1384 |
+
{pstd}
|
1385 |
+
Remarks are presented under the following headings:
|
1386 |
+
|
1387 |
+
{help coefplot##wildcards:Using wildcards in model names}
|
1388 |
+
{help coefplot##place:Placement of options}
|
1389 |
+
{help coefplot##matrix:Plotting results from matrices}
|
1390 |
+
{help coefplot##tempvar:Accessing internal temporary variables}
|
1391 |
+
|
1392 |
+
|
1393 |
+
{marker wildcards}{...}
|
1394 |
+
{title:Using wildcards in model names}
|
1395 |
+
|
1396 |
+
{pstd}
|
1397 |
+
Instead of providing distinct model names to {cmd:coefplot}, you can also
|
1398 |
+
specify a name pattern containing {cmd:*} (any string)
|
1399 |
+
and {cmd:?} (any nonzero character) wildcards. {cmd:coefplot}
|
1400 |
+
will then plot the results from all matching
|
1401 |
+
models. If a name pattern is specified as part of a plot delimited by
|
1402 |
+
parentheses, the results from the matching models will be combined into the
|
1403 |
+
same plot. For example, if models {cmd:est11}, {cmd:est12}, {cmd:est13},
|
1404 |
+
{cmd:est21}, {cmd:est22}, and {cmd:est23} are in
|
1405 |
+
memory, typing
|
1406 |
+
|
1407 |
+
{com}{...}
|
1408 |
+
. coefplot (est1*, {txt:{it:opts1}}) (est2*, {txt:{it:opts2}})
|
1409 |
+
{txt}{...}
|
1410 |
+
|
1411 |
+
{pstd}
|
1412 |
+
is equivalent to
|
1413 |
+
|
1414 |
+
{com}{...}
|
1415 |
+
. coefplot (est11 \ est12 \ est13, {txt:{it:opts1}}) (est21 \ est22 \ est23, {txt:{it:opts2}})
|
1416 |
+
{txt}{...}
|
1417 |
+
|
1418 |
+
{pstd}
|
1419 |
+
Likewise, typing
|
1420 |
+
|
1421 |
+
{com}{...}
|
1422 |
+
. coefplot (est*1, {txt:{it:opts1}} \ est*2, {txt:{it:opts2}} \, {txt:{it:opts3}})
|
1423 |
+
{txt}{...}
|
1424 |
+
|
1425 |
+
{pstd}
|
1426 |
+
is equivalent to
|
1427 |
+
|
1428 |
+
{com}{...}
|
1429 |
+
. coefplot (est11, {txt:{it:opts1}} \ est21, {txt:{it:opts1}} \ est12, {txt:{it:opts2}} \ est22, {txt:{it:opts2}} \, {txt:{it:opts3}})
|
1430 |
+
{txt}{...}
|
1431 |
+
|
1432 |
+
{pstd}
|
1433 |
+
Alternatively, if a name pattern is specified without parentheses,
|
1434 |
+
the matching models are treated as separate plots. For example, typing
|
1435 |
+
|
1436 |
+
{com}{...}
|
1437 |
+
. coefplot est1* || est2*
|
1438 |
+
{txt}{...}
|
1439 |
+
|
1440 |
+
{pstd}
|
1441 |
+
is equivalent to
|
1442 |
+
|
1443 |
+
{com}{...}
|
1444 |
+
. coefplot est11 est12 est13 || est21 est22 est23
|
1445 |
+
{txt}{...}
|
1446 |
+
|
1447 |
+
{pstd}
|
1448 |
+
or
|
1449 |
+
|
1450 |
+
{com}{...}
|
1451 |
+
. coefplot (est11) (est12) (est13) || (est21) (est22) (est23)
|
1452 |
+
{txt}{...}
|
1453 |
+
|
1454 |
+
{pstd}
|
1455 |
+
Use global options {helpb coefplot##pnum:p1()}, {helpb coefplot##pnum:p2()},
|
1456 |
+
etc. to provide specific options to the different plots in this case. For
|
1457 |
+
example, typing
|
1458 |
+
|
1459 |
+
{com}{...}
|
1460 |
+
. coefplot est1*, p1({txt:{it:opts1}}) p2({txt:{it:opts2}}) p3({txt:{it:opts3}})
|
1461 |
+
{txt}{...}
|
1462 |
+
|
1463 |
+
{pstd}
|
1464 |
+
is equivalent to
|
1465 |
+
|
1466 |
+
{com}{...}
|
1467 |
+
. coefplot (est11, {txt:{it:opts1}}) (est12, {txt:{it:opts2}}) (est13, {txt:{it:opts3}})
|
1468 |
+
{txt}{...}
|
1469 |
+
|
1470 |
+
|
1471 |
+
{marker place}{...}
|
1472 |
+
{title:Placement of options}
|
1473 |
+
|
1474 |
+
{pstd}
|
1475 |
+
{cmd:coefplot} has four levels of options:
|
1476 |
+
|
1477 |
+
{phang}(1) {help coefplot##modelopts:{it:modelopts}} are options that apply to a single
|
1478 |
+
model (or matrix). They specify the information to be displayed.
|
1479 |
+
|
1480 |
+
{phang}(2) {help coefplot##plotopts:{it:plotopts}} are options that apply to a single
|
1481 |
+
plot, possibly containing results from multiple models. They affect
|
1482 |
+
the rendition of markers and confidence intervals and provide a label
|
1483 |
+
for the plot.
|
1484 |
+
|
1485 |
+
{phang}(3) {help coefplot##subgropts:{it:subgropts}} are options that
|
1486 |
+
apply to a single subgraph, possibly containing multiple plots.
|
1487 |
+
|
1488 |
+
{phang}(4) {help coefplot##globalopts:{it:globalopts}} are options that apply
|
1489 |
+
to the overall graph.
|
1490 |
+
|
1491 |
+
{pstd}
|
1492 |
+
The levels are nested in the sense that upper level options include all
|
1493 |
+
lower level options. That is,
|
1494 |
+
{help coefplot##globalopts:{it:globalopts}} includes
|
1495 |
+
{help coefplot##subgropts:{it:subgropts}},
|
1496 |
+
{help coefplot##plotopts:{it:plotopts}}, and
|
1497 |
+
{help coefplot##modelopts:{it:modelopts}};
|
1498 |
+
{help coefplot##subgropts:{it:subgropts}} includes
|
1499 |
+
{help coefplot##plotopts:{it:plotopts}}, and
|
1500 |
+
{help coefplot##modelopts:{it:modelopts}};
|
1501 |
+
{help coefplot##plotopts:{it:plotopts}} includes
|
1502 |
+
{help coefplot##modelopts:{it:modelopts}}. However, upper level options
|
1503 |
+
may not be specified at a lower level.
|
1504 |
+
|
1505 |
+
{pstd}
|
1506 |
+
If lower level options are specified at an upper level, they serve as
|
1507 |
+
defaults for all included lower levels elements. For example, if you want
|
1508 |
+
to draw 99% and 95% confidence intervals for all included models,
|
1509 |
+
specify {cmd:levels(99 95)} as global option:
|
1510 |
+
|
1511 |
+
{com}{...}
|
1512 |
+
. coefplot model1 model2 model3, levels(99 95)
|
1513 |
+
{txt}{...}
|
1514 |
+
|
1515 |
+
{pstd}
|
1516 |
+
Options specified with an individual element override the defaults set
|
1517 |
+
by upper level options. For example, if you want to draw 99% and 95%
|
1518 |
+
confidence intervals for model 1 and model 2 and 90% confidence intervals
|
1519 |
+
for model 3, you could type:
|
1520 |
+
|
1521 |
+
{com}{...}
|
1522 |
+
. coefplot model1 model2 (model3, level(90)), levels(99 95)
|
1523 |
+
{txt}{...}
|
1524 |
+
|
1525 |
+
{pstd}
|
1526 |
+
There are some fine distinctions about the placement of options and how they
|
1527 |
+
are interpreted. For example, if you type
|
1528 |
+
|
1529 |
+
{com}{...}
|
1530 |
+
. coefplot m1, {txt:{it:opts1}} || m2, {txt:{it:opts2}} {txt:{it:opts3}}
|
1531 |
+
{txt}{...}
|
1532 |
+
|
1533 |
+
{pstd}
|
1534 |
+
then {it:opts2} and {it:opts3} are interpreted as global options. If you
|
1535 |
+
want to apply {it:opts2} only to {cmd:m2} then type
|
1536 |
+
|
1537 |
+
{com}{...}
|
1538 |
+
. coefplot m1, {txt:{it:opts1}} || m2, {txt:{it:opts2}} ||, {txt:{it:opts3}}
|
1539 |
+
{txt}{...}
|
1540 |
+
|
1541 |
+
{pstd}
|
1542 |
+
Similarly, if you type
|
1543 |
+
|
1544 |
+
{com}{...}
|
1545 |
+
. coefplot (m1, {txt:{it:opts1}} \ m2, {txt:{it:opts2}})
|
1546 |
+
{txt}{...}
|
1547 |
+
|
1548 |
+
{pstd}
|
1549 |
+
then {it:opts2} will be applied to both models. To apply {it:opts2} only to
|
1550 |
+
{cmd:m2} type
|
1551 |
+
|
1552 |
+
{com}{...}
|
1553 |
+
. coefplot (m1, {txt:{it:opts1}} \ m2, {txt:{it:opts2}} \)
|
1554 |
+
{txt}{...}
|
1555 |
+
|
1556 |
+
{pstd}
|
1557 |
+
or, if you also want to include {it:opts3} to be applied to both models,
|
1558 |
+
type
|
1559 |
+
|
1560 |
+
{com}{...}
|
1561 |
+
. coefplot (m1, {txt:{it:opts1}} \ m2, {txt:{it:opts2}} \, {txt:{it:opts3}})
|
1562 |
+
{txt}{...}
|
1563 |
+
|
1564 |
+
{pstd}
|
1565 |
+
or
|
1566 |
+
|
1567 |
+
{com}{...}
|
1568 |
+
. coefplot (m1, {txt:{it:opts1}} \ m2, {txt:{it:opts2}} \), {txt:{it:opts3}}
|
1569 |
+
{txt}{...}
|
1570 |
+
|
1571 |
+
{pstd}
|
1572 |
+
In case of multiple subgraphs there is some ambiguity about where to
|
1573 |
+
specify the plot options (unless global option
|
1574 |
+
{helpb coefplot##norecycle:norecycle} is specified). You can provide plot
|
1575 |
+
options within any of the subgraphs as plot options are collected across
|
1576 |
+
subgraphs. However, in case of conflict, the plot options from the rightmost
|
1577 |
+
subgraph usually take precedence over earlier plot options. In addition,
|
1578 |
+
you can also use global options {helpb coefplot##pnum:p1()},
|
1579 |
+
{helpb coefplot##pnum:p2()}, etc. to provide
|
1580 |
+
options for specific plots. In case of conflict, options specified within a plot take
|
1581 |
+
precedence over options provided via {helpb coefplot##pnum:p1()},
|
1582 |
+
{helpb coefplot##pnum:p2()}, etc.
|
1583 |
+
|
1584 |
+
{marker matrix}{...}
|
1585 |
+
{title:Plotting results from matrices}
|
1586 |
+
|
1587 |
+
{pstd}
|
1588 |
+
Use syntax {helpb coefplot##matrix:{ul:m}atrix({it:mspec})} instead of the
|
1589 |
+
name of a stored model to plot results from a matrix. {it:mspec} may be:
|
1590 |
+
|
1591 |
+
{p2colset 9 21 23 2}{...}
|
1592 |
+
{p2col:{it:name}}use first row of matrix {it:name}
|
1593 |
+
{p_end}
|
1594 |
+
{p2col:{it:name}{cmd:[}#{cmd:,.]}}use #th row of
|
1595 |
+
matrix {it:name}; may also type {it:name}{cmd:[}#{cmd:,]} or
|
1596 |
+
{it:name}{cmd:[}#{cmd:]}
|
1597 |
+
{p_end}
|
1598 |
+
{p2col:{it:name}{cmd:[.,}#{cmd:]}}use #th column of
|
1599 |
+
matrix {it:name}; may also type {it:name}{cmd:[,}#{cmd:]}
|
1600 |
+
{p_end}
|
1601 |
+
{p2colreset}{...}
|
1602 |
+
|
1603 |
+
{pstd}
|
1604 |
+
If the {cmd:matrix()} syntax is used, then option {helpb coefplot##b:b()} is discarded
|
1605 |
+
and names given in {helpb coefplot##at:at()}, {helpb coefplot##ci:ci()},
|
1606 |
+
{helpb coefplot##v:v()}, {helpb coefplot##se:se()},
|
1607 |
+
{helpb coefplot##df:df()}, and {helpb coefplot##aux:aux()} refer to regular
|
1608 |
+
matrices instead of {cmd:e()}-matrices. The matrix name may be omitted in these
|
1609 |
+
options if results are to be read from the same matrix; only the
|
1610 |
+
relevant row or column numbers have to be provided (whether the
|
1611 |
+
numbers are interpreted as row or column numbers
|
1612 |
+
depends what was specified in {cmd:matrix()}).
|
1613 |
+
|
1614 |
+
{pstd}
|
1615 |
+
For example, to plot medians and their confidence intervals as computed
|
1616 |
+
by {helpb centile} you could type:
|
1617 |
+
|
1618 |
+
{com}{...}
|
1619 |
+
sysuse auto, clear
|
1620 |
+
matrix C = J(3,3,.)
|
1621 |
+
matrix rownames C = median ll95 ul95
|
1622 |
+
matrix colnames C = mpg trunk turn
|
1623 |
+
local i 0
|
1624 |
+
foreach v of var mpg trunk turn {
|
1625 |
+
local ++ i
|
1626 |
+
centile `v'
|
1627 |
+
matrix C[1,`i'] = r(c_1) \ r(lb_1) \ r(ub_1)
|
1628 |
+
}
|
1629 |
+
matrix list C
|
1630 |
+
coefplot matrix(C), ci((2 3))
|
1631 |
+
{txt}{...}
|
1632 |
+
|
1633 |
+
{pstd}
|
1634 |
+
This is equivalent to:
|
1635 |
+
|
1636 |
+
{com}{...}
|
1637 |
+
coefplot matrix(C[1]), ci((C[2] C[3]))
|
1638 |
+
{txt}{...}
|
1639 |
+
|
1640 |
+
{pstd}
|
1641 |
+
Note that a single {cmd:coefplot} command can contain both regular syntax
|
1642 |
+
and {cmd:matrix()} syntax. For example, to add means to the graph above
|
1643 |
+
you could type:
|
1644 |
+
|
1645 |
+
{com}{...}
|
1646 |
+
mean mpg trunk turn
|
1647 |
+
estimates store mean
|
1648 |
+
coefplot (matrix(C), ci((2 3))) (mean)
|
1649 |
+
{txt}{...}
|
1650 |
+
|
1651 |
+
|
1652 |
+
{marker tempvar}{...}
|
1653 |
+
{title:Accessing internal temporary variables}
|
1654 |
+
|
1655 |
+
{pstd}
|
1656 |
+
{cmd:coefplot} maintains a number of internal variables that can be
|
1657 |
+
used within
|
1658 |
+
{helpb coefplot##ifopt:if()},
|
1659 |
+
{helpb coefplot##weight:weight()},
|
1660 |
+
{helpb coefplot##transform:transform()},
|
1661 |
+
{helpb marker_label_options:mlabel()},
|
1662 |
+
{helpb marker_label_options:mlabvposition()}, and
|
1663 |
+
{helpb addplot_option:addplot()}. These
|
1664 |
+
variables are:
|
1665 |
+
|
1666 |
+
{p2colset 9 21 23 2}{...}
|
1667 |
+
{p2col:{cmd:@b}}point estimates
|
1668 |
+
{p_end}
|
1669 |
+
{p2col:{cmd:@ll}#}lower limits of confidence interval # (may use {cmd:@ll} for {cmd:@ll1})
|
1670 |
+
{p_end}
|
1671 |
+
{p2col:{cmd:@ul}#}upper limits of confidence interval # (may use {cmd:@ul} for {cmd:@ul1})
|
1672 |
+
{p_end}
|
1673 |
+
{p2col:{cmd:@V}}variances
|
1674 |
+
{p_end}
|
1675 |
+
{p2col:{cmd:@se}}standard errors
|
1676 |
+
{p_end}
|
1677 |
+
{p2col:{cmd:@t}}t or z statistics, computed as @b/@se
|
1678 |
+
{p_end}
|
1679 |
+
{p2col:{cmd:@df}}degrees of freedom
|
1680 |
+
{p_end}
|
1681 |
+
{p2col:{cmd:@pval}}p-values, computed as (1-normal(|@t|))*2 or ttail(@df,|@t|)*2, depending
|
1682 |
+
on whether df are available
|
1683 |
+
{p_end}
|
1684 |
+
{p2col:{cmd:@at}}plot positions
|
1685 |
+
{p_end}
|
1686 |
+
{p2col:{cmd:@plot}}plot ID (labeled)
|
1687 |
+
{p_end}
|
1688 |
+
{p2col:{cmd:@by}}subgraph ID (labeled)
|
1689 |
+
{p_end}
|
1690 |
+
{p2col:{cmd:@mlbl}}Marker labels set by {helpb coefplot##mlabels:mlabels()} (string variable)
|
1691 |
+
{p_end}
|
1692 |
+
{p2col:{cmd:@mlpos}}Marker label positions set by {helpb coefplot##mlabels:mlabels()}
|
1693 |
+
{p_end}
|
1694 |
+
{p2col:{cmd:@aux}#}auxiliary variables collected by {helpb coefplot##aux:aux()} (may use {cmd:@aux} for {cmd:@aux1})
|
1695 |
+
{p_end}
|
1696 |
+
{p2colreset}{...}
|
1697 |
+
|
1698 |
+
{pstd}
|
1699 |
+
The internal variables can be used like other variables in the
|
1700 |
+
dataset. For example, option {cmd:mlabel(@plot)} would add plot labels as marker
|
1701 |
+
labels or option {cmd:addplot(line @at @b)} would draw a connecting line
|
1702 |
+
through all point estimates in the graph.
|
1703 |
+
|
1704 |
+
|
1705 |
+
{marker saved_results}{...}
|
1706 |
+
{title:Saved results}
|
1707 |
+
|
1708 |
+
{pstd}
|
1709 |
+
{cmd:coefplot} returns the following macros and scalars in {cmd:r()}:
|
1710 |
+
|
1711 |
+
{synoptset 20 tabbed}{...}
|
1712 |
+
{p2col 5 20 24 2: Scalars}{p_end}
|
1713 |
+
{synopt:{cmd:r(n_ci)}}number of confidence intervals{p_end}
|
1714 |
+
{synopt:{cmd:r(n_plot)}}number of plots{p_end}
|
1715 |
+
{synopt:{cmd:r(n_subgr)}}number of subgraphs{p_end}
|
1716 |
+
|
1717 |
+
{synoptset 20 tabbed}{...}
|
1718 |
+
{p2col 5 20 24 2: Macros}{p_end}
|
1719 |
+
{synopt:{cmd:r(graph)}}copy of graph command{p_end}
|
1720 |
+
{synopt:{cmd:r(labels)}}coefficient labels{p_end}
|
1721 |
+
{synopt:{cmd:r(eqlabels)}}equation labels{p_end}
|
1722 |
+
{synopt:{cmd:r(groups)}}group labels{p_end}
|
1723 |
+
{synopt:{cmd:r(headings)}}headings{p_end}
|
1724 |
+
{synopt:{cmd:r(legend)}}contents of legend option{p_end}
|
1725 |
+
|
1726 |
+
|
1727 |
+
{marker author}{...}
|
1728 |
+
{title:Author}
|
1729 |
+
|
1730 |
+
{pstd}
|
1731 |
+
Ben Jann, University of Bern, [email protected]
|
1732 |
+
|
1733 |
+
{pstd}
|
1734 |
+
Thanks for citing this software in one of the following ways:
|
1735 |
+
|
1736 |
+
{pmore}
|
1737 |
+
Jann, B. (2014). Plotting regression coefficients and other
|
1738 |
+
estimates. The Stata Journal 14(4): 708-737.
|
1739 |
+
|
1740 |
+
{pmore}
|
1741 |
+
Jann, B. (2013). Plotting regression coefficients and other estimates
|
1742 |
+
in Stata. University of Bern Social Sciences Working Papers
|
1743 |
+
Nr. 1. Available from
|
1744 |
+
{browse "http://ideas.repec.org/p/bss/wpaper/1.html"}.
|
1745 |
+
|
1746 |
+
{pmore}
|
1747 |
+
Jann, B. (2013). coefplot: Stata module to plot regression coefficients
|
1748 |
+
and other results. Available from
|
1749 |
+
{browse "http://ideas.repec.org/c/boc/bocode/s457686.html"}.
|
1750 |
+
|
1751 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estadd.ado
ADDED
@@ -0,0 +1,2463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.3.3 28may2014 Ben Jann
|
2 |
+
* 1. estadd and helpers
|
3 |
+
* 2. estadd_local
|
4 |
+
* 3. estadd_scalar
|
5 |
+
* 4. estadd_matrix
|
6 |
+
* 5. estadd_mean
|
7 |
+
* 6. estadd_sd
|
8 |
+
* 7. estadd_beta
|
9 |
+
* 8. estadd_coxsnell
|
10 |
+
* 9. estadd_nagelkerke
|
11 |
+
* 10. estadd_ysumm
|
12 |
+
* 11. estadd_summ
|
13 |
+
* 12. estadd_vif
|
14 |
+
* 13. estadd_ebsd
|
15 |
+
* 14. estadd_expb
|
16 |
+
* 15. estadd_pcorr
|
17 |
+
* 16. estadd_lrtest
|
18 |
+
* 17. estadd_brent
|
19 |
+
* 18. estadd_fitstat
|
20 |
+
* 19. estadd_listcoef
|
21 |
+
* 20. estadd_mlogtest
|
22 |
+
* 21. estadd_prchange
|
23 |
+
* 22. estadd_prvalue
|
24 |
+
* 23. estadd_asprvalue
|
25 |
+
* 24. estadd_margins
|
26 |
+
* 99. copy of erepost.ado
|
27 |
+
|
28 |
+
* 1.
|
29 |
+
program estadd
|
30 |
+
version 8.2
|
31 |
+
local caller : di _caller()
|
32 |
+
capt _on_colon_parse `0'
|
33 |
+
if !_rc {
|
34 |
+
local 0 `"`s(before)'"'
|
35 |
+
local names `"`s(after)'"'
|
36 |
+
}
|
37 |
+
syntax anything(equalok id="subcommand") [if] [in] [fw aw iw pw] [, * ]
|
38 |
+
if regexm(`"`anything'"',"^r\((.*)\)$") { // check -estadd r(name)-
|
39 |
+
capt confirm scalar `anything'
|
40 |
+
if _rc {
|
41 |
+
capt confirm matrix `anything'
|
42 |
+
if _rc {
|
43 |
+
di as err `"`anything' not found"'
|
44 |
+
exit 111
|
45 |
+
}
|
46 |
+
else {
|
47 |
+
local anything `"matrix `anything'"'
|
48 |
+
}
|
49 |
+
}
|
50 |
+
else {
|
51 |
+
local anything `"scalar `anything'"'
|
52 |
+
}
|
53 |
+
}
|
54 |
+
gettoken subcommand : anything
|
55 |
+
capt confirm name `subcommand'
|
56 |
+
if _rc {
|
57 |
+
di as err "invalid subcommand"
|
58 |
+
exit 198
|
59 |
+
}
|
60 |
+
if `"`options'"'!="" local options `", `options'"'
|
61 |
+
if `"`weight'`exp'"'!="" local wgtexp `"[`weight'`exp']"'
|
62 |
+
|
63 |
+
//expand estimates names and backup current estimates if necessary
|
64 |
+
tempname rcurrent ecurrent
|
65 |
+
capt _return drop `rcurrent'
|
66 |
+
_return hold `rcurrent'
|
67 |
+
capt noisily {
|
68 |
+
local names: list retok names
|
69 |
+
if "`names'"=="" {
|
70 |
+
local names "."
|
71 |
+
local qui
|
72 |
+
}
|
73 |
+
else local qui quietly
|
74 |
+
foreach name of local names {
|
75 |
+
if "`name'"=="." {
|
76 |
+
capt est_expand "`name'"
|
77 |
+
if _rc local enames "`enames'`name' "
|
78 |
+
else local enames "`enames'`r(names)' "
|
79 |
+
}
|
80 |
+
else {
|
81 |
+
est_expand "`name'" //=> error if estimates not found
|
82 |
+
local enames "`enames'`r(names)' "
|
83 |
+
}
|
84 |
+
}
|
85 |
+
local names: list uniq enames
|
86 |
+
if "`names'"=="." local active
|
87 |
+
else {
|
88 |
+
capt est_expand .
|
89 |
+
if _rc local active "."
|
90 |
+
else local active "`r(names)'"
|
91 |
+
if "`active'"=="." | `:list posof "`active'" in names'==0 {
|
92 |
+
local active
|
93 |
+
_est hold `ecurrent', restore estsystem nullok
|
94 |
+
}
|
95 |
+
}
|
96 |
+
}
|
97 |
+
if _rc {
|
98 |
+
_return restore `rcurrent'
|
99 |
+
exit _rc
|
100 |
+
}
|
101 |
+
_return restore `rcurrent', hold
|
102 |
+
|
103 |
+
// cases:
|
104 |
+
// - if active estimates not stored yet and "`names'"==".": simply execute
|
105 |
+
// estadd_subcmd to active estimates
|
106 |
+
// - else if active estimates not stored yet: backup/restore active estimates
|
107 |
+
// - else if active estimates stored but not in `names': backup/restore active estimates
|
108 |
+
// - else if active estimates stored: no backup but restore at end
|
109 |
+
|
110 |
+
//loop over estimates names and run subcommand
|
111 |
+
nobreak {
|
112 |
+
foreach m of local names {
|
113 |
+
if "`names'"!="." {
|
114 |
+
if "`m'"=="." _est unhold `ecurrent'
|
115 |
+
else {
|
116 |
+
capt confirm new var _est_`m' // fix e(sample)
|
117 |
+
if _rc qui replace _est_`m' = 0 if _est_`m' >=.
|
118 |
+
_est unhold `m'
|
119 |
+
}
|
120 |
+
}
|
121 |
+
backup_estimates_name
|
122 |
+
capt n break `qui' version `caller': estadd_`anything' `if' `in' `wgtexp' `options'
|
123 |
+
local rc = _rc
|
124 |
+
restore_estimates_name
|
125 |
+
if "`names'"!="." {
|
126 |
+
if "`m'"=="." _est hold `ecurrent', restore estsystem nullok
|
127 |
+
else _est hold `m', estimates varname(_est_`m')
|
128 |
+
}
|
129 |
+
if `rc' continue, break
|
130 |
+
}
|
131 |
+
if "`active'"!="" estimates restore `active', noh
|
132 |
+
}
|
133 |
+
_return restore `rcurrent'
|
134 |
+
if `rc' {
|
135 |
+
if `rc' == 199 di as error "invalid subcommand"
|
136 |
+
exit `rc'
|
137 |
+
}
|
138 |
+
end
|
139 |
+
|
140 |
+
program define backup_estimates_name, eclass
|
141 |
+
ereturn local _estadd_estimates_name `"`e(_estimates_name)'"'
|
142 |
+
ereturn local _estimates_name ""
|
143 |
+
end
|
144 |
+
program define restore_estimates_name, eclass
|
145 |
+
ereturn local _estimates_name `"`e(_estadd_estimates_name)'"'
|
146 |
+
ereturn local _estadd_estimates_name ""
|
147 |
+
end
|
148 |
+
|
149 |
+
program confirm_new_ename
|
150 |
+
capture confirm existence `e(`0')'
|
151 |
+
if !_rc {
|
152 |
+
di as err "e(`0') already defined"
|
153 |
+
exit 110
|
154 |
+
}
|
155 |
+
end
|
156 |
+
|
157 |
+
program confirm_esample
|
158 |
+
local efun: e(functions)
|
159 |
+
if `:list posof "sample" in efun'==0 {
|
160 |
+
di as err "e(sample) information not available"
|
161 |
+
exit 498
|
162 |
+
}
|
163 |
+
end
|
164 |
+
|
165 |
+
program confirm_numvar
|
166 |
+
args var
|
167 |
+
local ts = index("`var'",".")
|
168 |
+
confirm numeric variable `=substr("`var'",`ts'+1,.)'
|
169 |
+
end
|
170 |
+
|
171 |
+
program define added_macro
|
172 |
+
args name
|
173 |
+
di as txt %25s `"e(`name') : "' `""{res:`e(`name')'}""'
|
174 |
+
end
|
175 |
+
|
176 |
+
program define added_scalar
|
177 |
+
args name label
|
178 |
+
di as txt %25s `"e(`name') = "' " " as res e(`name') _c
|
179 |
+
if `"`label'"'!="" {
|
180 |
+
di as txt _col(38) `"(`label')"'
|
181 |
+
}
|
182 |
+
else di ""
|
183 |
+
end
|
184 |
+
|
185 |
+
program define added_matrix
|
186 |
+
args name label
|
187 |
+
capture {
|
188 |
+
local r = rowsof(e(`name'))
|
189 |
+
local c = colsof(e(`name'))
|
190 |
+
}
|
191 |
+
if _rc {
|
192 |
+
tempname tmp
|
193 |
+
mat `tmp' = e(`name')
|
194 |
+
local r = rowsof(`tmp')
|
195 |
+
local c = colsof(`tmp')
|
196 |
+
}
|
197 |
+
di as txt %25s `"e(`name') : "' " " ///
|
198 |
+
as res "`r' x `c'" _c
|
199 |
+
if `"`label'"'=="_rown" {
|
200 |
+
local thelabel: rownames e(`name')
|
201 |
+
local thelabel: list retok thelabel
|
202 |
+
if `r'>1 {
|
203 |
+
local thelabel: subinstr local thelabel " " ", ", all
|
204 |
+
}
|
205 |
+
di as txt _col(38) `"(`thelabel')"'
|
206 |
+
}
|
207 |
+
else if `"`label'"'!="" {
|
208 |
+
di as txt _col(38) `"(`label')"'
|
209 |
+
}
|
210 |
+
else di ""
|
211 |
+
end
|
212 |
+
|
213 |
+
* 2.
|
214 |
+
* -estadd- subroutine: add local
|
215 |
+
program estadd_loc
|
216 |
+
estadd_local `0'
|
217 |
+
end
|
218 |
+
program estadd_loca
|
219 |
+
estadd_local `0'
|
220 |
+
end
|
221 |
+
program estadd_local, eclass
|
222 |
+
version 8.2
|
223 |
+
syntax anything(equalok) [, Prefix(name) Replace Quietly ]
|
224 |
+
gettoken name def : anything , parse(" =:")
|
225 |
+
if "`replace'"=="" {
|
226 |
+
confirm_new_ename `prefix'`name'
|
227 |
+
}
|
228 |
+
ereturn local `prefix'`name'`def'
|
229 |
+
di _n as txt "added macro:"
|
230 |
+
added_macro `prefix'`name'
|
231 |
+
end
|
232 |
+
|
233 |
+
* 3.
|
234 |
+
* -estadd- subroutine: add scalar
|
235 |
+
program estadd_sca
|
236 |
+
estadd_scalar `0'
|
237 |
+
end
|
238 |
+
program estadd_scal
|
239 |
+
estadd_scalar `0'
|
240 |
+
end
|
241 |
+
program estadd_scala
|
242 |
+
estadd_scalar `0'
|
243 |
+
end
|
244 |
+
program estadd_scalar, eclass
|
245 |
+
version 8.2
|
246 |
+
syntax anything(equalok) [, Prefix(name) Replace Quietly ]
|
247 |
+
if regexm("`anything'","^r\((.*)\)$") { // estadd scalar r(name)
|
248 |
+
local name = regexs(1)
|
249 |
+
capt confirm name `name'
|
250 |
+
confirm scalar `anything'
|
251 |
+
if _rc error 198
|
252 |
+
local equ "`anything'"
|
253 |
+
}
|
254 |
+
else {
|
255 |
+
local isname 0
|
256 |
+
gettoken name equ0: anything, parse(" =")
|
257 |
+
capt confirm name `name'
|
258 |
+
if _rc error 198
|
259 |
+
else if `"`equ0'"'=="" { // estadd scalar name
|
260 |
+
local isname 1
|
261 |
+
local equ "scalar(`name')"
|
262 |
+
}
|
263 |
+
else { // estadd scalar name [=] exp
|
264 |
+
gettoken trash equ : equ0, parse(" =")
|
265 |
+
if `"`trash'"'!="=" {
|
266 |
+
local equ `"`equ0'"'
|
267 |
+
}
|
268 |
+
}
|
269 |
+
}
|
270 |
+
if "`replace'"=="" {
|
271 |
+
confirm_new_ename `prefix'`name'
|
272 |
+
}
|
273 |
+
ereturn scalar `prefix'`name' = `equ'
|
274 |
+
di _n as txt "added scalar:"
|
275 |
+
added_scalar `prefix'`name'
|
276 |
+
end
|
277 |
+
|
278 |
+
* 4.
|
279 |
+
* -estadd- subroutine: add matrix
|
280 |
+
program estadd_mat
|
281 |
+
estadd_matrix `0'
|
282 |
+
end
|
283 |
+
program estadd_matr
|
284 |
+
estadd_matrix `0'
|
285 |
+
end
|
286 |
+
program estadd_matri
|
287 |
+
estadd_matrix `0'
|
288 |
+
end
|
289 |
+
program estadd_matrix, eclass
|
290 |
+
version 8.2
|
291 |
+
syntax anything(equalok) [, Prefix(name) Replace Quietly ]
|
292 |
+
if regexm("`anything'","^r\((.*)\)$") { // estadd matrix r(name)
|
293 |
+
local name = regexs(1)
|
294 |
+
capt confirm name `name'
|
295 |
+
if _rc error 198
|
296 |
+
confirm matrix `anything'
|
297 |
+
local equ "`anything'"
|
298 |
+
}
|
299 |
+
else {
|
300 |
+
local isname 0
|
301 |
+
gettoken name equ0: anything, parse(" =")
|
302 |
+
capt confirm name `name'
|
303 |
+
if _rc error 198
|
304 |
+
else if `"`equ0'"'=="" { // estadd matrix name
|
305 |
+
local isname 1
|
306 |
+
local equ "`name'"
|
307 |
+
}
|
308 |
+
else { // estadd matrix name [=] exp
|
309 |
+
gettoken trash equ : equ0, parse(" =")
|
310 |
+
if `"`trash'"'!="=" {
|
311 |
+
local equ `"`equ0'"'
|
312 |
+
}
|
313 |
+
}
|
314 |
+
}
|
315 |
+
if "`replace'"=="" {
|
316 |
+
confirm_new_ename `prefix'`name'
|
317 |
+
}
|
318 |
+
tempname M
|
319 |
+
mat `M' = `equ'
|
320 |
+
ereturn matrix `prefix'`name' = `M'
|
321 |
+
di _n as txt "added matrix:"
|
322 |
+
added_matrix `prefix'`name'
|
323 |
+
end
|
324 |
+
|
325 |
+
* 5.
|
326 |
+
* -estadd- subroutine: means of regressors
|
327 |
+
program define estadd_mean, eclass
|
328 |
+
version 8.2
|
329 |
+
syntax [, Prefix(name) Replace Quietly ]
|
330 |
+
//check availability of e(sample)
|
331 |
+
confirm_esample
|
332 |
+
//check e()-names
|
333 |
+
if "`replace'"=="" confirm_new_ename `prefix'mean
|
334 |
+
//use aweights with -summarize-
|
335 |
+
local wtype `e(wtype)'
|
336 |
+
if "`wtype'"=="pweight" local wtype aweight
|
337 |
+
//subpop?
|
338 |
+
local subpop "`e(subpop)'"
|
339 |
+
if "`subpop'"=="" local subpop 1
|
340 |
+
//copy coefficients matrix and determine varnames
|
341 |
+
tempname results
|
342 |
+
mat `results' = e(b)
|
343 |
+
local vars: colnames `results'
|
344 |
+
//loop over variables: calculate -mean-
|
345 |
+
local j 0
|
346 |
+
foreach var of local vars {
|
347 |
+
local ++j
|
348 |
+
capture confirm_numvar `var'
|
349 |
+
if _rc mat `results'[1,`j'] = .z
|
350 |
+
else {
|
351 |
+
capt su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop', meanonly
|
352 |
+
mat `results'[1,`j'] = cond(_rc,.,r(mean))
|
353 |
+
}
|
354 |
+
}
|
355 |
+
//return the results
|
356 |
+
ereturn matrix `prefix'mean = `results'
|
357 |
+
di _n as txt "added matrix:"
|
358 |
+
added_matrix `prefix'mean
|
359 |
+
end
|
360 |
+
|
361 |
+
* 6.
|
362 |
+
* -estadd- subroutine: standard deviations of regressors
|
363 |
+
program define estadd_sd, eclass
|
364 |
+
version 8.2
|
365 |
+
syntax [, noBinary Prefix(name) Replace Quietly ]
|
366 |
+
//check availability of e(sample)
|
367 |
+
confirm_esample
|
368 |
+
//check e()-names
|
369 |
+
if "`replace'"=="" confirm_new_ename `prefix'sd
|
370 |
+
//use aweights with -summarize-
|
371 |
+
local wtype `e(wtype)'
|
372 |
+
if "`wtype'"=="pweight" local wtype aweight
|
373 |
+
//subpop?
|
374 |
+
local subpop "`e(subpop)'"
|
375 |
+
if "`subpop'"=="" local subpop 1
|
376 |
+
//copy coefficients matrix and determine varnames
|
377 |
+
tempname results
|
378 |
+
mat `results' = e(b)
|
379 |
+
local vars: colnames `results'
|
380 |
+
//loop over variables: calculate -mean-
|
381 |
+
local j 0
|
382 |
+
foreach var of local vars {
|
383 |
+
local ++j
|
384 |
+
capture confirm_numvar `var'
|
385 |
+
if _rc mat `results'[1,`j'] = .z
|
386 |
+
else {
|
387 |
+
capture assert `var'==0 | `var'==1 if e(sample) & `subpop'
|
388 |
+
if _rc | "`binary'"=="" {
|
389 |
+
capt su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop'
|
390 |
+
mat `results'[1,`j'] = cond(_rc,.,r(sd))
|
391 |
+
}
|
392 |
+
else mat `results'[1,`j'] = .z
|
393 |
+
}
|
394 |
+
}
|
395 |
+
//return the results
|
396 |
+
ereturn matrix `prefix'sd = `results'
|
397 |
+
di _n as txt "added matrix:"
|
398 |
+
added_matrix `prefix'sd
|
399 |
+
end
|
400 |
+
|
401 |
+
* 7.
|
402 |
+
* -estadd- subroutine: standardized coefficients
|
403 |
+
program define estadd_beta, eclass
|
404 |
+
version 8.2
|
405 |
+
syntax [, Prefix(name) Replace Quietly ]
|
406 |
+
//check availability of e(sample)
|
407 |
+
confirm_esample
|
408 |
+
//check e()-names
|
409 |
+
if "`replace'"=="" confirm_new_ename `prefix'beta
|
410 |
+
//use aweights with -summarize-
|
411 |
+
local wtype `e(wtype)'
|
412 |
+
if "`wtype'"=="pweight" local wtype aweight
|
413 |
+
//subpop?
|
414 |
+
local subpop "`e(subpop)'"
|
415 |
+
if "`subpop'"=="" local subpop 1
|
416 |
+
//copy coefficients matrix and determine varnames
|
417 |
+
tempname results sddep
|
418 |
+
mat `results' = e(b)
|
419 |
+
local vars: colnames `results'
|
420 |
+
local eqs: coleq `results', q
|
421 |
+
local depv "`e(depvar)'"
|
422 |
+
//loop over variables: calculate -beta-
|
423 |
+
local j 0
|
424 |
+
local lastdepvar
|
425 |
+
foreach var of local vars {
|
426 |
+
local depvar: word `++j' of `eqs'
|
427 |
+
if "`depvar'"=="_" local depvar "`depv'"
|
428 |
+
capture confirm_numvar `depvar'
|
429 |
+
if _rc mat `results'[1,`j'] = .z
|
430 |
+
else {
|
431 |
+
if "`depvar'"!="`lastdepvar'" {
|
432 |
+
capt su `depvar' [`wtype'`e(wexp)'] if e(sample) & `subpop'
|
433 |
+
scalar `sddep' = cond(_rc,.,r(sd))
|
434 |
+
}
|
435 |
+
capture confirm_numvar `var'
|
436 |
+
if _rc mat `results'[1,`j'] = .z
|
437 |
+
else {
|
438 |
+
capt su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop'
|
439 |
+
mat `results'[1,`j'] = cond(_rc,.,`results'[1,`j'] * r(sd) / `sddep')
|
440 |
+
}
|
441 |
+
}
|
442 |
+
local lastdepvar "`depvar'"
|
443 |
+
}
|
444 |
+
//return the results
|
445 |
+
ereturn matrix `prefix'beta = `results'
|
446 |
+
di _n as txt "added matrix:"
|
447 |
+
added_matrix `prefix'beta
|
448 |
+
end
|
449 |
+
|
450 |
+
* 8.
|
451 |
+
* -estadd- subroutine: Cox & Snell Pseudo R-Squared
|
452 |
+
program define estadd_coxsnell, eclass
|
453 |
+
version 8.2
|
454 |
+
syntax [, Prefix(name) Replace Quietly ]
|
455 |
+
//check e()-names
|
456 |
+
if "`replace'"=="" confirm_new_ename `prefix'coxsnell
|
457 |
+
//compute statistic
|
458 |
+
tempname results
|
459 |
+
scalar `results' = 1 - exp((e(ll_0)-e(ll))*2/e(N)) // = 1 - exp(e(ll_0)-e(ll))^(2/e(N))
|
460 |
+
//return the results
|
461 |
+
*di as txt "Cox & Snell Pseudo R2 = " as res `results'
|
462 |
+
ereturn scalar `prefix'coxsnell = `results'
|
463 |
+
di _n as txt "added scalar:"
|
464 |
+
added_scalar `prefix'coxsnell
|
465 |
+
end
|
466 |
+
|
467 |
+
* 9.
|
468 |
+
* -estadd- subroutine: Nagelkerke Pseudo R-Squared
|
469 |
+
program define estadd_nagelkerke, eclass
|
470 |
+
version 8.2
|
471 |
+
syntax [, Prefix(name) Replace Quietly ]
|
472 |
+
//check e()-names
|
473 |
+
if "`replace'"=="" confirm_new_ename `prefix'nagelkerke
|
474 |
+
//compute statistic
|
475 |
+
tempname results
|
476 |
+
scalar `results' = (1 - exp((e(ll_0)-e(ll))*2/e(N))) / (1 - exp(e(ll_0)*2/e(N)))
|
477 |
+
// = (1 - exp(e(ll_0)-e(ll))^(2/e(N))) / (1 - exp(e(ll_0))^(2/e(N)))
|
478 |
+
//return the results
|
479 |
+
*di as txt "Nagelkerke Pseudo R2 = " as res `results'
|
480 |
+
ereturn scalar `prefix'nagelkerke = `results'
|
481 |
+
di _n as txt "added scalar:"
|
482 |
+
added_scalar `prefix'nagelkerke
|
483 |
+
end
|
484 |
+
|
485 |
+
* 10.
|
486 |
+
* -estadd- subroutine: summary statistics for dependent variable
|
487 |
+
program define estadd_ysumm, eclass
|
488 |
+
version 8.2
|
489 |
+
syntax [, MEan SUm MIn MAx RAnge sd Var cv SEMean SKewness ///
|
490 |
+
Kurtosis MEDian p1 p5 p10 p25 p50 p75 p90 p95 p99 iqr q all ///
|
491 |
+
Prefix(passthru) Replace Quietly ]
|
492 |
+
//check availability of e(sample)
|
493 |
+
confirm_esample
|
494 |
+
//default prefix
|
495 |
+
if `"`prefix'"'=="" local prefix y
|
496 |
+
else {
|
497 |
+
local 0 ", `prefix'"
|
498 |
+
syntax [, prefix(name) ]
|
499 |
+
}
|
500 |
+
//use aweights with -summarize-
|
501 |
+
local wtype `e(wtype)'
|
502 |
+
if "`wtype'"=="pweight" local wtype aweight
|
503 |
+
//subpop?
|
504 |
+
local subpop "`e(subpop)'"
|
505 |
+
if "`subpop'"=="" local subpop 1
|
506 |
+
//determine list of stats
|
507 |
+
tempname results
|
508 |
+
local Stats p99 p95 p90 p75 p50 p25 p10 p5 p1 kurtosis ///
|
509 |
+
skewness var sd max min sum mean
|
510 |
+
if "`all'"!="" {
|
511 |
+
local stats `Stats'
|
512 |
+
local range range
|
513 |
+
local cv cv
|
514 |
+
local semean semean
|
515 |
+
local iqr iqr
|
516 |
+
local sumtype detail
|
517 |
+
}
|
518 |
+
else {
|
519 |
+
if "`q'"!="" {
|
520 |
+
local p25 p25
|
521 |
+
local p50 p50
|
522 |
+
local p75 p75
|
523 |
+
}
|
524 |
+
if "`median'"!="" local p50 p50
|
525 |
+
foreach stat of local Stats {
|
526 |
+
if "``stat''"!="" {
|
527 |
+
local stats: list stats | stat
|
528 |
+
}
|
529 |
+
}
|
530 |
+
if "`stats'"=="" & "`range'"=="" & "`cv'"=="" & ///
|
531 |
+
"`semean'"=="" & "`iqr'"=="" local stats sd max min mean
|
532 |
+
local sumtype sum mean min max
|
533 |
+
if "`:list stats - sumtype'"=="" & "`cv'"=="" & ///
|
534 |
+
"`semean'"=="" & "`iqr'"=="" local sumtype meanonly
|
535 |
+
else {
|
536 |
+
local sumtype `sumtype' Var sd
|
537 |
+
if "`:list stats - sumtype'"=="" & "`iqr'"=="" local sumtype
|
538 |
+
else local sumtype detail
|
539 |
+
}
|
540 |
+
}
|
541 |
+
local Stats: subinstr local stats "var" "Var"
|
542 |
+
local nstats: word count `iqr' `semean' `cv' `range' `stats'
|
543 |
+
if "`replace'"=="" {
|
544 |
+
foreach stat in `iqr' `semean' `cv' `range' `stats' {
|
545 |
+
confirm_new_ename `prefix'`=lower("`stat'")'
|
546 |
+
}
|
547 |
+
}
|
548 |
+
//calculate stats
|
549 |
+
local var: word 1 of `e(depvar)'
|
550 |
+
mat `results' = J(`nstats',1,.z)
|
551 |
+
qui su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop', `sumtype'
|
552 |
+
local i 0
|
553 |
+
if "`iqr'"!="" {
|
554 |
+
mat `results'[`++i',1] = r(p75) - r(p25)
|
555 |
+
}
|
556 |
+
if "`semean'"!="" {
|
557 |
+
mat `results'[`++i',1] = r(sd) / sqrt(r(N))
|
558 |
+
}
|
559 |
+
if "`cv'"!="" {
|
560 |
+
mat `results'[`++i',1] = r(sd) / r(mean)
|
561 |
+
}
|
562 |
+
if "`range'"!="" {
|
563 |
+
mat `results'[`++i',1] = r(max) - r(min)
|
564 |
+
}
|
565 |
+
foreach stat of local Stats {
|
566 |
+
mat `results'[`++i',1] = r(`stat')
|
567 |
+
}
|
568 |
+
//return the results
|
569 |
+
local i 0
|
570 |
+
di as txt _n "added scalars:"
|
571 |
+
foreach stat in `iqr' `semean' `cv' `range' `stats' {
|
572 |
+
local sname = lower("`stat'")
|
573 |
+
ereturn scalar `prefix'`sname' = `results'[`++i',1]
|
574 |
+
added_scalar `prefix'`sname'
|
575 |
+
}
|
576 |
+
end
|
577 |
+
|
578 |
+
* 11.
|
579 |
+
* -estadd- subroutine: various summary statistics
|
580 |
+
program define estadd_summ, eclass
|
581 |
+
version 8.2
|
582 |
+
syntax [, MEan SUm MIn MAx RAnge sd Var cv SEMean SKewness ///
|
583 |
+
Kurtosis MEDian p1 p5 p10 p25 p50 p75 p90 p95 p99 iqr q all ///
|
584 |
+
Prefix(name) Replace Quietly ]
|
585 |
+
//check availability of e(sample)
|
586 |
+
confirm_esample
|
587 |
+
//use aweights with -summarize-
|
588 |
+
local wtype `e(wtype)'
|
589 |
+
if "`wtype'"=="pweight" local wtype aweight
|
590 |
+
//subpop?
|
591 |
+
local subpop "`e(subpop)'"
|
592 |
+
if "`subpop'"=="" local subpop 1
|
593 |
+
//determine list of stats
|
594 |
+
tempname results results2
|
595 |
+
local Stats p99 p95 p90 p75 p50 p25 p10 p5 p1 kurtosis ///
|
596 |
+
skewness var sd max min sum mean
|
597 |
+
if "`all'"!="" {
|
598 |
+
local stats `Stats'
|
599 |
+
local range range
|
600 |
+
local cv cv
|
601 |
+
local semean semean
|
602 |
+
local iqr iqr
|
603 |
+
local sumtype detail
|
604 |
+
}
|
605 |
+
else {
|
606 |
+
if "`q'"!="" {
|
607 |
+
local p25 p25
|
608 |
+
local p50 p50
|
609 |
+
local p75 p75
|
610 |
+
}
|
611 |
+
if "`median'"!="" local p50 p50
|
612 |
+
foreach stat of local Stats {
|
613 |
+
if "``stat''"!="" {
|
614 |
+
local stats: list stats | stat
|
615 |
+
}
|
616 |
+
}
|
617 |
+
if "`stats'"=="" & "`range'"=="" & "`cv'"=="" & ///
|
618 |
+
"`semean'"=="" & "`iqr'"=="" local stats sd max min mean
|
619 |
+
local sumtype sum mean min max
|
620 |
+
if "`:list stats - sumtype'"=="" & "`cv'"=="" & ///
|
621 |
+
"`semean'"=="" & "`iqr'"=="" local sumtype meanonly
|
622 |
+
else {
|
623 |
+
local sumtype `sumtype' Var sd
|
624 |
+
if "`:list stats - sumtype'"=="" & "`iqr'"=="" local sumtype
|
625 |
+
else local sumtype detail
|
626 |
+
}
|
627 |
+
}
|
628 |
+
local Stats: subinstr local stats "var" "Var"
|
629 |
+
local nstats: word count `iqr' `semean' `cv' `range' `stats'
|
630 |
+
if "`replace'"=="" {
|
631 |
+
foreach stat in `iqr' `semean' `cv' `range' `stats' {
|
632 |
+
confirm_new_ename `prefix'`=lower("`stat'")'
|
633 |
+
}
|
634 |
+
}
|
635 |
+
//copy coefficients matrix and determine varnames
|
636 |
+
mat `results' = e(b)
|
637 |
+
local vars: colnames `results'
|
638 |
+
if `nstats'>1 {
|
639 |
+
mat `results' = `results' \ J(`nstats'-1,colsof(`results'),.z)
|
640 |
+
}
|
641 |
+
//loop over variables: calculate stats
|
642 |
+
local j 0
|
643 |
+
foreach var of local vars {
|
644 |
+
local ++j
|
645 |
+
capture confirm_numvar `var'
|
646 |
+
if _rc mat `results'[1,`j'] = .z
|
647 |
+
else {
|
648 |
+
capt su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop', `sumtype'
|
649 |
+
local i 0
|
650 |
+
if "`iqr'"!="" {
|
651 |
+
mat `results'[`++i',`j'] = cond(_rc,.,r(p75) - r(p25))
|
652 |
+
}
|
653 |
+
if "`semean'"!="" {
|
654 |
+
mat `results'[`++i',`j'] = cond(_rc,.,r(sd) / sqrt(r(N)))
|
655 |
+
}
|
656 |
+
if "`cv'"!="" {
|
657 |
+
mat `results'[`++i',`j'] = cond(_rc,.,r(sd) / r(mean))
|
658 |
+
}
|
659 |
+
if "`range'"!="" {
|
660 |
+
mat `results'[`++i',`j'] = cond(_rc,.,r(max) - r(min))
|
661 |
+
}
|
662 |
+
foreach stat of local Stats {
|
663 |
+
mat `results'[`++i',`j'] = cond(_rc,.,r(`stat'))
|
664 |
+
}
|
665 |
+
}
|
666 |
+
}
|
667 |
+
//return the results
|
668 |
+
local i 0
|
669 |
+
di as txt _n "added matrices:"
|
670 |
+
foreach stat in `iqr' `semean' `cv' `range' `stats' {
|
671 |
+
local sname = lower("`stat'")
|
672 |
+
mat `results2' = `results'[`++i',1...]
|
673 |
+
ereturn matrix `prefix'`sname' = `results2'
|
674 |
+
added_matrix `prefix'`sname'
|
675 |
+
}
|
676 |
+
end
|
677 |
+
|
678 |
+
* 12.
|
679 |
+
* -estadd- subroutine: variance inflation factors
|
680 |
+
program define estadd_vif, eclass
|
681 |
+
version 8.2
|
682 |
+
local caller : di _caller()
|
683 |
+
syntax [, TOLerance SQRvif Prefix(name) Replace Quietly ]
|
684 |
+
//check availability of e(sample)
|
685 |
+
confirm_esample
|
686 |
+
//check e()-names
|
687 |
+
if "`replace'"=="" {
|
688 |
+
confirm_new_ename `prefix'vif
|
689 |
+
if "`tolerance'"!="" confirm_new_ename `prefix'tolerance
|
690 |
+
if "`sqrvif'"!="" confirm_new_ename `prefix'sqrvif
|
691 |
+
}
|
692 |
+
//copy coefficients matrix and set to .z
|
693 |
+
tempname results results2 results3
|
694 |
+
matrix `results' = e(b)
|
695 |
+
forv j = 1/`=colsof(`results')' {
|
696 |
+
mat `results'[1,`j'] = .z
|
697 |
+
}
|
698 |
+
if "`tolerance'"!="" mat `results2' = `results'
|
699 |
+
if "`sqrvif'"!="" mat `results3' = `results'
|
700 |
+
//compute VIF and add to results vector
|
701 |
+
capt n `quietly' version `caller': vif
|
702 |
+
if _rc {
|
703 |
+
if _rc == 301 di as err "-estadd:vif- can only be used after -regress-"
|
704 |
+
exit _rc
|
705 |
+
}
|
706 |
+
local i 0
|
707 |
+
local name "`r(name_`++i')'"
|
708 |
+
while "`name'"!="" {
|
709 |
+
local j = colnumb(`results',"`name'")
|
710 |
+
if `j'<. {
|
711 |
+
matrix `results'[1,`j'] = r(vif_`i')
|
712 |
+
if "`tolerance'"!="" matrix `results2'[1,`j'] = 1 / r(vif_`i')
|
713 |
+
if "`sqrvif'"!="" matrix `results3'[1,`j'] = sqrt( r(vif_`i') )
|
714 |
+
}
|
715 |
+
local name "`r(name_`++i')'"
|
716 |
+
}
|
717 |
+
//return the results
|
718 |
+
if "`sqrvif'"!="" | "`tolerance'"!="" di as txt _n "added matrices:"
|
719 |
+
else di as txt _n "added matrix:"
|
720 |
+
if "`sqrvif'"!="" {
|
721 |
+
ereturn matrix `prefix'sqrvif = `results3'
|
722 |
+
added_matrix `prefix'sqrvif
|
723 |
+
}
|
724 |
+
if "`tolerance'"!="" {
|
725 |
+
ereturn matrix `prefix'tolerance = `results2'
|
726 |
+
added_matrix `prefix'tolerance
|
727 |
+
}
|
728 |
+
ereturn matrix `prefix'vif = `results'
|
729 |
+
added_matrix `prefix'vif
|
730 |
+
end
|
731 |
+
|
732 |
+
* 13.
|
733 |
+
* -estadd- subroutine: standardized factor change coefficients
|
734 |
+
program define estadd_ebsd, eclass
|
735 |
+
version 8.2
|
736 |
+
syntax [, Prefix(name) Replace Quietly ]
|
737 |
+
//check availability of e(sample)
|
738 |
+
confirm_esample
|
739 |
+
//check e()-names
|
740 |
+
if "`replace'"=="" confirm_new_ename `prefix'ebsd
|
741 |
+
//use aweights with -summarize-
|
742 |
+
local wtype `e(wtype)'
|
743 |
+
if "`wtype'"=="pweight" local wtype aweight
|
744 |
+
//subpop?
|
745 |
+
local subpop "`e(subpop)'"
|
746 |
+
if "`subpop'"=="" local subpop 1
|
747 |
+
//copy coefficients matrix and determine varnames
|
748 |
+
tempname results
|
749 |
+
mat `results' = e(b)
|
750 |
+
local vars: colnames `results'
|
751 |
+
//loop over variables: calculate -mean-
|
752 |
+
local j 0
|
753 |
+
foreach var of local vars {
|
754 |
+
local ++j
|
755 |
+
capture confirm_numvar `var'
|
756 |
+
if _rc mat `results'[1,`j'] = .z
|
757 |
+
else {
|
758 |
+
capt su `var' [`wtype'`e(wexp)'] if e(sample) & `subpop'
|
759 |
+
mat `results'[1,`j'] = cond(_rc,.,exp( `results'[1,`j'] * r(sd)))
|
760 |
+
}
|
761 |
+
}
|
762 |
+
//return the results
|
763 |
+
ereturn matrix `prefix'ebsd = `results'
|
764 |
+
di _n as txt "added matrix:"
|
765 |
+
added_matrix `prefix'ebsd
|
766 |
+
end
|
767 |
+
|
768 |
+
* 14.
|
769 |
+
* -estadd- subroutine: exponentiated coefficients
|
770 |
+
program define estadd_expb, eclass
|
771 |
+
version 8.2
|
772 |
+
syntax [, noCONStant Prefix(name) Replace Quietly ]
|
773 |
+
//check e()-names
|
774 |
+
if "`replace'"=="" confirm_new_ename `prefix'expb
|
775 |
+
//copy coefficients matrix and determine names of coefficients
|
776 |
+
tempname results
|
777 |
+
mat `results' = e(b)
|
778 |
+
local coefs: colnames `results'
|
779 |
+
//loop over coefficients
|
780 |
+
local j 0
|
781 |
+
foreach coef of local coefs {
|
782 |
+
local ++j
|
783 |
+
if `"`constant'"'!="" & `"`coef'"'=="_cons" {
|
784 |
+
mat `results'[1,`j'] = .z
|
785 |
+
}
|
786 |
+
else {
|
787 |
+
mat `results'[1,`j'] = exp(`results'[1,`j'])
|
788 |
+
}
|
789 |
+
}
|
790 |
+
//return the results
|
791 |
+
ereturn matrix `prefix'expb = `results'
|
792 |
+
di _n as txt "added matrix:"
|
793 |
+
added_matrix `prefix'expb
|
794 |
+
end
|
795 |
+
|
796 |
+
* 15.
|
797 |
+
* -estadd- subroutine: partial and semi-partial correlations
|
798 |
+
program define estadd_pcorr, eclass
|
799 |
+
version 8.2
|
800 |
+
syntax [, semi Prefix(name) Replace Quietly ]
|
801 |
+
//check availability of e(sample)
|
802 |
+
confirm_esample
|
803 |
+
//check e()-names
|
804 |
+
if "`replace'"=="" {
|
805 |
+
if "`semi'"!="" confirm_new_ename `prefix'spcorr
|
806 |
+
confirm_new_ename `prefix'pcorr
|
807 |
+
}
|
808 |
+
//copy coefficients matrix and set to .z
|
809 |
+
tempname results results2
|
810 |
+
matrix `results' = e(b)
|
811 |
+
forv j = 1/`=colsof(`results')' {
|
812 |
+
mat `results'[1,`j'] = .z
|
813 |
+
}
|
814 |
+
local eqs: coleq `results', quoted
|
815 |
+
local eq: word 1 of `eqs'
|
816 |
+
mat `results2' = `results'[1,"`eq':"]
|
817 |
+
local vars: colnames `results2'
|
818 |
+
foreach var of local vars {
|
819 |
+
capt confirm numeric var `var'
|
820 |
+
if !_rc local temp "`temp'`var' "
|
821 |
+
}
|
822 |
+
local vars "`temp'"
|
823 |
+
if "`semi'"!="" mat `results2' = `results'
|
824 |
+
else {
|
825 |
+
mat drop `results2'
|
826 |
+
local results2
|
827 |
+
}
|
828 |
+
local depv: word 1 of `e(depvar)'
|
829 |
+
//compute statistics and add to results vector
|
830 |
+
local wtype `e(wtype)'
|
831 |
+
if inlist("`wtype'","pweight","iweight") local wtype aweight
|
832 |
+
_estadd_pcorr_compute `depv' `vars' [`wtype'`e(wexp)'] if e(sample), ///
|
833 |
+
eq(`eq') results(`results') results2(`results2')
|
834 |
+
//return the results
|
835 |
+
if "`semi'"!="" {
|
836 |
+
di as txt _n "added matrices:"
|
837 |
+
ereturn matrix `prefix'spcorr = `results2'
|
838 |
+
added_matrix `prefix'spcorr
|
839 |
+
}
|
840 |
+
else di as txt _n "added matrix:"
|
841 |
+
ereturn matrix `prefix'pcorr = `results'
|
842 |
+
added_matrix `prefix'pcorr
|
843 |
+
end
|
844 |
+
program define _estadd_pcorr_compute // based on pcorr.ado by StataCorp
|
845 |
+
// and pcorr2.ado by Richard Williams
|
846 |
+
syntax varlist(min=1) [aw fw] [if], eq(str) results(str) [ results2(str) ]
|
847 |
+
marksample touse
|
848 |
+
tempname hcurrent
|
849 |
+
_est hold `hcurrent', restore
|
850 |
+
quietly reg `varlist' [`weight'`exp'] if `touse'
|
851 |
+
if (e(N)==0 | e(N)>=.) error 2000
|
852 |
+
local NmK = e(df_r)
|
853 |
+
local R2 = e(r2)
|
854 |
+
gettoken depv varlist: varlist
|
855 |
+
foreach var of local varlist {
|
856 |
+
quietly test `var'
|
857 |
+
if r(F)<. {
|
858 |
+
local s "1"
|
859 |
+
if _b[`var']<0 local s "-1"
|
860 |
+
local c = colnumb(`results',"`eq':`var'")
|
861 |
+
mat `results'[1,`c'] = `s' * sqrt(r(F)/(r(F)+`NmK'))
|
862 |
+
if "`results2'"!="" {
|
863 |
+
mat `results2'[1,`c'] = `s' * sqrt(r(F)*((1-`R2')/`NmK'))
|
864 |
+
}
|
865 |
+
}
|
866 |
+
}
|
867 |
+
end
|
868 |
+
|
869 |
+
* 16.
|
870 |
+
* -estadd- subroutine: Likelihood-ratio test
|
871 |
+
program define estadd_lrtest, eclass
|
872 |
+
version 8.2
|
873 |
+
local caller : di _caller()
|
874 |
+
syntax anything(id="model") [, Name(name) Prefix(name) Replace Quietly * ]
|
875 |
+
if "`name'"=="" local name lrtest_
|
876 |
+
//check e()-names
|
877 |
+
if "`replace'"=="" {
|
878 |
+
confirm_new_ename `prefix'`name'p
|
879 |
+
confirm_new_ename `prefix'`name'chi2
|
880 |
+
confirm_new_ename `prefix'`name'df
|
881 |
+
}
|
882 |
+
//compute statistics
|
883 |
+
`quietly' version `caller': lrtest `anything', `options'
|
884 |
+
//return the results
|
885 |
+
ereturn scalar `prefix'`name'p = r(p)
|
886 |
+
ereturn scalar `prefix'`name'chi2 = r(chi2)
|
887 |
+
ereturn scalar `prefix'`name'df = r(df)
|
888 |
+
di _n as txt "added scalars:"
|
889 |
+
added_scalar `prefix'`name'p
|
890 |
+
added_scalar `prefix'`name'chi2
|
891 |
+
added_scalar `prefix'`name'df
|
892 |
+
end
|
893 |
+
|
894 |
+
* 17.
|
895 |
+
* -estadd- subroutine: support for -brant- by Long and Freese
|
896 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
897 |
+
program define estadd_brant, eclass
|
898 |
+
version 8.2
|
899 |
+
local caller : di _caller()
|
900 |
+
syntax [ , Prefix(name) Replace Quietly * ]
|
901 |
+
capt findfile brant.ado
|
902 |
+
if _rc {
|
903 |
+
di as error "fitstat.ado from the -spost9_ado- package by Long and Freese required"
|
904 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
905 |
+
error 499
|
906 |
+
}
|
907 |
+
// check names
|
908 |
+
if "`replace'"=="" {
|
909 |
+
foreach name in brant_chi2 brant_df brant_p brant {
|
910 |
+
confirm_new_ename `prefix'`name'
|
911 |
+
}
|
912 |
+
}
|
913 |
+
// compute and return the results
|
914 |
+
`quietly' version `caller': brant, `options'
|
915 |
+
di as txt _n "added scalars:"
|
916 |
+
foreach stat in chi2 df p {
|
917 |
+
ereturn scalar `prefix'brant_`stat' = r(`stat')
|
918 |
+
added_scalar `prefix'brant_`stat'
|
919 |
+
}
|
920 |
+
tempname mat
|
921 |
+
matrix `mat' = r(ivtests)
|
922 |
+
matrix `mat' = `mat''
|
923 |
+
ereturn matrix `prefix'brant = `mat'
|
924 |
+
di as txt _n "added matrix:"
|
925 |
+
added_matrix `prefix'brant _rown
|
926 |
+
end
|
927 |
+
|
928 |
+
* 18.
|
929 |
+
* -estadd- subroutine: support for -fitstat- by Long and Freese
|
930 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
931 |
+
program define estadd_fitstat, eclass
|
932 |
+
version 8.2
|
933 |
+
local caller : di _caller()
|
934 |
+
syntax [ , Prefix(name) Replace Quietly Bic * ]
|
935 |
+
capt findfile fitstat.ado
|
936 |
+
if _rc {
|
937 |
+
di as error "fitstat.ado from the -spost9_ado- package by Long and Freese required"
|
938 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
939 |
+
error 499
|
940 |
+
}
|
941 |
+
`quietly' version `caller': fitstat, `bic' `options'
|
942 |
+
local stats: r(scalars)
|
943 |
+
local allstats ///
|
944 |
+
dev dev_df lrx2 lrx2_df lrx2_p r2_adj r2_mf r2_mfadj r2_ml ///
|
945 |
+
r2_cu r2_mz r2_ef v_ystar v_error r2_ct r2_ctadj aic aic_n ///
|
946 |
+
bic bic_p statabic stataaic n_rhs n_parm
|
947 |
+
local stats: list allstats & stats
|
948 |
+
if "`bic'"!="" {
|
949 |
+
local bic aic aic_n bic bic_p statabic stataaic
|
950 |
+
local stats: list bic & stats
|
951 |
+
}
|
952 |
+
|
953 |
+
|
954 |
+
// check names
|
955 |
+
if "`replace'"=="" {
|
956 |
+
foreach stat of local stats {
|
957 |
+
if inlist("`stat'", "bic", "aic") local rname `stat'0
|
958 |
+
else local rname `stat'
|
959 |
+
confirm_new_ename `prefix'`rname'
|
960 |
+
}
|
961 |
+
}
|
962 |
+
|
963 |
+
// return the results
|
964 |
+
di as txt _n "added scalars:"
|
965 |
+
foreach stat of local stats {
|
966 |
+
if inlist("`stat'", "bic", "aic") local rname `stat'0
|
967 |
+
else local rname `stat'
|
968 |
+
ereturn scalar `prefix'`rname' = r(`stat')
|
969 |
+
added_scalar `prefix'`rname'
|
970 |
+
}
|
971 |
+
end
|
972 |
+
|
973 |
+
* 19.
|
974 |
+
* -estadd- subroutine: support for -listcoef- by Long and Freese
|
975 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
976 |
+
program define estadd_listcoef, eclass
|
977 |
+
version 8.2
|
978 |
+
local caller : di _caller()
|
979 |
+
syntax [anything] [ , Prefix(name) Replace Quietly ///
|
980 |
+
nosd gt lt ADJacent Matrix EXpand * ]
|
981 |
+
|
982 |
+
// handle some options and look for e(sample)
|
983 |
+
if `"`matrix'"'!="" {
|
984 |
+
local matrix matrix
|
985 |
+
}
|
986 |
+
if `"`e(cmd)'"'=="slogit" & "`expand'"!="" {
|
987 |
+
di as err "-expand- option not supported"
|
988 |
+
exit 198
|
989 |
+
}
|
990 |
+
confirm_esample
|
991 |
+
|
992 |
+
// set some constants
|
993 |
+
local listcoef_matrices "xs ys std fact facts pct pcts"
|
994 |
+
if "`sd'"=="" local listcoef_matrices "`listcoef_matrices' sdx"
|
995 |
+
|
996 |
+
// run listcoef
|
997 |
+
capt findfile listcoef.ado
|
998 |
+
if _rc {
|
999 |
+
di as error "-listcoef- from the -spost9_ado- package by Long and Freese required"
|
1000 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
1001 |
+
error 499
|
1002 |
+
}
|
1003 |
+
`quietly' version `caller': listcoef `anything' , matrix `gt' `lt' `adjacent' `options'
|
1004 |
+
|
1005 |
+
// check existing e()'s
|
1006 |
+
if "`replace'"=="" {
|
1007 |
+
confirm_new_ename `prefix'pvalue
|
1008 |
+
foreach matrix of local listcoef_matrices {
|
1009 |
+
_estadd_listcoef_ChkEName b_`matrix', prefix(`prefix')
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
// grab r()-results and post in e()
|
1014 |
+
di as txt _n "added matrices:"
|
1015 |
+
if inlist(`"`e(cmd)'"',"mlogit","mprobit") {
|
1016 |
+
_estadd_listcoef_AddResToNomModl `listcoef_matrices', prefix(`prefix') `gt' `lt' `adjacent'
|
1017 |
+
}
|
1018 |
+
else {
|
1019 |
+
foreach matrix of local listcoef_matrices {
|
1020 |
+
_estadd_listcoef_AddMatToE `matrix', prefix(`prefix')
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
end
|
1024 |
+
program define _estadd_listcoef_ChkEName
|
1025 |
+
syntax name [, prefix(str) ]
|
1026 |
+
capt confirm matrix r(`namelist')
|
1027 |
+
if _rc exit
|
1028 |
+
confirm_new_ename `prefix'`namelist'
|
1029 |
+
end
|
1030 |
+
program define _estadd_listcoef_AddMatToE, eclass
|
1031 |
+
syntax name [, prefix(str) ]
|
1032 |
+
capt confirm matrix r(b_`namelist')
|
1033 |
+
if _rc exit
|
1034 |
+
tempname tmp
|
1035 |
+
matrix `tmp' = r(b_`namelist')
|
1036 |
+
capt confirm matrix r(b2_`namelist')
|
1037 |
+
if _rc==0 {
|
1038 |
+
local eqnames: coleq e(b), quoted
|
1039 |
+
local eqnames: list uniq eqnames
|
1040 |
+
local eqname: word 1 of `eqnames'
|
1041 |
+
mat coleq `tmp' = `"`eqname'"'
|
1042 |
+
tempname tmp2
|
1043 |
+
matrix `tmp2' = r(b2_`namelist')
|
1044 |
+
local eqname: word 2 of `eqnames'
|
1045 |
+
mat coleq `tmp2' = `"`eqname'"'
|
1046 |
+
mat `tmp' = `tmp' , `tmp2'
|
1047 |
+
mat drop `tmp2'
|
1048 |
+
}
|
1049 |
+
ereturn matrix `prefix'b_`namelist' = `tmp'
|
1050 |
+
added_matrix `prefix'b_`namelist' _rown
|
1051 |
+
end
|
1052 |
+
program define _estadd_listcoef_AddResToNomModl, eclass
|
1053 |
+
syntax anything(name=listcoef_matrices) [, prefix(str) gt lt ADJacent ]
|
1054 |
+
if "`lt'"=="" & "`gt'"=="" {
|
1055 |
+
local lt lt
|
1056 |
+
local gt gt
|
1057 |
+
}
|
1058 |
+
local adjacent = "`adjacent'"!=""
|
1059 |
+
local lt = "`lt'"!=""
|
1060 |
+
local gt = "`gt'"!=""
|
1061 |
+
|
1062 |
+
// outcomes and labels
|
1063 |
+
tempname outcomes
|
1064 |
+
if `"`e(cmd)'"'=="mlogit" {
|
1065 |
+
if c(stata_version) < 9 local type cat
|
1066 |
+
else local type out
|
1067 |
+
mat `outcomes' = e(`type')
|
1068 |
+
local noutcomes = colsof(`outcomes')
|
1069 |
+
local eqnames `"`e(eqnames)'"'
|
1070 |
+
if (`:list sizeof eqnames'<`noutcomes') {
|
1071 |
+
local ibase = e(ibase`type')
|
1072 |
+
}
|
1073 |
+
else local ibase 0
|
1074 |
+
forv i = 1/`noutcomes' {
|
1075 |
+
if `i'==`ibase' {
|
1076 |
+
local outcomelab`i' `"`e(baselab)'"'
|
1077 |
+
}
|
1078 |
+
else {
|
1079 |
+
gettoken eq eqnames : eqnames
|
1080 |
+
local outcomelab`i' `"`eq'"'
|
1081 |
+
}
|
1082 |
+
if `"`outcomelab`i''"'=="" {
|
1083 |
+
local outcomelab`i': di `outcomes'[1,`i']
|
1084 |
+
}
|
1085 |
+
}
|
1086 |
+
}
|
1087 |
+
else if `"`e(cmd)'"'=="mprobit" {
|
1088 |
+
mat `outcomes' = e(outcomes)'
|
1089 |
+
local noutcomes = colsof(`outcomes')
|
1090 |
+
forv i = 1/`noutcomes' {
|
1091 |
+
local outcomelab`i' `"`e(out`i')'"'
|
1092 |
+
}
|
1093 |
+
}
|
1094 |
+
else {
|
1095 |
+
di as err `"`e(cmd)' not supported"'
|
1096 |
+
exit 499
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
// collect vectors
|
1100 |
+
tempname stats
|
1101 |
+
mat `stats' = r(b) \ r(b_z) \ r(b_z) \ r(b_p)
|
1102 |
+
forv i = 1/`=colsof(`stats')' {
|
1103 |
+
mat `stats'[2,`i'] = `stats'[1,`i'] / `stats'[3,`i']
|
1104 |
+
}
|
1105 |
+
mat rown `stats' = "b" "se" "z" "P>|z|"
|
1106 |
+
local enames "b_raw b_se b_z b_p"
|
1107 |
+
foreach matrix of local listcoef_matrices {
|
1108 |
+
capt confirm matrix r(b_`matrix')
|
1109 |
+
if _rc continue
|
1110 |
+
mat `stats' = `stats' \ r(b_`matrix')
|
1111 |
+
local enames `"`enames' b_`matrix'"'
|
1112 |
+
}
|
1113 |
+
|
1114 |
+
// select/reorder contrasts of interest
|
1115 |
+
local contrast "r(contrast)"
|
1116 |
+
local ncontrast = colsof(`contrast')
|
1117 |
+
tempname stats0 temp
|
1118 |
+
matrix rename `stats' `stats0'
|
1119 |
+
forv i = 1/`noutcomes' {
|
1120 |
+
local out1 = `outcomes'[1, `i']
|
1121 |
+
local j 0
|
1122 |
+
forv j = 1/`noutcomes' {
|
1123 |
+
local out2 = `outcomes'[1, `j']
|
1124 |
+
if `out1'==`out2' continue
|
1125 |
+
if `adjacent' & abs(`i'-`j')>1 continue
|
1126 |
+
if `lt'==0 & `out1'<`out2' continue
|
1127 |
+
if `gt'==0 & `out1'>`out2' continue
|
1128 |
+
forv l = 1/`ncontrast' {
|
1129 |
+
if el(`contrast',1,`l')!=`out1' continue
|
1130 |
+
if el(`contrast',2,`l')!=`out2' continue
|
1131 |
+
mat `temp' = `stats0'[1..., `l']
|
1132 |
+
mat coleq `temp' = `"`outcomelab`i''-`outcomelab`j''"'
|
1133 |
+
mat `stats' = nullmat(`stats'), `temp'
|
1134 |
+
}
|
1135 |
+
}
|
1136 |
+
}
|
1137 |
+
capt mat drop `stats0'
|
1138 |
+
|
1139 |
+
// post rows to e()
|
1140 |
+
local i 0
|
1141 |
+
foreach ename of local enames {
|
1142 |
+
local ++i
|
1143 |
+
mat `temp' = `stats'[`i', 1...]
|
1144 |
+
ereturn matrix `prefix'`ename' = `temp'
|
1145 |
+
added_matrix `prefix'`ename' _rown
|
1146 |
+
}
|
1147 |
+
end
|
1148 |
+
|
1149 |
+
* 20.
|
1150 |
+
* -estadd- subroutine: support for -mlogtest- by Long and Freese
|
1151 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
1152 |
+
program define estadd_mlogtest, eclass
|
1153 |
+
version 8.2
|
1154 |
+
local caller : di _caller()
|
1155 |
+
syntax [anything] [ , Prefix(name) Replace Quietly set(passthru) * ]
|
1156 |
+
`quietly' version `caller': mlogtest `anything' , `set' `options'
|
1157 |
+
local rmat: r(matrices)
|
1158 |
+
|
1159 |
+
// check names
|
1160 |
+
if `"`replace'"'=="" {
|
1161 |
+
foreach m in combine lrcomb {
|
1162 |
+
if `:list m in rmat'==0 continue
|
1163 |
+
forv r = 1/`=rowsof(r(`m'))' {
|
1164 |
+
local cat1 = el(r(`m'),`r',1)
|
1165 |
+
local cat2 = el(r(`m'),`r',2)
|
1166 |
+
confirm_new_ename `prefix'`m'_`cat1'_`cat2'_chi2
|
1167 |
+
confirm_new_ename `prefix'`m'_`cat1'_`cat2'_df
|
1168 |
+
confirm_new_ename `prefix'`m'_`cat1'_`cat2'_p
|
1169 |
+
}
|
1170 |
+
}
|
1171 |
+
foreach m in hausman suest smhsiao {
|
1172 |
+
if `:list m in rmat'==0 continue
|
1173 |
+
forv r = 1/`=rowsof(r(`m'))' {
|
1174 |
+
local cat = el(r(`m'),`r',1)
|
1175 |
+
confirm_new_ename `prefix'`m'_`cat'_chi2
|
1176 |
+
confirm_new_ename `prefix'`m'_`cat'_df
|
1177 |
+
confirm_new_ename `prefix'`m'_`cat'_p
|
1178 |
+
}
|
1179 |
+
}
|
1180 |
+
if `"`set'"'!="" {
|
1181 |
+
foreach m in wald lrtest {
|
1182 |
+
if `:list m in rmat'==0 continue
|
1183 |
+
local i 0
|
1184 |
+
local r = rownumb(r(`m'),"set_`++i'")
|
1185 |
+
while(`r'<.) {
|
1186 |
+
confirm_new_ename `prefix'`m'_set`i'_chi2
|
1187 |
+
confirm_new_ename `prefix'`m'_set`i'_df
|
1188 |
+
confirm_new_ename `prefix'`m'_set`i'_p
|
1189 |
+
local r = rownumb(r(`m'),"set_`++i'")
|
1190 |
+
}
|
1191 |
+
}
|
1192 |
+
}
|
1193 |
+
foreach m in wald lrtest {
|
1194 |
+
if `:list m in rmat'==0 continue
|
1195 |
+
local r .
|
1196 |
+
if `"`set'"'!="" local r = rownumb(r(`m'),"set_1")-1
|
1197 |
+
if `r'<1 continue
|
1198 |
+
confirm_new_ename `prefix'`m'
|
1199 |
+
}
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
local di_added_scalars `"di _n as txt "added scalars:"'
|
1203 |
+
// combine
|
1204 |
+
foreach m in combine lrcomb {
|
1205 |
+
if `:list m in rmat'==0 continue
|
1206 |
+
`di_added_scalars'
|
1207 |
+
local di_added_scalars
|
1208 |
+
forv r = 1/`=rowsof(r(`m'))' {
|
1209 |
+
local cat1 = el(r(`m'),`r',1)
|
1210 |
+
local cat2 = el(r(`m'),`r',2)
|
1211 |
+
eret scalar `prefix'`m'_`cat1'_`cat2'_chi2 = el(r(`m'),`r',3)
|
1212 |
+
added_scalar `prefix'`m'_`cat1'_`cat2'_chi2
|
1213 |
+
eret scalar `prefix'`m'_`cat1'_`cat2'_df = el(r(`m'),`r',4)
|
1214 |
+
added_scalar `prefix'`m'_`cat1'_`cat2'_df
|
1215 |
+
eret scalar `prefix'`m'_`cat1'_`cat2'_p = el(r(`m'),`r',5)
|
1216 |
+
added_scalar `prefix'`m'_`cat1'_`cat2'_p
|
1217 |
+
}
|
1218 |
+
}
|
1219 |
+
// iia
|
1220 |
+
foreach m in hausman suest smhsiao {
|
1221 |
+
if `:list m in rmat'==0 continue
|
1222 |
+
`di_added_scalars'
|
1223 |
+
local di_added_scalars
|
1224 |
+
if "`m'"=="smhsiao" local skip 2
|
1225 |
+
else local skip 0
|
1226 |
+
forv r = 1/`=rowsof(r(`m'))' {
|
1227 |
+
local cat = el(r(`m'),`r',1)
|
1228 |
+
eret scalar `prefix'`m'_`cat'_chi2 = el(r(`m'),`r',2+`skip')
|
1229 |
+
added_scalar `prefix'`m'_`cat'_chi2
|
1230 |
+
eret scalar `prefix'`m'_`cat'_df = el(r(`m'),`r',3+`skip')
|
1231 |
+
added_scalar `prefix'`m'_`cat'_df
|
1232 |
+
eret scalar `prefix'`m'_`cat'_p = el(r(`m'),`r',4+`skip')
|
1233 |
+
added_scalar `prefix'`m'_`cat'_p
|
1234 |
+
}
|
1235 |
+
}
|
1236 |
+
|
1237 |
+
// wald/lrtest
|
1238 |
+
tempname tmp
|
1239 |
+
if `"`set'"'!="" {
|
1240 |
+
foreach m in wald lrtest {
|
1241 |
+
if `:list m in rmat'==0 continue
|
1242 |
+
local i 0
|
1243 |
+
local r = rownumb(r(`m'),"set_`++i'")
|
1244 |
+
if `r'>=. continue
|
1245 |
+
`di_added_scalars'
|
1246 |
+
local di_added_scalars
|
1247 |
+
while(`r'<.) {
|
1248 |
+
eret scalar `prefix'`m'_set`i'_chi2 = el(r(`m'),`r',1)
|
1249 |
+
added_scalar `prefix'`m'_set`i'_chi2
|
1250 |
+
eret scalar `prefix'`m'_set`i'_df = el(r(`m'),`r',2)
|
1251 |
+
added_scalar `prefix'`m'_set`i'_df
|
1252 |
+
eret scalar `prefix'`m'_set`i'_p = el(r(`m'),`r',3)
|
1253 |
+
added_scalar `prefix'`m'_set`i'_p
|
1254 |
+
local r = rownumb(r(`m'),"set_`++i'")
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
local di_added_matrices `"di _n as txt "added matrices:"'
|
1259 |
+
foreach m in wald lrtest {
|
1260 |
+
if `:list m in rmat'==0 continue
|
1261 |
+
local r .
|
1262 |
+
if `"`set'"'!="" local r = rownumb(r(`m'),"set_1")-1
|
1263 |
+
if `r'<1 continue
|
1264 |
+
`di_added_matrices'
|
1265 |
+
local di_added_matrices
|
1266 |
+
mat `tmp' = r(`m')
|
1267 |
+
mat `tmp' = `tmp'[1..`r',1...]'
|
1268 |
+
eret mat `prefix'`m' = `tmp'
|
1269 |
+
added_matrix `prefix'`m' _rown
|
1270 |
+
}
|
1271 |
+
|
1272 |
+
end
|
1273 |
+
|
1274 |
+
|
1275 |
+
* 21.
|
1276 |
+
* -estadd- subroutine: support for -prchange- by Long and Freese
|
1277 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
1278 |
+
program define estadd_prchange
|
1279 |
+
version 8.2
|
1280 |
+
local caller : di _caller()
|
1281 |
+
syntax [anything] [if] [in] [ , Prefix(name) Replace Quietly ///
|
1282 |
+
PAttern(str) Binary(str) Continuous(str) NOAvg Avg split SPLIT2(name) ///
|
1283 |
+
adapt /// old syntax; now works as synonym for noavg
|
1284 |
+
Outcome(passthru) Fromto noBAse * ]
|
1285 |
+
|
1286 |
+
// handle some options
|
1287 |
+
if `"`split2'"'!="" local split split
|
1288 |
+
if "`split'"!="" & `"`outcome'"'!="" {
|
1289 |
+
di as err "split and outcome() not both allowed"
|
1290 |
+
exit 198
|
1291 |
+
}
|
1292 |
+
if "`split'"!="" & `"`avg'`noavg'"'!="" {
|
1293 |
+
di as err "split and avg not both allowed"
|
1294 |
+
exit 198
|
1295 |
+
}
|
1296 |
+
if "`avg'"!="" & `"`outcome'"'!="" {
|
1297 |
+
di as err "avg and outcome not both allowed"
|
1298 |
+
exit 198
|
1299 |
+
}
|
1300 |
+
if "`avg'"!="" & "`noavg'"!="" {
|
1301 |
+
di as err "avg and noavg not both allowed"
|
1302 |
+
exit 198
|
1303 |
+
}
|
1304 |
+
if `"`adapt'"'!="" local noavg noavg
|
1305 |
+
if `:list sizeof binary'>1 | `:list sizeof continuous'>1 error 198
|
1306 |
+
estadd_prchange_ExpandType binary `"`binary'"'
|
1307 |
+
estadd_prchange_ExpandType continuous `"`continuous'"'
|
1308 |
+
if `"`binary'"'=="" local binary 2
|
1309 |
+
if `"`continuous'"'=="" local continuous 4
|
1310 |
+
if `"`pattern'"'!="" {
|
1311 |
+
estadd_prchange_ExpandType pattern `"`pattern'"'
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
// check e(sample)
|
1315 |
+
confirm_esample
|
1316 |
+
|
1317 |
+
// run prchange
|
1318 |
+
capt findfile prchange.ado
|
1319 |
+
if _rc {
|
1320 |
+
di as error "-prchange- from the -spost9_ado- package by Long and Freese required"
|
1321 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
1322 |
+
error 499
|
1323 |
+
}
|
1324 |
+
`quietly' version `caller': prchange `anything' `if' `in', `base' `outcome' `fromto' `options'
|
1325 |
+
|
1326 |
+
// determine type of model (ordinal: nomord = 1; nominal: nomord = 2)
|
1327 |
+
local nomord = (r(modeltype)=="typical nomord")
|
1328 |
+
if inlist(`"`e(cmd)'"',"mlogit","mprobit") local nomord = 2
|
1329 |
+
if "`avg'`noavg'"!="" {
|
1330 |
+
if `nomord'==0 {
|
1331 |
+
di as err "avg not allowed with this model"
|
1332 |
+
exit 198
|
1333 |
+
}
|
1334 |
+
}
|
1335 |
+
if !`nomord' & "`split'"!="" {
|
1336 |
+
di as err "split not allowed with this model"
|
1337 |
+
exit 198
|
1338 |
+
}
|
1339 |
+
|
1340 |
+
// determine outcome number (in prchange-returns)
|
1341 |
+
if `"`outcome'"'!="" {
|
1342 |
+
if `nomord' {
|
1343 |
+
forv i = 1/`=colsof(r(catval))' {
|
1344 |
+
if el(r(catval), 1, `i') == r(outcome) {
|
1345 |
+
local outcomenum `i'
|
1346 |
+
continue, break
|
1347 |
+
}
|
1348 |
+
}
|
1349 |
+
if "`outcomenum'"=="" { // should never happen
|
1350 |
+
di as err `"outcome `outcome' not found"'
|
1351 |
+
exit 499
|
1352 |
+
}
|
1353 |
+
}
|
1354 |
+
else {
|
1355 |
+
local outcomenum = colnumb(r(predval), `"`r(outcome)'"')
|
1356 |
+
}
|
1357 |
+
}
|
1358 |
+
|
1359 |
+
// check names
|
1360 |
+
if "`replace'"=="" {
|
1361 |
+
if `"`outcome'"'!="" | "`split'"!="" | `nomord'==0 {
|
1362 |
+
confirm_new_ename `prefix'predval
|
1363 |
+
if `"`outcome'"'!="" | "`split'"!="" {
|
1364 |
+
confirm_new_ename `prefix'outcome
|
1365 |
+
}
|
1366 |
+
}
|
1367 |
+
else {
|
1368 |
+
forv i = 1/`=colsof(r(catval))' {
|
1369 |
+
local theoutcome: di el(r(catval),1,`i')
|
1370 |
+
confirm_new_ename `prefix'predval`theoutcome'
|
1371 |
+
}
|
1372 |
+
}
|
1373 |
+
confirm_new_ename `prefix'delta
|
1374 |
+
confirm_new_ename `prefix'centered
|
1375 |
+
confirm_new_ename `prefix'dc
|
1376 |
+
if "`fromto'"!="" {
|
1377 |
+
confirm_new_ename `prefix'dcfrom
|
1378 |
+
confirm_new_ename `prefix'dcto
|
1379 |
+
}
|
1380 |
+
if "`nobase'"=="" {
|
1381 |
+
confirm_new_ename `prefix'X
|
1382 |
+
}
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
// grab r()-results and post in e()
|
1386 |
+
if "`split'"!="" {
|
1387 |
+
if `"`split2'"'=="" {
|
1388 |
+
local split2 `"`e(_estadd_estimates_name)'"'
|
1389 |
+
if `"`split2'"'=="" {
|
1390 |
+
local split2 `"`e(cmd)'"'
|
1391 |
+
}
|
1392 |
+
local split2 `"`split2'_"'
|
1393 |
+
}
|
1394 |
+
_estadd_prchange_StoreEachOutc `split2' , nomord(`nomord') ///
|
1395 |
+
pattern(`pattern') binary(`binary') continuous(`continuous') ///
|
1396 |
+
`base' `fromto' prefix(`prefix')
|
1397 |
+
}
|
1398 |
+
else {
|
1399 |
+
_estadd_prchange_AddStuffToE, nomord(`nomord') outcome(`outcomenum') ///
|
1400 |
+
pattern(`pattern') binary(`binary') continuous(`continuous') ///
|
1401 |
+
`avg' `noavg' `base' `fromto' prefix(`prefix')
|
1402 |
+
}
|
1403 |
+
end
|
1404 |
+
program estadd_prchange_ExpandType
|
1405 |
+
args name list
|
1406 |
+
foreach l of local list {
|
1407 |
+
local w = length(`"`l'"')
|
1408 |
+
if `"`l'"'==substr("minmax",1,max(2,`w')) local type 1
|
1409 |
+
else if `"`l'"'==substr("01",1,max(1,`w')) local type 2
|
1410 |
+
else if `"`l'"'==substr("delta",1,max(1,`w')) local type 3
|
1411 |
+
else if `"`l'"'==substr("sd",1,max(1,`w')) local type 4
|
1412 |
+
else if `"`l'"'==substr("margefct",1,max(1,`w')) local type 5
|
1413 |
+
else {
|
1414 |
+
di as err `"'`l'' not allowed"'
|
1415 |
+
exit 198
|
1416 |
+
}
|
1417 |
+
local newlist `newlist' `type'
|
1418 |
+
}
|
1419 |
+
c_local `name' `newlist'
|
1420 |
+
end
|
1421 |
+
program define _estadd_prchange_AddStuffToE, eclass
|
1422 |
+
// input add
|
1423 |
+
// ========================= ========================================
|
1424 |
+
// outcome() nomord opt change changenm change# predval outcome
|
1425 |
+
// no 0 - x last
|
1426 |
+
// yes 0 - x x x
|
1427 |
+
// no 1/2 - x all all
|
1428 |
+
// yes 1/2 - x x x
|
1429 |
+
// no 1/2 avg x all
|
1430 |
+
// no 1/2 noavg all all
|
1431 |
+
// nobase=="" => add X, SD, Min, Max
|
1432 |
+
// all models => add centered, delta
|
1433 |
+
syntax , nomord(str) [ pattern(passthru) binary(passthru) continuous(passthru) ///
|
1434 |
+
outcome(str) NOAVG avg nobase fromto prefix(str) split ] //
|
1435 |
+
// prepare predval and determine value of outcome
|
1436 |
+
if `"`outcome'"'!="" {
|
1437 |
+
tempname predv
|
1438 |
+
mat `predv' = r(predval)
|
1439 |
+
mat `predv' = `predv'[1...,`outcome']
|
1440 |
+
if `nomord' {
|
1441 |
+
local theoutcome: di el(r(catval),1,`outcome')
|
1442 |
+
}
|
1443 |
+
else {
|
1444 |
+
local theoutcome: colnames `predv'
|
1445 |
+
}
|
1446 |
+
}
|
1447 |
+
// add scalars
|
1448 |
+
di _n as txt "added scalars:"
|
1449 |
+
// - predval and outcome
|
1450 |
+
local cpredval = colsof(r(predval))
|
1451 |
+
if `"`outcome'"'!="" {
|
1452 |
+
ereturn scalar `prefix'predval = `predv'[1,1]
|
1453 |
+
added_scalar `prefix'predval `"`lab_predval'"'
|
1454 |
+
ereturn scalar `prefix'outcome = `theoutcome'
|
1455 |
+
added_scalar `prefix'outcome
|
1456 |
+
}
|
1457 |
+
else if `nomord' { // add all
|
1458 |
+
forv i=1/`cpredval' {
|
1459 |
+
local theoutcome: di el(r(catval),1,`i')
|
1460 |
+
ereturn scalar `prefix'predval`theoutcome' = el(r(predval),1,`i')
|
1461 |
+
added_scalar `prefix'predval`theoutcome'
|
1462 |
+
}
|
1463 |
+
}
|
1464 |
+
else { // add last
|
1465 |
+
ereturn scalar `prefix'predval = el(r(predval),1,`cpredval')
|
1466 |
+
added_scalar `prefix'predval
|
1467 |
+
}
|
1468 |
+
// - delta and centered
|
1469 |
+
ereturn scalar `prefix'delta = r(delta)
|
1470 |
+
added_scalar `prefix'delta
|
1471 |
+
ereturn scalar `prefix'centered = r(centered)
|
1472 |
+
added_scalar `prefix'centered
|
1473 |
+
// add matrices
|
1474 |
+
di _n as txt "added matrices:"
|
1475 |
+
if `nomord'==0 {
|
1476 |
+
if r(modeltype)=="twoeq count" & "`test'"=="" {
|
1477 |
+
local eq: coleq e(b)
|
1478 |
+
local eq: word 1 of `eq'
|
1479 |
+
}
|
1480 |
+
_estadd_prchange_PostMat r(change), prefix(`prefix') ///
|
1481 |
+
name(dc) `pattern' `binary' `continuous' `fromto' eq(`eq')
|
1482 |
+
}
|
1483 |
+
else {
|
1484 |
+
if `"`outcome'"'=="" {
|
1485 |
+
if "`avg'"!="" local nomordmat "r(changemn)"
|
1486 |
+
else {
|
1487 |
+
tempname nomordmat
|
1488 |
+
_estadd_prchange_GatherNomChMat `nomordmat' `noavg'
|
1489 |
+
}
|
1490 |
+
_estadd_prchange_PostMat `nomordmat', prefix(`prefix') ///
|
1491 |
+
name(dc) `pattern' `binary' `continuous' `fromto'
|
1492 |
+
}
|
1493 |
+
else {
|
1494 |
+
if `nomord'==2 {
|
1495 |
+
_estadd_prchange_GetEqnmNomModl `theoutcome'
|
1496 |
+
}
|
1497 |
+
if `"`split'"'!="" {
|
1498 |
+
_estadd_prchange_PostMat r(change`theoutcome'), prefix(`prefix') ///
|
1499 |
+
name(dc) `pattern' `binary' `continuous' `fromto' eq(`eq')
|
1500 |
+
}
|
1501 |
+
else {
|
1502 |
+
_estadd_prchange_PostMat r(change), prefix(`prefix') ///
|
1503 |
+
name(dc) `pattern' `binary' `continuous' `fromto' eq(`eq')
|
1504 |
+
}
|
1505 |
+
}
|
1506 |
+
}
|
1507 |
+
if `"`base'"'=="" {
|
1508 |
+
_estadd_prchange_PostMat r(baseval), prefix(`prefix') name(X)
|
1509 |
+
}
|
1510 |
+
if `"`pattern'"'=="" {
|
1511 |
+
_estadd_prchange_dcNote, prefix(`prefix') name(dc) `binary' `continuous'
|
1512 |
+
}
|
1513 |
+
end
|
1514 |
+
program define _estadd_prchange_dcNote
|
1515 |
+
syntax [ , prefix(str) name(str) binary(str) continuous(str) ]
|
1516 |
+
local res `""{res:minmax} change" "{res:01} change" "{res:delta} change" "{res:sd} change" "{res:margefct}""'
|
1517 |
+
local bres: word `binary' of `res'
|
1518 |
+
local cres: word `continuous' of `res'
|
1519 |
+
di _n as txt `"first row in e(dc) contains:"'
|
1520 |
+
di _n `" `bres' for binary variables"'
|
1521 |
+
di `" `cres' for continuous variables"'
|
1522 |
+
end
|
1523 |
+
program define _estadd_prchange_PostMat, eclass
|
1524 |
+
syntax anything, name(str) [ Fromto eq(str) prefix(str) ///
|
1525 |
+
pattern(passthru) binary(passthru) continuous(passthru) ]
|
1526 |
+
capt confirm matrix `anything'
|
1527 |
+
if _rc exit
|
1528 |
+
tempname tmp1
|
1529 |
+
local nmlist "`name'"
|
1530 |
+
matrix `tmp1' = `anything'
|
1531 |
+
if `"`eq'"'!="" {
|
1532 |
+
mat coleq `tmp1' = `"`eq'"'
|
1533 |
+
}
|
1534 |
+
if `"`pattern'`binary'`continuous'"'!="" {
|
1535 |
+
tempname pattmat
|
1536 |
+
_estadd_prchange_Merge `tmp1', pattmat(`pattmat') `pattern' `binary' `continuous' `fromto'
|
1537 |
+
}
|
1538 |
+
if "`fromto'"!="" {
|
1539 |
+
local nmlist "`nmlist' `name'from `name'to"
|
1540 |
+
tempname tmp tmp2 tmp3
|
1541 |
+
mat rename `tmp1' `tmp'
|
1542 |
+
local r = rowsof(`tmp')
|
1543 |
+
local i = 1
|
1544 |
+
while (`i'<=`r') {
|
1545 |
+
if (`r'-`i')>=2 {
|
1546 |
+
mat `tmp2' = nullmat(`tmp2') \ `tmp'[`i++',1...] // from
|
1547 |
+
mat `tmp3' = nullmat(`tmp3') \ `tmp'[`i++',1...] // to
|
1548 |
+
}
|
1549 |
+
mat `tmp1' = nullmat(`tmp1') \ `tmp'[`i++',1...]
|
1550 |
+
}
|
1551 |
+
mat drop `tmp'
|
1552 |
+
}
|
1553 |
+
local i 0
|
1554 |
+
foreach nm of local nmlist {
|
1555 |
+
local ++i
|
1556 |
+
local rown: rown `tmp`i''
|
1557 |
+
mat rown `tmp`i'' = `rown' // fix problem with leading blanks in equations
|
1558 |
+
ereturn matrix `prefix'`nm' = `tmp`i''
|
1559 |
+
added_matrix `prefix'`nm' _rown
|
1560 |
+
}
|
1561 |
+
if `"`pattmat'"'!="" {
|
1562 |
+
ereturn matrix `prefix'pattern = `pattmat'
|
1563 |
+
added_matrix `prefix'pattern
|
1564 |
+
}
|
1565 |
+
end
|
1566 |
+
program define _estadd_prchange_Merge
|
1567 |
+
syntax name(name=tmp1) [, pattmat(str) pattern(str) binary(str) continuous(str) fromto ]
|
1568 |
+
tempname tmp
|
1569 |
+
mat rename `tmp1' `tmp'
|
1570 |
+
local r = cond("`fromto'"!="", 3, 1)
|
1571 |
+
mat `tmp1' = `tmp'[1..`r',1...]*.
|
1572 |
+
mat `pattmat' = `tmp'[1,1...]*.
|
1573 |
+
local rtot = rowsof(`tmp')
|
1574 |
+
mat rown `tmp1' = main
|
1575 |
+
mat rown `pattmat' = :type
|
1576 |
+
local vars: colnames `tmp1'
|
1577 |
+
local eqs: coleq `tmp1', quoted
|
1578 |
+
local j 0
|
1579 |
+
foreach var of local vars {
|
1580 |
+
local ++j
|
1581 |
+
gettoken eq eqs : eqs
|
1582 |
+
if `"`eq'"'!=`"`lasteq'"' gettoken type rest : pattern
|
1583 |
+
else gettoken type rest : rest
|
1584 |
+
local lasteq `"`eq'"'
|
1585 |
+
if `"`type'"'=="" {
|
1586 |
+
capt assert `var'==0|`var'==1 if e(sample) & `var'<.
|
1587 |
+
if _rc local type `continuous'
|
1588 |
+
else local type `binary'
|
1589 |
+
}
|
1590 |
+
local ii = (`type'-1)*`r'+1
|
1591 |
+
forv i = 1/`r' {
|
1592 |
+
if `r'>1 & `i'<3 & `ii'>=`rtot' {
|
1593 |
+
mat `tmp1'[`i',`j'] = .z
|
1594 |
+
}
|
1595 |
+
else {
|
1596 |
+
mat `tmp1'[`i',`j'] = `tmp'[`ii++',`j']
|
1597 |
+
}
|
1598 |
+
}
|
1599 |
+
mat `pattmat'[1,`j'] = `type'
|
1600 |
+
}
|
1601 |
+
mat `tmp1' = `tmp1' \ `tmp'
|
1602 |
+
end
|
1603 |
+
program define _estadd_prchange_GatherNomChMat
|
1604 |
+
args mat noavg
|
1605 |
+
local cmd `"`e(cmd)'"'
|
1606 |
+
tempname tmpmat
|
1607 |
+
if `"`noavg'"'=="" {
|
1608 |
+
mat `tmpmat' = r(changemn)
|
1609 |
+
mat coleq `tmpmat' = `"Avg|Chg|"'
|
1610 |
+
mat `mat' = `tmpmat'
|
1611 |
+
}
|
1612 |
+
if `"`cmd'"'=="mlogit" {
|
1613 |
+
if c(stata_version) < 9 local outcat cat
|
1614 |
+
else local outcat out
|
1615 |
+
local k_cat = e(k_`outcat')
|
1616 |
+
local eqnames `"`e(eqnames)'"'
|
1617 |
+
if `k_cat'>`:list sizeof eqnames' { // no base equation
|
1618 |
+
local ibase = e(ibase`outcat')
|
1619 |
+
local baselab `"`e(baselab)'"'
|
1620 |
+
if `"`baselab'"'=="" {
|
1621 |
+
local baselab `"`e(base`outcat')'"'
|
1622 |
+
}
|
1623 |
+
forv i = 1/`k_cat' {
|
1624 |
+
if `i'==`ibase' {
|
1625 |
+
local eq `"`"`baselab'"'"'
|
1626 |
+
}
|
1627 |
+
else gettoken eq eqnames : eqnames, quotes
|
1628 |
+
local temp `"`temp' `eq'"'
|
1629 |
+
}
|
1630 |
+
local eqnames: list retok temp
|
1631 |
+
}
|
1632 |
+
local i 0
|
1633 |
+
foreach eq of local eqnames {
|
1634 |
+
local ++i
|
1635 |
+
local theoutcome: di el(e(`outcat'),1,`i')
|
1636 |
+
mat `tmpmat' = r(change`theoutcome')
|
1637 |
+
mat coleq `tmpmat' = `"`eq'"'
|
1638 |
+
mat `mat' = nullmat(`mat'), `tmpmat'
|
1639 |
+
}
|
1640 |
+
}
|
1641 |
+
else if `"`cmd'"'=="mprobit" {
|
1642 |
+
local eqnames `"`e(outeqs)'"'
|
1643 |
+
local i 0
|
1644 |
+
foreach eq of local eqnames {
|
1645 |
+
local ++i
|
1646 |
+
local theoutcome: di el(e(outcomes),`i',1)
|
1647 |
+
mat `tmpmat' = r(change`theoutcome')
|
1648 |
+
mat coleq `tmpmat' = `"`eq'"'
|
1649 |
+
mat `mat' = nullmat(`mat'), `tmpmat'
|
1650 |
+
}
|
1651 |
+
}
|
1652 |
+
else { // ordered models
|
1653 |
+
local eqnames : colnames r(catval)
|
1654 |
+
local i 0
|
1655 |
+
foreach eq of local eqnames {
|
1656 |
+
local ++i
|
1657 |
+
local theoutcome: di el(r(catval),1,`i')
|
1658 |
+
mat `tmpmat' = r(change`theoutcome')
|
1659 |
+
mat coleq `tmpmat' = `"`eq'"'
|
1660 |
+
mat `mat' = nullmat(`mat'), `tmpmat'
|
1661 |
+
}
|
1662 |
+
}
|
1663 |
+
end
|
1664 |
+
program define _estadd_prchange_GetEqnmNomModl
|
1665 |
+
args theoutcome
|
1666 |
+
local cmd `"`e(cmd)'"'
|
1667 |
+
if `"`cmd'"'=="mlogit" {
|
1668 |
+
if c(stata_version) < 9 local outcat cat
|
1669 |
+
else local outcat out
|
1670 |
+
local k_cat = e(k_`outcat')
|
1671 |
+
local eqnames `"`e(eqnames)'"'
|
1672 |
+
local nobase = (`k_cat'>`:list sizeof eqnames')
|
1673 |
+
if `nobase' {
|
1674 |
+
local ibase = e(ibase`outcat')
|
1675 |
+
local baselab `"`e(baselab)'"'
|
1676 |
+
}
|
1677 |
+
forv i = 1/`k_cat' {
|
1678 |
+
if `nobase' {
|
1679 |
+
if `i'==`ibase' {
|
1680 |
+
local eq `"`baselab'"'
|
1681 |
+
}
|
1682 |
+
else gettoken eq eqnames : eqnames
|
1683 |
+
}
|
1684 |
+
else gettoken eq eqnames : eqnames
|
1685 |
+
if el(e(`outcat'),1,`i')==`theoutcome' {
|
1686 |
+
local value `"`eq'"'
|
1687 |
+
continue, break
|
1688 |
+
}
|
1689 |
+
}
|
1690 |
+
}
|
1691 |
+
else if `"`cmd'"'=="mprobit" {
|
1692 |
+
local eqnames `"`e(outeqs)'"'
|
1693 |
+
local i 0
|
1694 |
+
foreach eq of local eqnames {
|
1695 |
+
if el(e(outcomes),`++i',1)==`theoutcome' {
|
1696 |
+
local value `"`eq'"'
|
1697 |
+
continue, break
|
1698 |
+
}
|
1699 |
+
}
|
1700 |
+
}
|
1701 |
+
if `"`value'"'=="" local value `theoutcome'
|
1702 |
+
c_local eq `"`value'"'
|
1703 |
+
end
|
1704 |
+
program define _estadd_prchange_StoreEachOutc // only for nomord models
|
1705 |
+
syntax anything [, nomord(str) nobase fromto prefix(passthru) ///
|
1706 |
+
pattern(passthru) binary(passthru) continuous(passthru) ]
|
1707 |
+
// backup estimates
|
1708 |
+
tempname hcurrent
|
1709 |
+
_est hold `hcurrent', copy restore estsystem
|
1710 |
+
if `"`nomord'"'=="2" { // backup b and V
|
1711 |
+
tempname b bi V Vi
|
1712 |
+
mat `b' = e(b)
|
1713 |
+
mat `V' = e(V)
|
1714 |
+
}
|
1715 |
+
// cycle through categories
|
1716 |
+
local k_kat = colsof(r(predval))
|
1717 |
+
tempname catval catvali
|
1718 |
+
mat `catval' = r(catval)
|
1719 |
+
forv i=1/`k_kat' {
|
1720 |
+
mat `catvali' = `catval'[1...,`i']
|
1721 |
+
local catlabi: colnames `catvali'
|
1722 |
+
local catnumi: di `catvali'[1,1]
|
1723 |
+
if `"`nomord'"'=="2" {
|
1724 |
+
_estadd_prchange_GetEqnmNomModl `catnumi'
|
1725 |
+
if colnumb(`b', `"`eq':"')<. {
|
1726 |
+
mat `bi' = `b'[1...,`"`eq':"']
|
1727 |
+
mat `Vi' = `V'[`"`eq':"',`"`eq':"']
|
1728 |
+
}
|
1729 |
+
else { // base outcome; get first eq and set zero
|
1730 |
+
local tmp : coleq `b', q
|
1731 |
+
gettoken tmp : tmp
|
1732 |
+
mat `bi' = `b'[1...,`"`tmp':"'] * 0
|
1733 |
+
mat `Vi' = `V'[`"`tmp':"',`"`tmp':"'] * 0
|
1734 |
+
}
|
1735 |
+
mat coleq `bi' = ""
|
1736 |
+
mat coleq `Vi' = ""
|
1737 |
+
mat roweq `Vi' = ""
|
1738 |
+
erepost b=`bi' V=`Vi'
|
1739 |
+
}
|
1740 |
+
`qui' _estadd_prchange_AddStuffToE, split nomord(1) outcome(`i') ///
|
1741 |
+
`base' `fromto' `pattern' `binary' `continuous' `prefix'
|
1742 |
+
`qui' di ""
|
1743 |
+
local qui qui
|
1744 |
+
_eststo `anything'`catnumi', title(`"`catlabi'"') // store without e(sample)
|
1745 |
+
di as txt "results for outcome " as res `catnumi' ///
|
1746 |
+
as txt " stored as " as res "`anything'`catnumi'"
|
1747 |
+
}
|
1748 |
+
// retore estimates
|
1749 |
+
_est unhold `hcurrent'
|
1750 |
+
end
|
1751 |
+
|
1752 |
+
* 22.
|
1753 |
+
* -estadd- subroutine: support for -prvalue- by Long and Freese
|
1754 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
1755 |
+
program define estadd_prvalue, eclass
|
1756 |
+
version 9.2
|
1757 |
+
local caller : di _caller()
|
1758 |
+
syntax [anything] [if] [in] [ , Prefix(passthru) Replace Quietly ///
|
1759 |
+
LABel(str) Title(passthru) swap Diff * ]
|
1760 |
+
|
1761 |
+
// post
|
1762 |
+
if `"`anything'"'!="" {
|
1763 |
+
gettoken post post2 : anything
|
1764 |
+
if `"`post'"'!="post" {
|
1765 |
+
di as err `"`post' not allowed"'
|
1766 |
+
exit 198
|
1767 |
+
}
|
1768 |
+
else if `"`label'"'!="" {
|
1769 |
+
di as err "label() not allowed"
|
1770 |
+
exit 198
|
1771 |
+
}
|
1772 |
+
_estadd_prvalue_Post `post2' `if' `in', `prefix' `replace' `quietly' ///
|
1773 |
+
`title' `swap' `diff' `options'
|
1774 |
+
exit
|
1775 |
+
}
|
1776 |
+
else if `"`title'"'!="" {
|
1777 |
+
di as err "title() not allowed"
|
1778 |
+
exit 198
|
1779 |
+
}
|
1780 |
+
else if "`swap'"!="" {
|
1781 |
+
di as err "swap not allowed"
|
1782 |
+
exit 198
|
1783 |
+
}
|
1784 |
+
|
1785 |
+
// look for e(sample)
|
1786 |
+
confirm_esample
|
1787 |
+
|
1788 |
+
// run prvalue
|
1789 |
+
capt findfile prvalue.ado
|
1790 |
+
if _rc {
|
1791 |
+
di as error "-prvalue- from the -spost9_ado- package by Long and Freese required"
|
1792 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
1793 |
+
error 499
|
1794 |
+
}
|
1795 |
+
`quietly' version `caller': prvalue `if' `in', `diff' `options'
|
1796 |
+
|
1797 |
+
// append?
|
1798 |
+
capture confirm existence `e(_estadd_prvalue)'
|
1799 |
+
local append = (_rc==0) & ("`replace'"=="")
|
1800 |
+
tempname prvalue prvalue_x prvalue_x2
|
1801 |
+
if `append' {
|
1802 |
+
mat `prvalue' = e(_estadd_prvalue)
|
1803 |
+
mat `prvalue_x' = e(_estadd_prvalue_x)
|
1804 |
+
capt mat `prvalue_x2' = e(_estadd_prvalue_x2)
|
1805 |
+
local ires = rowsof(`prvalue') + 1
|
1806 |
+
}
|
1807 |
+
else local ires 1
|
1808 |
+
if `"`label'"'=="" {
|
1809 |
+
local label "pred`ires'"
|
1810 |
+
}
|
1811 |
+
else {
|
1812 |
+
local label = substr(`"`label'"', 1, 30) // 30 characters max
|
1813 |
+
local problemchars `": . `"""'"'
|
1814 |
+
foreach char of local problemchars {
|
1815 |
+
local label: subinstr local label `"`char'"' "_", all
|
1816 |
+
}
|
1817 |
+
}
|
1818 |
+
|
1819 |
+
// collect results
|
1820 |
+
tempname pred
|
1821 |
+
mat `pred' = r(pred)
|
1822 |
+
if `"`diff'"'!="" {
|
1823 |
+
_estadd_prvalue_GetRidOfD `pred'
|
1824 |
+
}
|
1825 |
+
_estadd_prvalue_ReshapePred `pred', label(`label')
|
1826 |
+
_estadd_prvalue_AddPred `prvalue' `pred' `append'
|
1827 |
+
_estadd_prvalue_AddX `prvalue_x', label(`label')
|
1828 |
+
capture confirm matrix r(x2)
|
1829 |
+
local hasx2 = _rc==0
|
1830 |
+
if `hasx2' {
|
1831 |
+
_estadd_prvalue_AddX `prvalue_x2', label(`label') two
|
1832 |
+
}
|
1833 |
+
|
1834 |
+
// post in e()
|
1835 |
+
di as txt _n cond(`append',"updated","added") " matrices:"
|
1836 |
+
ereturn matrix _estadd_prvalue = `prvalue'
|
1837 |
+
added_matrix _estadd_prvalue
|
1838 |
+
ereturn matrix _estadd_prvalue_x = `prvalue_x'
|
1839 |
+
added_matrix _estadd_prvalue_x
|
1840 |
+
if `hasx2' {
|
1841 |
+
ereturn matrix _estadd_prvalue_x2 = `prvalue_x2'
|
1842 |
+
added_matrix _estadd_prvalue_x2
|
1843 |
+
}
|
1844 |
+
end
|
1845 |
+
program _estadd_prvalue_GetRidOfD
|
1846 |
+
args pred
|
1847 |
+
local coln: colnames `pred'
|
1848 |
+
local firstcol: word 1 of `coln'
|
1849 |
+
local nfirstcol = substr("`firstcol'",2,.)
|
1850 |
+
local coln : subinstr local coln "`firstcol'" "`nfirstcol'" , word
|
1851 |
+
mat coln `pred' = `coln'
|
1852 |
+
end
|
1853 |
+
program _estadd_prvalue_ReshapePred
|
1854 |
+
syntax anything, label(str)
|
1855 |
+
tempname tmp res
|
1856 |
+
local r = rowsof(`anything')
|
1857 |
+
forv i=1/`r' {
|
1858 |
+
mat `tmp' = `anything'[`i',1...]
|
1859 |
+
local nm: rownames `tmp'
|
1860 |
+
mat coleq `tmp' = `"`nm'"'
|
1861 |
+
mat `res' = nullmat(`res'), `tmp'
|
1862 |
+
}
|
1863 |
+
mat rown `res' = `"`label'"'
|
1864 |
+
mat `anything' = `res'
|
1865 |
+
end
|
1866 |
+
program _estadd_prvalue_AddPred
|
1867 |
+
args prvalue pred append
|
1868 |
+
if `append' {
|
1869 |
+
local coln1: colfullnames `prvalue'
|
1870 |
+
local coln2: colfullnames `pred'
|
1871 |
+
if `"`coln1'"'!=`"`coln2'"' {
|
1872 |
+
di as err "incompatible prvalue results"
|
1873 |
+
exit 498
|
1874 |
+
}
|
1875 |
+
}
|
1876 |
+
mat `prvalue' = nullmat(`prvalue') \ `pred'
|
1877 |
+
end
|
1878 |
+
program _estadd_prvalue_AddX
|
1879 |
+
syntax anything, label(str) [ two ]
|
1880 |
+
if "`two'"!="" local two 2
|
1881 |
+
tempname tmp
|
1882 |
+
mat `tmp' = r(x`two')
|
1883 |
+
mat rown `tmp' = `"`label'"'
|
1884 |
+
mat `anything' = nullmat(`anything') \ `tmp'
|
1885 |
+
end
|
1886 |
+
program _estadd_prvalue_Post, eclass
|
1887 |
+
syntax [name(name=post2)] [ , Prefix(name) Replace Quietly ///
|
1888 |
+
Title(passthru) swap ]
|
1889 |
+
capture confirm matrix e(_estadd_prvalue)
|
1890 |
+
if _rc {
|
1891 |
+
di as err "prvalue results not found"
|
1892 |
+
exit 498
|
1893 |
+
}
|
1894 |
+
// backup estimates
|
1895 |
+
tempname hcurrent
|
1896 |
+
_est hold `hcurrent', copy restore estsystem
|
1897 |
+
local cmd = e(cmd)
|
1898 |
+
local depvar = e(depvar)
|
1899 |
+
local N = e(N)
|
1900 |
+
local estname `"`e(_estadd_estimates_name)'"'
|
1901 |
+
|
1902 |
+
// get results
|
1903 |
+
tempname prvalue prvalue_x prvalue_x2
|
1904 |
+
mat `prvalue' = e(_estadd_prvalue)
|
1905 |
+
mat `prvalue_x' = e(_estadd_prvalue_x)
|
1906 |
+
capture confirm matrix e(_estadd_prvalue_x2)
|
1907 |
+
local hasx2 = _rc==0
|
1908 |
+
if `hasx2' {
|
1909 |
+
mat `prvalue_x2' = e(_estadd_prvalue_x2)
|
1910 |
+
}
|
1911 |
+
|
1912 |
+
// return prvalues
|
1913 |
+
tempname tmp tmp2 b se
|
1914 |
+
if "`swap'"=="" {
|
1915 |
+
local eqs: coleq `prvalue', q
|
1916 |
+
local eqs: list uniq eqs
|
1917 |
+
foreach eq of local eqs {
|
1918 |
+
mat `tmp' = `prvalue'[1...,`"`eq':"']
|
1919 |
+
mat `tmp2' = `tmp'[1...,1]'
|
1920 |
+
mat coleq `tmp2' = `"`eq'"'
|
1921 |
+
mat roweq `tmp2' = ""
|
1922 |
+
mat `b' = nullmat(`b'), `tmp2'
|
1923 |
+
mat `tmp2' = `tmp'[1...,`"`eq':SE"']'
|
1924 |
+
mat coleq `tmp2' = `"`eq'"'
|
1925 |
+
mat roweq `tmp2' = ""
|
1926 |
+
mat `se' = nullmat(`se'), `tmp2'
|
1927 |
+
}
|
1928 |
+
mat drop `tmp' `tmp2'
|
1929 |
+
}
|
1930 |
+
else {
|
1931 |
+
local r = rowsof(`prvalue')
|
1932 |
+
local c = colsof(`prvalue')
|
1933 |
+
local coln: colnames `prvalue'
|
1934 |
+
local eqs: coleq `prvalue', q
|
1935 |
+
mat coln `prvalue' = `eqs'
|
1936 |
+
mat coleq `prvalue' = `coln'
|
1937 |
+
local coln: list uniq coln
|
1938 |
+
local ncol: list sizeof coln
|
1939 |
+
local icol: list posof "SE" in coln
|
1940 |
+
forv i=1/`r' {
|
1941 |
+
mat `tmp' = `prvalue'[`i',1...]
|
1942 |
+
local labl : rownames `tmp'
|
1943 |
+
forv j=1(`ncol')`c' {
|
1944 |
+
mat `tmp2' = nullmat(`tmp2'), `tmp'[1...,`j']
|
1945 |
+
}
|
1946 |
+
mat coleq `tmp2' = `"`labl'"'
|
1947 |
+
mat `b' = nullmat(`b'), `tmp2'
|
1948 |
+
mat drop `tmp2'
|
1949 |
+
forv j=`icol'(`ncol')`c' {
|
1950 |
+
mat `tmp2' = nullmat(`tmp2'), `tmp'[1...,`j']
|
1951 |
+
}
|
1952 |
+
mat coleq `tmp2' = `"`labl'"'
|
1953 |
+
mat `se' = nullmat(`se'), `tmp2'
|
1954 |
+
mat drop `tmp2'
|
1955 |
+
}
|
1956 |
+
mat drop `tmp'
|
1957 |
+
}
|
1958 |
+
ereturn post `b', obs(`N')
|
1959 |
+
ereturn local model "`cmd'"
|
1960 |
+
ereturn local cmd "estadd_prvalue"
|
1961 |
+
ereturn local depvar "`depvar'"
|
1962 |
+
di as txt _n "scalars:"
|
1963 |
+
added_scalar N
|
1964 |
+
di as txt _n "macros:"
|
1965 |
+
added_macro depvar
|
1966 |
+
added_macro cmd
|
1967 |
+
added_macro model
|
1968 |
+
added_macro properties
|
1969 |
+
di as txt _n "matrices:"
|
1970 |
+
added_matrix b "predictions"
|
1971 |
+
ereturn matrix se = `se'
|
1972 |
+
added_matrix se "standard errors"
|
1973 |
+
local istat 0
|
1974 |
+
foreach stat in LB UB Category Cond {
|
1975 |
+
local elabel: word `++istat' of "lower CI bounds" "upper CI bounds" ///
|
1976 |
+
"outcome values" "conditional predictions"
|
1977 |
+
if "`swap'"=="" {
|
1978 |
+
foreach eq of local eqs {
|
1979 |
+
local colnumb = colnumb(`prvalue',`"`eq':`stat'"')
|
1980 |
+
if `colnumb'>=. continue
|
1981 |
+
mat `tmp2' = `prvalue'[1...,`colnumb']'
|
1982 |
+
mat coleq `tmp2' = `"`eq'"'
|
1983 |
+
mat roweq `tmp2' = ""
|
1984 |
+
mat `tmp' = nullmat(`tmp'), `tmp2'
|
1985 |
+
}
|
1986 |
+
}
|
1987 |
+
else {
|
1988 |
+
local icol: list posof "`stat'" in coln
|
1989 |
+
if `icol'==0 continue
|
1990 |
+
forv i=1/`r' {
|
1991 |
+
mat `tmp2' = `prvalue'[`i',1...]
|
1992 |
+
local labl : rownames `tmp2'
|
1993 |
+
mat coleq `tmp2' = `"`labl'"'
|
1994 |
+
forv j=`icol'(`ncol')`c' {
|
1995 |
+
mat `tmp' = nullmat(`tmp'), `tmp2'[1...,`j']
|
1996 |
+
}
|
1997 |
+
}
|
1998 |
+
mat drop `tmp2'
|
1999 |
+
}
|
2000 |
+
capt confirm matrix `tmp'
|
2001 |
+
if _rc==0 {
|
2002 |
+
ereturn matrix `prefix'`stat' = `tmp'
|
2003 |
+
added_matrix `prefix'`stat' "`elabel'"
|
2004 |
+
}
|
2005 |
+
}
|
2006 |
+
|
2007 |
+
// return x-values
|
2008 |
+
matrix `prvalue_x' = `prvalue_x''
|
2009 |
+
ereturn matrix `prefix'X = `prvalue_x'
|
2010 |
+
added_matrix `prefix'X _rown
|
2011 |
+
if `hasx2' {
|
2012 |
+
matrix `prvalue_x2' = `prvalue_x2''
|
2013 |
+
ereturn matrix `prefix'X2 = `prvalue_x2'
|
2014 |
+
added_matrix `prefix'X2 _rown
|
2015 |
+
}
|
2016 |
+
|
2017 |
+
// store
|
2018 |
+
if "`post2'"!="" {
|
2019 |
+
_eststo `estname'`post2', `title'
|
2020 |
+
di as txt _n "results stored as " as res "`estname'`post2'"
|
2021 |
+
}
|
2022 |
+
else if `"`title'"'!="" {
|
2023 |
+
estimates change ., `title'
|
2024 |
+
}
|
2025 |
+
|
2026 |
+
// retore estimates
|
2027 |
+
if "`post2'"!="" {
|
2028 |
+
_est unhold `hcurrent'
|
2029 |
+
}
|
2030 |
+
else {
|
2031 |
+
_est unhold `hcurrent', not
|
2032 |
+
}
|
2033 |
+
end
|
2034 |
+
|
2035 |
+
* 23.
|
2036 |
+
* -estadd- subroutine: support for -asprvalue- by Long and Freese
|
2037 |
+
* (see http://www.indiana.edu/~jslsoc/spost.htm)
|
2038 |
+
program define estadd_asprvalue, eclass
|
2039 |
+
version 9.2
|
2040 |
+
local caller : di _caller()
|
2041 |
+
syntax [anything] [ , Prefix(passthru) Replace Quietly ///
|
2042 |
+
LABel(str) Title(passthru) swap * ]
|
2043 |
+
|
2044 |
+
// post
|
2045 |
+
if `"`anything'"'!="" {
|
2046 |
+
gettoken post post2 : anything
|
2047 |
+
if `"`post'"'!="post" {
|
2048 |
+
di as err `"`post' not allowed"'
|
2049 |
+
exit 198
|
2050 |
+
}
|
2051 |
+
else if `"`label'"'!="" {
|
2052 |
+
di as err "label() not allowed"
|
2053 |
+
exit 198
|
2054 |
+
}
|
2055 |
+
_estadd_asprvalue_Post `post2' , `prefix' `replace' `quietly' ///
|
2056 |
+
`title' `swap' `options'
|
2057 |
+
exit
|
2058 |
+
}
|
2059 |
+
else if `"`title'"'!="" {
|
2060 |
+
di as err "title() not allowed"
|
2061 |
+
exit 198
|
2062 |
+
}
|
2063 |
+
else if "`swap'"!="" {
|
2064 |
+
di as err "swap not allowed"
|
2065 |
+
exit 198
|
2066 |
+
}
|
2067 |
+
|
2068 |
+
// look for e(sample)
|
2069 |
+
confirm_esample
|
2070 |
+
|
2071 |
+
// run prvalue
|
2072 |
+
capt findfile asprvalue.ado
|
2073 |
+
if _rc {
|
2074 |
+
di as error "-asprvalue- from the -spost9_ado- package by Long and Freese required"
|
2075 |
+
di as error `"type {stata "net from http://www.indiana.edu/~jslsoc/stata"}"'
|
2076 |
+
error 499
|
2077 |
+
}
|
2078 |
+
`quietly' version `caller': asprvalue , `options'
|
2079 |
+
|
2080 |
+
// append?
|
2081 |
+
capture confirm existence `e(_estadd_asprval)'
|
2082 |
+
local append = (_rc==0) & ("`replace'"=="")
|
2083 |
+
tempname asprval asprval_asv asprval_csv
|
2084 |
+
if `append' {
|
2085 |
+
mat `asprval' = e(_estadd_asprval)
|
2086 |
+
capt mat `asprval_asv' = e(_estadd_asprval_asv)
|
2087 |
+
capt mat `asprval_csv' = e(_estadd_asprval_csv)
|
2088 |
+
local ires = rowsof(`asprval') + 1
|
2089 |
+
}
|
2090 |
+
else local ires 1
|
2091 |
+
if `"`label'"'=="" {
|
2092 |
+
local label "pred`ires'"
|
2093 |
+
}
|
2094 |
+
else {
|
2095 |
+
local label = substr(`"`label'"', 1, 30) // 30 characters max
|
2096 |
+
local problemchars `": . `"""'"'
|
2097 |
+
foreach char of local problemchars {
|
2098 |
+
local label: subinstr local label `"`char'"' "_", all
|
2099 |
+
}
|
2100 |
+
}
|
2101 |
+
|
2102 |
+
// collect results
|
2103 |
+
tempname res
|
2104 |
+
mat `res' = r(p)
|
2105 |
+
_estadd_asprvalue_Reshape `res', label(`label')
|
2106 |
+
_estadd_asprvalue_Add `asprval' `res' `append'
|
2107 |
+
capture confirm matrix r(asv)
|
2108 |
+
local hasasv = _rc==0
|
2109 |
+
if `hasasv' {
|
2110 |
+
mat `res' = r(asv)
|
2111 |
+
_estadd_asprvalue_Reshape `res', label(`label')
|
2112 |
+
_estadd_asprvalue_Add `asprval_asv' `res' `append'
|
2113 |
+
}
|
2114 |
+
capture confirm matrix r(csv)
|
2115 |
+
local hascsv = _rc==0
|
2116 |
+
if `hascsv' {
|
2117 |
+
_estadd_asprvalue_AddCsv `asprval_csv', label(`label')
|
2118 |
+
}
|
2119 |
+
|
2120 |
+
// post in e()
|
2121 |
+
di as txt _n cond(`append',"updated","added") " matrices:"
|
2122 |
+
ereturn matrix _estadd_asprval = `asprval'
|
2123 |
+
added_matrix _estadd_asprval
|
2124 |
+
if `hasasv' {
|
2125 |
+
ereturn matrix _estadd_asprval_asv = `asprval_asv'
|
2126 |
+
added_matrix _estadd_asprval_asv
|
2127 |
+
}
|
2128 |
+
if `hascsv' {
|
2129 |
+
ereturn matrix _estadd_asprval_csv = `asprval_csv'
|
2130 |
+
added_matrix _estadd_asprval_csv
|
2131 |
+
}
|
2132 |
+
end
|
2133 |
+
program _estadd_asprvalue_Reshape
|
2134 |
+
syntax anything, label(str)
|
2135 |
+
tempname tmp res
|
2136 |
+
local r = rowsof(`anything')
|
2137 |
+
forv i=1/`r' {
|
2138 |
+
mat `tmp' = `anything'[`i',1...]
|
2139 |
+
local nm: rownames `tmp'
|
2140 |
+
mat coleq `tmp' = `"`nm'"'
|
2141 |
+
mat `res' = nullmat(`res'), `tmp'
|
2142 |
+
}
|
2143 |
+
mat rown `res' = `"`label'"'
|
2144 |
+
mat `anything' = `res'
|
2145 |
+
end
|
2146 |
+
program _estadd_asprvalue_Add
|
2147 |
+
args master using append
|
2148 |
+
if `append' {
|
2149 |
+
local coln1: colfullnames `master'
|
2150 |
+
local coln2: colfullnames `using'
|
2151 |
+
if `"`coln1'"'!=`"`coln2'"' {
|
2152 |
+
di as err "incompatible asprvalue results"
|
2153 |
+
exit 498
|
2154 |
+
}
|
2155 |
+
}
|
2156 |
+
mat `master' = nullmat(`master') \ `using'
|
2157 |
+
end
|
2158 |
+
program _estadd_asprvalue_AddCsv
|
2159 |
+
syntax anything, label(str)
|
2160 |
+
tempname tmp
|
2161 |
+
mat `tmp' = r(csv)
|
2162 |
+
mat rown `tmp' = `"`label'"'
|
2163 |
+
mat `anything' = nullmat(`anything') \ `tmp'
|
2164 |
+
end
|
2165 |
+
program _estadd_asprvalue_Post, eclass
|
2166 |
+
syntax [name(name=post2)] [ , Prefix(name) Replace Quietly ///
|
2167 |
+
Title(passthru) swap ]
|
2168 |
+
capture confirm matrix e(_estadd_asprval)
|
2169 |
+
if _rc {
|
2170 |
+
di as err "asprvalue results not found"
|
2171 |
+
exit 498
|
2172 |
+
}
|
2173 |
+
|
2174 |
+
// backup estimates
|
2175 |
+
tempname hcurrent
|
2176 |
+
_est hold `hcurrent', copy restore estsystem
|
2177 |
+
local cmd = e(cmd)
|
2178 |
+
local depvar = e(depvar)
|
2179 |
+
local N = e(N)
|
2180 |
+
local estname `"`e(_estadd_estimates_name)'"'
|
2181 |
+
|
2182 |
+
// get results
|
2183 |
+
tempname asprval asprval_asv asprval_csv
|
2184 |
+
mat `asprval' = e(_estadd_asprval)
|
2185 |
+
capture confirm matrix e(_estadd_asprval_asv)
|
2186 |
+
local hasasv = _rc==0
|
2187 |
+
if `hasasv' {
|
2188 |
+
mat `asprval_asv' = e(_estadd_asprval_asv)
|
2189 |
+
}
|
2190 |
+
capture confirm matrix e(_estadd_asprval_csv)
|
2191 |
+
local hascsv = _rc==0
|
2192 |
+
if `hascsv' {
|
2193 |
+
mat `asprval_csv' = e(_estadd_asprval_csv)
|
2194 |
+
}
|
2195 |
+
|
2196 |
+
// return predictions
|
2197 |
+
tempname tmp tmp2 b
|
2198 |
+
if "`swap'"=="" {
|
2199 |
+
local eqs: coleq `asprval', q
|
2200 |
+
local eqs: list uniq eqs
|
2201 |
+
foreach eq of local eqs {
|
2202 |
+
mat `tmp' = `asprval'[1...,`"`eq':"']
|
2203 |
+
mat `tmp2' = `tmp'[1...,1]'
|
2204 |
+
mat coleq `tmp2' = `"`eq'"'
|
2205 |
+
mat roweq `tmp2' = ""
|
2206 |
+
mat `b' = nullmat(`b'), `tmp2'
|
2207 |
+
}
|
2208 |
+
mat drop `tmp' `tmp2'
|
2209 |
+
}
|
2210 |
+
else {
|
2211 |
+
local r = rowsof(`asprval')
|
2212 |
+
local coln: colnames `asprval'
|
2213 |
+
local eqs: coleq `asprval', q
|
2214 |
+
mat coln `asprval' = `eqs'
|
2215 |
+
forv i=1/`r' {
|
2216 |
+
mat `tmp' = `asprval'[`i',1...]
|
2217 |
+
local labl : rownames `tmp'
|
2218 |
+
mat coleq `tmp' = `"`labl'"'
|
2219 |
+
mat `b' = nullmat(`b'), `tmp'
|
2220 |
+
}
|
2221 |
+
mat drop `tmp'
|
2222 |
+
}
|
2223 |
+
ereturn post `b', obs(`N')
|
2224 |
+
ereturn local model "`cmd'"
|
2225 |
+
ereturn local cmd "estadd_asprvalue"
|
2226 |
+
ereturn local depvar "`depvar'"
|
2227 |
+
di as txt _n "scalars:"
|
2228 |
+
added_scalar N
|
2229 |
+
di as txt _n "macros:"
|
2230 |
+
added_macro depvar
|
2231 |
+
added_macro cmd
|
2232 |
+
added_macro model
|
2233 |
+
added_macro properties
|
2234 |
+
di as txt _n "matrices:"
|
2235 |
+
added_matrix b "predictions"
|
2236 |
+
|
2237 |
+
// return asv-values
|
2238 |
+
if `hasasv' {
|
2239 |
+
if "`swap'"=="" {
|
2240 |
+
local vars: coleq `asprval_asv'
|
2241 |
+
local vars: list uniq vars
|
2242 |
+
local cats: colnames `asprval_asv'
|
2243 |
+
local cats: list uniq cats
|
2244 |
+
foreach var of local vars {
|
2245 |
+
foreach cat of local cats {
|
2246 |
+
mat `tmp2' = `asprval_asv'[1...,`"`var':`cat'"']'
|
2247 |
+
mat coleq `tmp2' = `"`cat'"'
|
2248 |
+
mat roweq `tmp2' = ""
|
2249 |
+
mat `tmp' = nullmat(`tmp'), `tmp2'
|
2250 |
+
}
|
2251 |
+
mat rown `tmp' = `"`var'"'
|
2252 |
+
mat `b' = nullmat(`b') \ `tmp'
|
2253 |
+
mat drop `tmp'
|
2254 |
+
}
|
2255 |
+
}
|
2256 |
+
else {
|
2257 |
+
local r = rowsof(`asprval_asv')
|
2258 |
+
local vars: coleq `asprval_asv'
|
2259 |
+
local vars: list uniq vars
|
2260 |
+
forv i=1/`r' {
|
2261 |
+
foreach var of local vars {
|
2262 |
+
mat `tmp2' = `asprval_asv'[`i',`"`var':"']
|
2263 |
+
local lbl: rownames `tmp2'
|
2264 |
+
mat coleq `tmp2' = `"`lbl'"'
|
2265 |
+
mat rown `tmp2' = `"`var'"'
|
2266 |
+
mat `tmp' = nullmat(`tmp') \ `tmp2'
|
2267 |
+
}
|
2268 |
+
mat `b' = nullmat(`b') , `tmp'
|
2269 |
+
mat drop `tmp'
|
2270 |
+
}
|
2271 |
+
}
|
2272 |
+
ereturn matrix `prefix'asv = `b'
|
2273 |
+
added_matrix `prefix'asv _rown
|
2274 |
+
}
|
2275 |
+
// return csv-values
|
2276 |
+
if `hascsv' {
|
2277 |
+
matrix `asprval_csv' = `asprval_csv''
|
2278 |
+
ereturn matrix `prefix'csv = `asprval_csv'
|
2279 |
+
added_matrix `prefix'csv _rown
|
2280 |
+
}
|
2281 |
+
|
2282 |
+
// store
|
2283 |
+
if "`post2'"!="" {
|
2284 |
+
_eststo `estname'`post2', `title'
|
2285 |
+
di as txt _n "results stored as " as res "`estname'`post2'"
|
2286 |
+
}
|
2287 |
+
else if `"`title'"'!="" {
|
2288 |
+
estimates change ., `title'
|
2289 |
+
}
|
2290 |
+
|
2291 |
+
// retore estimates
|
2292 |
+
if "`post2'"!="" {
|
2293 |
+
_est unhold `hcurrent'
|
2294 |
+
}
|
2295 |
+
else {
|
2296 |
+
_est unhold `hcurrent', not
|
2297 |
+
}
|
2298 |
+
end
|
2299 |
+
|
2300 |
+
* 24. estadd_margins
|
2301 |
+
program define estadd_margins, eclass
|
2302 |
+
version 11.0
|
2303 |
+
local caller : di _caller()
|
2304 |
+
syntax [ anything(everything equalok)] [fw aw iw pw] [, Prefix(name) Replace Quietly * ]
|
2305 |
+
|
2306 |
+
// set default prefix
|
2307 |
+
if "`prefix'"=="" local prefix "margins_"
|
2308 |
+
|
2309 |
+
// compute and return the results
|
2310 |
+
if `"`weight'`exp'"'!="" local wgtexp `"[`weight'`exp']"'
|
2311 |
+
`quietly' version `caller': margins `anything' `wgtexp', `options'
|
2312 |
+
|
2313 |
+
// check names
|
2314 |
+
local rscalars: r(scalars)
|
2315 |
+
local rmacros: r(macros)
|
2316 |
+
local rmatrices: r(matrices)
|
2317 |
+
local rmatrices: subinstr local rmatrices "V" "se", word
|
2318 |
+
if "`replace'"=="" {
|
2319 |
+
foreach nmlist in rscalars rmacros rmatrices {
|
2320 |
+
foreach name of local `nmlist' {
|
2321 |
+
confirm_new_ename `prefix'`name'
|
2322 |
+
}
|
2323 |
+
}
|
2324 |
+
}
|
2325 |
+
|
2326 |
+
// add results
|
2327 |
+
di as txt _n "added scalars:"
|
2328 |
+
foreach name of local rscalars {
|
2329 |
+
ereturn scalar `prefix'`name' = r(`name')
|
2330 |
+
added_scalar `prefix'`name'
|
2331 |
+
}
|
2332 |
+
di as txt _n "added macros:"
|
2333 |
+
foreach name of local rmacros {
|
2334 |
+
ereturn local `prefix'`name' `"`r(`name')'"'
|
2335 |
+
added_macro `prefix'`name'
|
2336 |
+
}
|
2337 |
+
di as txt _n "added matrices:"
|
2338 |
+
tempname tmpmat
|
2339 |
+
foreach name of local rmatrices {
|
2340 |
+
if "`name'"=="se" {
|
2341 |
+
mat `tmpmat' = vecdiag(r(V))
|
2342 |
+
forv i = 1/`=colsof(`tmpmat')' {
|
2343 |
+
mat `tmpmat'[1,`i'] = sqrt(`tmpmat'[1,`i'])
|
2344 |
+
}
|
2345 |
+
}
|
2346 |
+
else {
|
2347 |
+
mat `tmpmat' = r(`name')
|
2348 |
+
}
|
2349 |
+
eret matrix `prefix'`name' = `tmpmat'
|
2350 |
+
added_matrix `prefix'`name'
|
2351 |
+
}
|
2352 |
+
end
|
2353 |
+
|
2354 |
+
* 99.
|
2355 |
+
* copy of erepost.ado, version 1.0.1, Ben Jann, 30jul2007
|
2356 |
+
* used by estadd_listcoef and estadd_prchange
|
2357 |
+
prog erepost, eclass
|
2358 |
+
version 8.2
|
2359 |
+
syntax [anything(equalok)] [, cmd(str) noEsample Esample2(varname) REName ///
|
2360 |
+
Obs(passthru) Dof(passthru) PROPerties(passthru) * ]
|
2361 |
+
if "`esample'"!="" & "`esample2'"!="" {
|
2362 |
+
di as err "only one allowed of noesample and esample()"
|
2363 |
+
exit 198
|
2364 |
+
}
|
2365 |
+
// parse [b = b] [V = V]
|
2366 |
+
if `"`anything'"'!="" {
|
2367 |
+
tokenize `"`anything'"', parse(" =")
|
2368 |
+
if `"`7'"'!="" error 198
|
2369 |
+
if `"`1'"'=="b" {
|
2370 |
+
if `"`2'"'=="=" & `"`3'"'!="" {
|
2371 |
+
local b `"`3'"'
|
2372 |
+
confirm matrix `b'
|
2373 |
+
}
|
2374 |
+
else error 198
|
2375 |
+
if `"`4'"'=="V" {
|
2376 |
+
if `"`5'"'=="=" & `"`6'"'!="" {
|
2377 |
+
local v `"`6'"'
|
2378 |
+
confirm matrix `b'
|
2379 |
+
}
|
2380 |
+
else error 198
|
2381 |
+
}
|
2382 |
+
else if `"`4'"'!="" error 198
|
2383 |
+
}
|
2384 |
+
else if `"`1'"'=="V" {
|
2385 |
+
if `"`4'"'!="" error 198
|
2386 |
+
if `"`2'"'=="=" & `"`3'"'!="" {
|
2387 |
+
local v `"`3'"'
|
2388 |
+
confirm matrix `v'
|
2389 |
+
}
|
2390 |
+
else error 198
|
2391 |
+
}
|
2392 |
+
else error 198
|
2393 |
+
}
|
2394 |
+
//backup existing e()'s
|
2395 |
+
if "`esample2'"!="" {
|
2396 |
+
local sample "`esample2'"
|
2397 |
+
}
|
2398 |
+
else if "`esample'"=="" {
|
2399 |
+
tempvar sample
|
2400 |
+
gen byte `sample' = e(sample)
|
2401 |
+
}
|
2402 |
+
local emacros: e(macros)
|
2403 |
+
if `"`properties'"'!="" {
|
2404 |
+
local emacros: subinstr local emacros "properties" "", word
|
2405 |
+
}
|
2406 |
+
foreach emacro of local emacros {
|
2407 |
+
local e_`emacro' `"`e(`emacro')'"'
|
2408 |
+
}
|
2409 |
+
local escalars: e(scalars)
|
2410 |
+
if `"`obs'"'!="" {
|
2411 |
+
local escalars: subinstr local escalars "N" "", word
|
2412 |
+
}
|
2413 |
+
if `"`dof'"'!="" {
|
2414 |
+
local escalars: subinstr local escalars "df_r" "", word
|
2415 |
+
}
|
2416 |
+
foreach escalar of local escalars {
|
2417 |
+
tempname e_`escalar'
|
2418 |
+
scalar `e_`escalar'' = e(`escalar')
|
2419 |
+
}
|
2420 |
+
local ematrices: e(matrices)
|
2421 |
+
if "`b'"=="" & `:list posof "b" in ematrices' {
|
2422 |
+
tempname b
|
2423 |
+
mat `b' = e(b)
|
2424 |
+
}
|
2425 |
+
if "`v'"=="" & `:list posof "V" in ematrices' {
|
2426 |
+
tempname v
|
2427 |
+
mat `v' = e(V)
|
2428 |
+
}
|
2429 |
+
local bV "b V"
|
2430 |
+
local ematrices: list ematrices - bV
|
2431 |
+
foreach ematrix of local ematrices {
|
2432 |
+
tempname e_`ematrix'
|
2433 |
+
matrix `e_`ematrix'' = e(`ematrix')
|
2434 |
+
}
|
2435 |
+
// rename
|
2436 |
+
if "`b'"!="" & "`v'"!="" & "`rename'"!="" {
|
2437 |
+
local eqnames: coleq `b', q
|
2438 |
+
local vnames: colnames `b'
|
2439 |
+
mat coleq `v' = `eqnames'
|
2440 |
+
mat coln `v' = `vnames'
|
2441 |
+
mat roweq `v' = `eqnames'
|
2442 |
+
mat rown `v' = `vnames'
|
2443 |
+
}
|
2444 |
+
// post results
|
2445 |
+
if "`esample'"=="" {
|
2446 |
+
eret post `b' `v', esample(`sample') `obs' `dof' `properties' `options'
|
2447 |
+
}
|
2448 |
+
else {
|
2449 |
+
eret post `b' `v', `obs' `dof' `properties' `options'
|
2450 |
+
}
|
2451 |
+
foreach emacro of local emacros {
|
2452 |
+
eret local `emacro' `"`e_`emacro''"'
|
2453 |
+
}
|
2454 |
+
if `"`cmd'"'!="" {
|
2455 |
+
eret local cmd `"`cmd'"'
|
2456 |
+
}
|
2457 |
+
foreach escalar of local escalars {
|
2458 |
+
eret scalar `escalar' = scalar(`e_`escalar'')
|
2459 |
+
}
|
2460 |
+
foreach ematrix of local ematrices {
|
2461 |
+
eret matrix `ematrix' = `e_`ematrix''
|
2462 |
+
}
|
2463 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estadd.hlp
ADDED
@@ -0,0 +1,935 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 13sep2013}{...}
|
3 |
+
{hi:help estadd}{right:also see: {helpb esttab}, {helpb estout}, {helpb eststo}, {helpb estpost}}
|
4 |
+
{right: {browse "http://repec.org/bocode/e/estout"}}
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{p 4 4 2}{hi:estadd} {hline 2} Add results to (stored) estimates
|
10 |
+
|
11 |
+
|
12 |
+
{title:Syntax}
|
13 |
+
|
14 |
+
{p 8 15 2}
|
15 |
+
{cmd:estadd} {it:{help estadd##subcommands:subcommand}} [{cmd:,}
|
16 |
+
{it:{help estadd##opts:options}} ] [ {cmd::} {it:namelist} ]
|
17 |
+
|
18 |
+
|
19 |
+
where {it:namelist} is {cmd:_all} | {cmd:*} | {it:name} [{it:name} ...]
|
20 |
+
|
21 |
+
{marker subcommands}
|
22 |
+
{it:subcommands}{col 26}description
|
23 |
+
{hline 65}
|
24 |
+
Elementary
|
25 |
+
{helpb estadd##local:{ul:loc}al} {it:name ...}{col 26}{...}
|
26 |
+
add a macro
|
27 |
+
{helpb estadd##scalar:{ul:sca}lar} {it:name} {cmd:=} {it:exp}{col 26}{...}
|
28 |
+
add a scalar
|
29 |
+
{helpb estadd##matrix:{ul:mat}rix} {it:name} {cmd:=} {it:mat}{col 26}{...}
|
30 |
+
add a matrix
|
31 |
+
{helpb estadd##rreturn:r({it:name})}{col 26}{...}
|
32 |
+
add contents of {cmd:r(}{it:name}{cmd:)} (matrix or scalar)
|
33 |
+
|
34 |
+
Statistics for each
|
35 |
+
coefficient
|
36 |
+
{helpb estadd##beta:beta}{col 26}{...}
|
37 |
+
standardized coefficients
|
38 |
+
{helpb estadd##vif:vif}{col 26}{...}
|
39 |
+
variance inflation factors (after {cmd:regress})
|
40 |
+
{helpb estadd##pcorr:pcorr}{col 26}{...}
|
41 |
+
partial (and semi-partial) correlations
|
42 |
+
{helpb estadd##expb:expb}{col 26}{...}
|
43 |
+
exponentiated coefficients
|
44 |
+
{helpb estadd##ebsd:ebsd}{col 26}{...}
|
45 |
+
standardized factor change coefficients
|
46 |
+
{helpb estadd##mean:mean}{col 26}{...}
|
47 |
+
means of regressors
|
48 |
+
{helpb estadd##sd:sd}{col 26}{...}
|
49 |
+
standard deviations of regressors
|
50 |
+
{helpb estadd##summ:summ}{col 26}{...}
|
51 |
+
various descriptives of the regressors
|
52 |
+
|
53 |
+
Summary statistics
|
54 |
+
{helpb estadd##coxsnell:coxsnell}{col 26}{...}
|
55 |
+
Cox & Snell's pseudo R-squared
|
56 |
+
{helpb estadd##nagelkerke:nagelkerke}{col 26}{...}
|
57 |
+
Nagelkerke's pseudo R-squared
|
58 |
+
{helpb estadd##lrtest:lrtest} {it:model}{col 26}{...}
|
59 |
+
likelihood-ratio test
|
60 |
+
{helpb estadd##ysumm:ysumm}{col 26}{...}
|
61 |
+
descriptives of the dependent variable
|
62 |
+
|
63 |
+
Other
|
64 |
+
{helpb estadd##margins:margins}{col 26}{...}
|
65 |
+
add results from {cmd:margins} (Stata 11 or newer)
|
66 |
+
|
67 |
+
{help estadd##spost:SPost}
|
68 |
+
{helpb estadd##brant:brant}{col 26}{...}
|
69 |
+
add results from {cmd:brant} (if installed)
|
70 |
+
{helpb estadd##fitstat:fitstat}{col 26}{...}
|
71 |
+
add results from {cmd:fitstat} (if installed)
|
72 |
+
{helpb estadd##listcoef:listcoef}{col 26}{...}
|
73 |
+
add results from {cmd:listcoef} (if installed)
|
74 |
+
{helpb estadd##mlogtest:mlogtest}{col 26}{...}
|
75 |
+
add results from {cmd:mlogtest} (if installed)
|
76 |
+
{helpb estadd##prchange:prchange}{col 26}{...}
|
77 |
+
add results from {cmd:prchange} (if installed)
|
78 |
+
{helpb estadd##prvalue:prvalue}{col 26}{...}
|
79 |
+
add results from {cmd:prvalue} (if installed)
|
80 |
+
{helpb estadd##asprvalue:asprvalue}{col 26}{...}
|
81 |
+
add results from {cmd:asprvalue} (if installed)
|
82 |
+
{hline 65}
|
83 |
+
|
84 |
+
{marker opts}
|
85 |
+
{it:{help estadd##options:options}}{col 26}description
|
86 |
+
{hline 65}
|
87 |
+
{cmdab:r:eplace}{col 26}{...}
|
88 |
+
permit overwriting existing {cmd:e()}'s
|
89 |
+
{cmdab:p:refix(}{it:string}{cmd:)}{col 26}{...}
|
90 |
+
specify prefix for names of added results
|
91 |
+
{cmdab:q:uietly}{col 26}{...}
|
92 |
+
suppress output from subcommand (if any)
|
93 |
+
{it:subcmdopts}{col 26}{...}
|
94 |
+
subcommand specific options
|
95 |
+
{hline 65}
|
96 |
+
|
97 |
+
|
98 |
+
{title:Description}
|
99 |
+
|
100 |
+
{p 4 4 2}
|
101 |
+
{cmd:estadd} adds additional results to the {cmd:e()}-returns of an
|
102 |
+
estimation command (see help {help estcom}, help {helpb ereturn}). If no
|
103 |
+
{it:namelist} is provided, then the results are added to the
|
104 |
+
currently active estimates (i.e. the model fit last). If these
|
105 |
+
estimates have been previously stored, the stored copy of the
|
106 |
+
estimates will also be modified. Alternatively, if {it:namelist} is
|
107 |
+
provided after the colon, results are added to all indicated sets of
|
108 |
+
stored estimates (see help {helpb estimates store} or help
|
109 |
+
{helpb eststo}). You may use the {cmd:*} and {cmd:?}
|
110 |
+
wildcards in {it:namelist}. Execution is silent if {it:namelist} is
|
111 |
+
provided.
|
112 |
+
|
113 |
+
{p 4 4 2}
|
114 |
+
Adding additional results to the {cmd:e()}-returns is useful, for example,
|
115 |
+
if the estimates be tabulated by commands such as {helpb estout}
|
116 |
+
or {helpb esttab}. See the {help estadd##examples:Examples} section below for
|
117 |
+
illustration of the usage of {cmd:estadd}.
|
118 |
+
|
119 |
+
{p 4 4 2}Technical note: Some of the subcommands below make use of the
|
120 |
+
information contained in {cmd:e(sample)} to determine estimation sample.
|
121 |
+
These subcommands return error if the estimates do not contain
|
122 |
+
{cmd:e(sample)}.
|
123 |
+
|
124 |
+
|
125 |
+
{title:Subcommands}
|
126 |
+
|
127 |
+
{dlgtab:Elementary}
|
128 |
+
{marker local}
|
129 |
+
{p 4 8 2}
|
130 |
+
{cmd:estadd} {cmdab:loc:al} {it:name ...}
|
131 |
+
|
132 |
+
{p 8 8 2}
|
133 |
+
adds in macro {cmd:e(}{it:name}{cmd:)} the specified contents (also
|
134 |
+
see help {helpb ereturn}).
|
135 |
+
|
136 |
+
{marker scalar}
|
137 |
+
{p 4 8 2}
|
138 |
+
{cmd:estadd} {cmdab:sca:lar} {it:name} {cmd:=} {it:exp}
|
139 |
+
|
140 |
+
{p 8 8 2}
|
141 |
+
adds in scalar {cmd:e(}{it:name}{cmd:)} the evaluation of {it:exp}
|
142 |
+
(also see help {helpb ereturn}).
|
143 |
+
|
144 |
+
{p 4 8 2}
|
145 |
+
{cmd:estadd} {cmdab:sca:lar} {cmd:r(}{it:name}{cmd:)}
|
146 |
+
|
147 |
+
{p 8 8 2}
|
148 |
+
adds in scalar {cmd:e(}{it:name}{cmd:)} the value of scalar {cmd:r(}{it:name}{cmd:)}.
|
149 |
+
|
150 |
+
{p 4 8 2}
|
151 |
+
{cmd:estadd} {cmdab:sca:lar} {it:name}
|
152 |
+
|
153 |
+
{p 8 8 2}
|
154 |
+
adds in scalar {cmd:e(}{it:name}{cmd:)} the the value of scalar {it:name}.
|
155 |
+
|
156 |
+
{marker matrix}
|
157 |
+
{p 4 8 2}
|
158 |
+
{cmd:estadd} {cmdab:mat:rix} {it:name} {cmd:=} {it:matrix_expression}
|
159 |
+
|
160 |
+
{p 8 8 2}
|
161 |
+
adds in matrix {cmd:e(}{it:name}{cmd:)} the evaluation of {it:matrix_expression}
|
162 |
+
(also see help {helpb matrix define}).
|
163 |
+
|
164 |
+
{p 4 8 2}
|
165 |
+
{cmd:estadd} {cmdab:mat:rix} {cmd:r(}{it:name}{cmd:)}
|
166 |
+
|
167 |
+
{p 8 8 2}
|
168 |
+
adds in matrix {cmd:e(}{it:name}{cmd:)} a copy of matrix {cmd:r(}{it:name}{cmd:)}.
|
169 |
+
|
170 |
+
{p 4 8 2}
|
171 |
+
{cmd:estadd} {cmdab:mat:rix} {it:name}
|
172 |
+
|
173 |
+
{p 8 8 2}
|
174 |
+
adds in matrix {cmd:e(}{it:name}{cmd:)} a copy of matrix {it:name}.
|
175 |
+
|
176 |
+
{marker rreturn}
|
177 |
+
{p 4 8 2}
|
178 |
+
{cmd:estadd} {cmd:r(}{it:name}{cmd:)}
|
179 |
+
|
180 |
+
{p 8 8 2}
|
181 |
+
adds in {cmd:e(}{it:name}{cmd:)} the value of scalar {cmd:r(}{it:name}{cmd:)}
|
182 |
+
or a copy of matrix {cmd:r(}{it:name}{cmd:)}, depending on the nature of
|
183 |
+
{cmd:r(}{it:name}{cmd:)}.
|
184 |
+
|
185 |
+
|
186 |
+
{dlgtab:Statistics for each coefficient}
|
187 |
+
{marker beta}
|
188 |
+
{p 4 8 2}
|
189 |
+
{cmd:estadd} {cmd:beta}
|
190 |
+
|
191 |
+
{p 8 8 2}
|
192 |
+
adds in {cmd:e(beta)} the standardized beta coefficients.
|
193 |
+
|
194 |
+
{marker vif}
|
195 |
+
{p 4 8 2}
|
196 |
+
{cmd:estadd} {cmd:vif} [{cmd:,} {cmdab:tol:erance} {cmdab:sqr:vif} ]
|
197 |
+
|
198 |
+
{p 8 8 2}
|
199 |
+
adds in {cmd:e(vif)} the variance inflation factors (VIFs) for the
|
200 |
+
regressors (see help {helpb vif}). Note that {cmd:vif} only works
|
201 |
+
with estimates produced by {helpb regress}. {cmd:tolerance}
|
202 |
+
additionally adds the tolerances (1/VIF) in {cmd:e(tolerance)}.
|
203 |
+
{cmd:sqrvif} additionally adds the square roots of the VIFs in
|
204 |
+
{cmd:e(sqrvif)}.
|
205 |
+
|
206 |
+
{marker pcorr}
|
207 |
+
{p 4 8 2}
|
208 |
+
{cmd:estadd} {cmd:pcorr} [{cmd:, semi} ]
|
209 |
+
|
210 |
+
{p 8 8 2}
|
211 |
+
adds the partial correlations (see help {helpb pcorr}) and,
|
212 |
+
optionally, the semi-partial correlations between the dependent
|
213 |
+
variable and the individual regressors (see, e.g., the {cmd:pcorr2}
|
214 |
+
package from the SSC Archive). In the case of multiple-equations
|
215 |
+
models, the results are computed for the first equation only. The
|
216 |
+
partial correlations will be returned in {cmd:e(pcorr)} and, if
|
217 |
+
{cmd:semi} is specified, the semi-partial correlations will be
|
218 |
+
returned in {cmd:e(spcorr)}.
|
219 |
+
|
220 |
+
{marker expb}
|
221 |
+
{p 4 8 2}
|
222 |
+
{cmd:estadd} {cmd:expb} [{cmd:,} {cmdab:nocons:tant} ]
|
223 |
+
|
224 |
+
{p 8 8 2}
|
225 |
+
adds in {cmd:e(expb)} the exponentiated coefficients (see the help
|
226 |
+
{it:{help eform_option}}). {cmd:noconstant} excludes the constant
|
227 |
+
from the added results.
|
228 |
+
|
229 |
+
{marker ebsd}
|
230 |
+
{p 4 8 2}
|
231 |
+
{cmd:estadd} {cmd:ebsd}
|
232 |
+
|
233 |
+
{p 8 8 2}
|
234 |
+
adds in {cmd:e(ebsd)} the standardized factor change coefficients,
|
235 |
+
i.e. exp(b_jS_j), where b_j is the raw coefficient and S_j is the
|
236 |
+
standard deviation of regressor j, that are sometimes reported for
|
237 |
+
logistic regression (see Long 1997).
|
238 |
+
|
239 |
+
{marker mean}
|
240 |
+
{p 4 8 2}
|
241 |
+
{cmd:estadd} {cmd:mean}
|
242 |
+
|
243 |
+
{p 8 8 2}
|
244 |
+
adds in {cmd:e(mean)} the means of the regressors.
|
245 |
+
|
246 |
+
{marker sd}
|
247 |
+
{p 4 8 2}
|
248 |
+
{cmd:estadd} {cmd:sd} [{cmd:,} {cmdab:nob:inary} ]
|
249 |
+
|
250 |
+
{p 8 8 2}
|
251 |
+
adds in {cmd:e(sd)} the standard deviations of the regressors.
|
252 |
+
{cmd:nobinary} suppresses the computation of the standard deviation
|
253 |
+
for 0/1 variables.
|
254 |
+
|
255 |
+
{marker summ}
|
256 |
+
{p 4 8 2}
|
257 |
+
{cmd:estadd} {cmd:summ} [{cmd:,} {it:stats} ]
|
258 |
+
|
259 |
+
{p 8 8 2}
|
260 |
+
adds vectors of the regressors' descriptive statistics to the
|
261 |
+
estimates. The following {it:stats} are available:
|
262 |
+
{p_end}
|
263 |
+
{marker stats}
|
264 |
+
{it:stats}{col 26}description
|
265 |
+
{hline 59}
|
266 |
+
{cmdab:me:an}{col 26}mean
|
267 |
+
{cmdab:su:m}{col 26}sum
|
268 |
+
{cmdab:mi:n}{col 26}minimum
|
269 |
+
{cmdab:ma:x}{col 26}maximum
|
270 |
+
{cmdab:ra:nge}{col 26}range = max - min
|
271 |
+
{cmd:sd}{col 26}standard deviation
|
272 |
+
{cmdab:v:ar}{col 26}variance
|
273 |
+
{cmd:cv}{col 26}coefficient of variation (sd/mean)
|
274 |
+
{cmdab:sem:ean}{col 26}standard error of mean = sd/sqrt(n)
|
275 |
+
{cmdab:sk:ewness}{col 26}skewness
|
276 |
+
{cmdab:k:urtosis}{col 26}kurtosis
|
277 |
+
{cmd:p1}{col 26}1st percentile
|
278 |
+
{cmd:p5}{col 26}5th percentile
|
279 |
+
{cmd:p10}{col 26}10th percentile
|
280 |
+
{cmd:p25}{col 26}25th percentile
|
281 |
+
{cmd:p50}{col 26}50th percentile
|
282 |
+
{cmd:p75}{col 26}75th percentile
|
283 |
+
{cmd:p90}{col 26}90th percentile
|
284 |
+
{cmd:p95}{col 26}95th percentile
|
285 |
+
{cmd:p99}{col 26}99th percentile
|
286 |
+
{cmd:iqr}{col 26}interquartile range = p75 - p25
|
287 |
+
{cmd:all}{col 26}all of the above
|
288 |
+
{cmdab:med:ian}{col 26}equivalent to specifying "{cmd:p50}"
|
289 |
+
{cmd:q}{col 26}equivalent to specifying "{cmd:p25 p50 p75}"
|
290 |
+
{hline 59}
|
291 |
+
|
292 |
+
{p 8 8 2}
|
293 |
+
The default is {cmd:mean sd min max}. Alternatively, indicate the
|
294 |
+
desired statistics. For example, to add information on the
|
295 |
+
regressors' skewness and kurtosis, type
|
296 |
+
|
297 |
+
{inp:. estadd summ, skewness kurtosis}
|
298 |
+
|
299 |
+
{p 8 8 2}
|
300 |
+
The statistics names are used as the names for the returned {cmd:e()}
|
301 |
+
matrices. For example, {cmd:estadd summ, mean} will store the means
|
302 |
+
of the regressors in {cmd:e(mean)}.
|
303 |
+
|
304 |
+
|
305 |
+
{dlgtab:Summary statistics}
|
306 |
+
{marker coxsnell}
|
307 |
+
{p 4 8 2}
|
308 |
+
{cmd:estadd} {cmd:coxsnell}
|
309 |
+
|
310 |
+
{p 8 8 2}
|
311 |
+
adds in {cmd:e(coxsnell)} the Cox & Snell pseudo R-squared, which is
|
312 |
+
defined as
|
313 |
+
|
314 |
+
{p 12 12 2}
|
315 |
+
r2_coxsnell = 1 - ( L0 / L1 )^(2/N)
|
316 |
+
|
317 |
+
{p 8 8 2}
|
318 |
+
where L0 is the likelihood of the model without regressors, L1 the
|
319 |
+
likelihood of the full model, and N is the sample size.
|
320 |
+
|
321 |
+
{marker nagelkerke}
|
322 |
+
{p 4 8 2}
|
323 |
+
{cmd:estadd} {cmd:nagelkerke}
|
324 |
+
|
325 |
+
{p 8 8 2}
|
326 |
+
adds in {cmd:e(nagelkerke)} the Nagelkerke pseudo R-squared (or Cragg
|
327 |
+
& Uhler pseudo R-squared), which is defined as
|
328 |
+
|
329 |
+
{p 12 12 2}
|
330 |
+
r2_nagelkerke = r2_coxsnell / (1 - L0^(2/N))
|
331 |
+
|
332 |
+
{marker lrtest}
|
333 |
+
{p 4 8 2}
|
334 |
+
{cmd:estadd} {cmd:lrtest} {it:model} [{cmd:,} {cmdab:n:ame:(}{it:string}{cmd:)}
|
335 |
+
{it:{help lrtest:lrtest_options}} ]
|
336 |
+
|
337 |
+
{p 8 8 2}
|
338 |
+
adds the results from a likelihood-ratio test, where {it:model} is
|
339 |
+
the comparison model (see help {helpb lrtest}). Added are
|
340 |
+
{cmd:e(lrtest_chi2)}, {cmd:e(lrtest_df)}, and {cmd:e(lrtest_p)}. The
|
341 |
+
names may be modified using the {cmd:name()} option. Specify
|
342 |
+
{cmd:name(}{it:myname}{cmd:)} to add {cmd:e(}{it:myname}{cmd:chi2)},
|
343 |
+
{cmd:e(}{it:myname}{cmd:df)}, and {cmd:e(}{it:myname}{cmd:p)}. See
|
344 |
+
help {helpb lrtest} for the {it:lrtest_options}.
|
345 |
+
|
346 |
+
{marker ysumm}
|
347 |
+
{p 4 8 2}
|
348 |
+
{cmd:estadd} {cmd:ysumm} [{cmd:,} {it:stats} ]
|
349 |
+
|
350 |
+
{p 8 8 2}
|
351 |
+
adds descriptive statistics of the dependent variable. See the
|
352 |
+
{helpb estadd##summ:summ} subcommand above for a list of the available
|
353 |
+
{it:stats}. The default is {cmd:mean sd min max}. The default prefix
|
354 |
+
for the names of the added scalars is {cmd:y} (e.g. the mean of the
|
355 |
+
dependent variable will be returned in {cmd:e(ymean)}). Use
|
356 |
+
{cmd:estadd}'s {cmd:prefix()} option to change the prefix. If a model
|
357 |
+
has multiple dependent variables, results for the first variable will
|
358 |
+
be added.
|
359 |
+
|
360 |
+
{dlgtab:Other}
|
361 |
+
{marker margins}
|
362 |
+
{p 4 8 2}
|
363 |
+
{cmd:estadd} {cmd:margins} [{it:marginlist}] [{it:if}] [{it:in}] [{it:weight}] [, {it:options} ]
|
364 |
+
|
365 |
+
{p 8 8 2}
|
366 |
+
adds results from the {cmd:margins} command, which was introduced
|
367 |
+
in Stata 11. See help {helpb margins} for options. All results returned by
|
368 |
+
{cmd:margins} except {cmd:e(V)} are added using "{cmd:margins_}" as a default
|
369 |
+
prefix. For example, the margins are added in {cmd:e(margins_b)}. The
|
370 |
+
standard errors are added in {cmd:e(margins_se)}. Use the {helpb estadd##opts:prefix()}
|
371 |
+
option to change the default prefix.
|
372 |
+
|
373 |
+
{marker spost}
|
374 |
+
{dlgtab:SPost}
|
375 |
+
|
376 |
+
{p 4 4 2} The following subcommands are wrappers for
|
377 |
+
commands from Long and Freese's {helpb SPost} package (see
|
378 |
+
{browse "http://www.indiana.edu/~jslsoc/spost.htm":http://www.indiana.edu/~jslsoc/spost.htm}). Type
|
379 |
+
|
380 |
+
. {net "from http://www.indiana.edu/~jslsoc/stata":net from http://www.indiana.edu/~jslsoc/stata}
|
381 |
+
|
382 |
+
{p 4 4 2}
|
383 |
+
to obtain the latest {cmd:SPost} version (spost9_ado). {cmd:SPost} for Stata 8 (spostado) is not
|
384 |
+
supported.
|
385 |
+
|
386 |
+
{p 4 4 2}For examples on using the subcommands see
|
387 |
+
{browse "http://repec.org/bocode/e/estout/spost.html":http://repec.org/bocode/e/estout/spost.html}.
|
388 |
+
|
389 |
+
{marker brant}
|
390 |
+
{p 4 8 2}
|
391 |
+
{cmd:estadd brant} [{cmd:,} {it:{help brant:brant_options}} ]
|
392 |
+
|
393 |
+
{p 8 8 2}
|
394 |
+
applies {helpb brant} from Long and
|
395 |
+
Freese's {helpb SPost} package and adds the returned results to
|
396 |
+
{cmd:e()}. You may specify {it:brant_options} as described in
|
397 |
+
help {helpb brant}. The following results are added:
|
398 |
+
|
399 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
400 |
+
{hline 60}
|
401 |
+
Scalars
|
402 |
+
{cmd:brant_chi2} Chi-squared of overall Brant test
|
403 |
+
{cmd:brant_df} Degrees of freedom of overall Brant test
|
404 |
+
{cmd:brant_p} P-value of overall Brant test
|
405 |
+
|
406 |
+
Matrix
|
407 |
+
{cmd:brant} Test results for individual regressors
|
408 |
+
(rows: chi2, p<chi2)
|
409 |
+
{hline 60}
|
410 |
+
|
411 |
+
{p 4 4 2}To address the rows of {cmd:e(brant)} in {helpb estout}'s {cmd:cells()}
|
412 |
+
option type {cmd:brant[chi2]} and {cmd:brant[p<chi2]}.
|
413 |
+
|
414 |
+
{marker fitstat}
|
415 |
+
{p 4 8 2}
|
416 |
+
{cmd:estadd fitstat} [{cmd:,} {it:{help fitstat:fitstat_options}} ]
|
417 |
+
|
418 |
+
{p 8 8 2}
|
419 |
+
applies {helpb fitstat} from Long and
|
420 |
+
Freese's {helpb SPost} package and adds the returned scalars to
|
421 |
+
{cmd:e()}. You may specify {it:fitstat_options} as described in
|
422 |
+
help {helpb fitstat}. Depending on model
|
423 |
+
and options, a selection of the following scalar statistics is added:
|
424 |
+
|
425 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
426 |
+
{hline 60}
|
427 |
+
{cmd:dev} Deviance (D)
|
428 |
+
{cmd:dev_df} Degrees of freedom of D
|
429 |
+
{cmd:lrx2} LR or Wald X2
|
430 |
+
{cmd:lrx2_df} Degrees of freedom of X2
|
431 |
+
{cmd:lrx2_p} Prob > LR or Wald X2
|
432 |
+
{cmd:r2_adj} Adjusted R2
|
433 |
+
{cmd:r2_mf} McFadden's R2
|
434 |
+
{cmd:r2_mfadj} McFadden's Adj R2
|
435 |
+
{cmd:r2_ml} ML (Cox-Snell) R2
|
436 |
+
{cmd:r2_cu} Cragg-Uhler(Nagelkerke) R2
|
437 |
+
{cmd:r2_mz} McKelvey & Zavoina's R2
|
438 |
+
{cmd:r2_ef} Efron's R2
|
439 |
+
{cmd:v_ystar} Variance of y*
|
440 |
+
{cmd:v_error} Variance of error
|
441 |
+
{cmd:r2_ct} Count R2
|
442 |
+
{cmd:r2_ctadj} Adj Count R2
|
443 |
+
{cmd:aic0} AIC
|
444 |
+
{cmd:aic_n} AIC*n
|
445 |
+
{cmd:bic0} BIC
|
446 |
+
{cmd:bic_p} BIC'
|
447 |
+
{cmd:statabic} BIC used by Stata
|
448 |
+
{cmd:stataaic} AIC used by Stata
|
449 |
+
{cmd:n_rhs} Number of rhs variables
|
450 |
+
{cmd:n_parm} Number of parameters
|
451 |
+
{hline 60}
|
452 |
+
|
453 |
+
{marker listcoef}
|
454 |
+
{p 4 8 2}
|
455 |
+
{cmd:estadd listcoef} [{it:varlist}] [{cmd:,} {cmd:nosd} {it:{help listcoef:listcoef_options}} ]
|
456 |
+
|
457 |
+
{p 8 8 2}
|
458 |
+
applies {helpb listcoef} from Long and
|
459 |
+
Freese's {helpb SPost} package and adds the returned results to
|
460 |
+
{cmd:e()}. You may specify {it:listcoef_options} as described in
|
461 |
+
help {helpb listcoef}. Furthermore, option {cmd:nosd} suppresses
|
462 |
+
adding the standard deviations of the variables in {cmd:e(b_sdx)}.
|
463 |
+
|
464 |
+
{p 8 8 2}Depending on the estimation command and options, several of the
|
465 |
+
following matrices are added:
|
466 |
+
|
467 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
468 |
+
{hline 60}
|
469 |
+
{cmd:b_xs} x-standardized coefficients
|
470 |
+
{cmd:b_ys} y-standardized coefficients
|
471 |
+
{cmd:b_std} Fully standardized coefficients
|
472 |
+
{cmd:b_fact} Factor change coefficients
|
473 |
+
{cmd:b_facts} Standardized factor change coefficients
|
474 |
+
{cmd:b_pct} Percent change coefficients
|
475 |
+
{cmd:b_pcts} Standardized percent change coefficients
|
476 |
+
{cmd:b_sdx} Standard deviation of the Xs
|
477 |
+
{hline 60}
|
478 |
+
|
479 |
+
{p 8 8 2}For nominal models ({helpb mlogit}, {helpb mprobit}) the
|
480 |
+
original parametrization of {cmd:e(b)} may not match the contrasts
|
481 |
+
computed by {cmd:listcoef}. To be able to tabulate standardized
|
482 |
+
coefficients along with the raw coefficients for the requested
|
483 |
+
contrasts, the following additional matrices are added for
|
484 |
+
these models:
|
485 |
+
|
486 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
487 |
+
{hline 60}
|
488 |
+
{cmd:b_raw} raw coefficients
|
489 |
+
{cmd:b_se} standard errors of raw coefficients
|
490 |
+
{cmd:b_z} z statistics
|
491 |
+
{cmd:b_p} p-values
|
492 |
+
{hline 60}
|
493 |
+
|
494 |
+
{marker mlogtest}
|
495 |
+
{p 4 8 2}
|
496 |
+
{cmd:estadd mlogtest} [{it:varlist}] [{cmd:,} {it:{help mlogtest:mlogtest_options}} ]
|
497 |
+
|
498 |
+
{p 8 8 2}
|
499 |
+
applies {helpb mlogtest} from Long and
|
500 |
+
Freese's {helpb SPost} package and adds the returned results to
|
501 |
+
{cmd:e()}. You may specify {it:mlogtest_options} as described in
|
502 |
+
help {helpb mlogtest}.
|
503 |
+
|
504 |
+
{p 8 8 2}Depending on the specified options, a selection of the following
|
505 |
+
returns are added:
|
506 |
+
|
507 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
508 |
+
{hline 60}
|
509 |
+
Scalars
|
510 |
+
{cmd:hausman_set}{it:#}{cmd:_chi2} Hausman IIA tests using {helpb hausman}
|
511 |
+
{cmd:hausman_set}{it:#}{cmd:_df}
|
512 |
+
{cmd:hausman_set}{it:#}{cmd:_p}
|
513 |
+
|
514 |
+
{cmd:suest_set}{it:#}{cmd:_chi2} Hausman IIA tests using {helpb suest}
|
515 |
+
{cmd:suest_set}{it:#}{cmd:_df}
|
516 |
+
{cmd:suest_set}{it:#}{cmd:_p}
|
517 |
+
|
518 |
+
{cmd:smhsiao_set}{it:#}{cmd:_chi2} Small-Hsiao IIA tests
|
519 |
+
{cmd:smhsiao_set}{it:#}{cmd:_df}
|
520 |
+
{cmd:smhsiao_set}{it:#}{cmd:_p}
|
521 |
+
|
522 |
+
{cmd:combine_}{it:#1}{cmd:_}{it:#2}{cmd:_chi2} Wald tests for combination of outcomes
|
523 |
+
{cmd:combine_}{it:#1}{cmd:_}{it:#2}{cmd:_df}
|
524 |
+
{cmd:combine_}{it:#1}{cmd:_}{it:#2}{cmd:_p}
|
525 |
+
|
526 |
+
{cmd:lrcomb_}{it:#1}{cmd:_}{it:#2}{cmd:_chi2} LR tests for combination of outcomes
|
527 |
+
{cmd:lrcomb_}{it:#1}{cmd:_}{it:#2}{cmd:_df}
|
528 |
+
{cmd:lrcomb_}{it:#1}{cmd:_}{it:#2}{cmd:_p}
|
529 |
+
|
530 |
+
{cmd:wald_set}{it:#}{cmd:_chi2} Wald tests for sets of independent
|
531 |
+
{cmd:wald_set}{it:#}{cmd:_df} variables
|
532 |
+
{cmd:wald_set}{it:#}{cmd:_p}
|
533 |
+
|
534 |
+
{cmd:lrtest_set}{it:#}{cmd:_chi2} LR tests for sets of independent
|
535 |
+
{cmd:lrtest_set}{it:#}{cmd:_df} variables
|
536 |
+
{cmd:lrtest_set}{it:#}{cmd:_p}
|
537 |
+
|
538 |
+
Matrices
|
539 |
+
{cmd:wald} Wald tests for individual variables
|
540 |
+
(rows: chi2, df, p)
|
541 |
+
{cmd:lrtest} LR tests for individual variables
|
542 |
+
(rows: chi2, df, p)
|
543 |
+
{hline 60}
|
544 |
+
|
545 |
+
{p 4 4 2}To address the rows of {cmd:e(wald)} and {cmd:e(lrtest)} in {helpb estout}'s
|
546 |
+
{cmd:cells()} option type the row names in brackets, for example, {cmd:wald[p]} or
|
547 |
+
{cmd:lrtest[chi2]}.
|
548 |
+
|
549 |
+
{marker prchange}
|
550 |
+
{p 4 8 2}
|
551 |
+
{cmd:estadd prchange} [{it:varlist}] [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [{cmd:,}
|
552 |
+
{cmdab:pa:ttern(}{it:typepattern}{cmd:)} {cmdab:b:inary(}{it:type}{cmd:)} {cmdab:c:ontinuous(}{it:type}{cmd:)}
|
553 |
+
[{cmd:no}]{cmdab:a:vg} {cmd:split}[{cmd:(}{it:prefix}{cmd:)}] {it:{help prchange:prchange_options}} ]
|
554 |
+
|
555 |
+
{p 8 8 2}
|
556 |
+
applies {helpb prchange} from Long and
|
557 |
+
Freese's {helpb SPost} package and adds the returned results to
|
558 |
+
{cmd:e()}. You may specify {it:prchange_options} as described in
|
559 |
+
help {helpb prchange}. In particular, the {cmd:outcome()} option may be
|
560 |
+
used with models for count, ordered, or nominal outcomes
|
561 |
+
to request results for a specific outcome. Further options are:
|
562 |
+
|
563 |
+
{p 8 12 2}{cmd:pattern(}{it:typepattern}{cmd:)}, {cmd:binary(}{it:type}{cmd:)}, and
|
564 |
+
{cmd:continuous(}{it:type}{cmd:)} to determine which types of discrete change
|
565 |
+
effects are added as the main results. The default is to add the 0 to 1
|
566 |
+
change effect for binary variables and the standard deviation change effect
|
567 |
+
for continuous variables. Use {cmd:binary(}{it:type}{cmd:)} and
|
568 |
+
{cmd:continuous(}{it:type}{cmd:)} to change these defaults. Available
|
569 |
+
types are:
|
570 |
+
|
571 |
+
{it:type} Description
|
572 |
+
{hline 48}
|
573 |
+
{cmdab:mi:nmax} minimum to maximum change effect
|
574 |
+
{cmdab:0:1} 0 to 1 change effect
|
575 |
+
{cmdab:d:elta} {cmd:delta()} change effect
|
576 |
+
{cmdab:s:d} standard deviation change effect
|
577 |
+
{cmdab:m:argefct} marginal effect (some models only)
|
578 |
+
{hline 48}
|
579 |
+
|
580 |
+
{p 12 12 2}Use {cmd:pattern(}{it:typepattern}{cmd:)} if you want to determine the
|
581 |
+
type of the added effects individually for each regressor. For example,
|
582 |
+
{bind:{cmd:pattern(minmax sd delta)}} would add {cmd:minmax} for the first regressor,
|
583 |
+
{cmd:sd} for the second, and {cmd:delta} for the third, and then proceed
|
584 |
+
using the defaults for the remaining variables.
|
585 |
+
|
586 |
+
{p 8 12 2}{cmd:avg} to request that only the average results over
|
587 |
+
all outcomes are added if applied to ordered
|
588 |
+
or nominal models ({helpb ologit}, {helpb oprobit}, {helpb slogit}, {helpb mlogit}, {helpb mprobit}). The
|
589 |
+
default is to add the average results as well as the individual results for
|
590 |
+
the different outcomes (unless {helpb prchange}'s {cmd:outcome()} option is
|
591 |
+
specified, in which case only results for the indicated outcome are
|
592 |
+
added). Furthermore, specify {cmd:noavg} to suppress the average results
|
593 |
+
and only add the outcome-specific results. {cmd:avg} cannot be combined with {cmd:split}
|
594 |
+
or {cmd:outcome()}.
|
595 |
+
|
596 |
+
{p 8 12 2}{cmd:split}[{cmd:(}{it:prefix}{cmd:)}] to save
|
597 |
+
each outcome's results in a separate estimation set if applied to ordered
|
598 |
+
or nominal models ({helpb ologit}, {helpb oprobit}, {helpb slogit}, {helpb mlogit},
|
599 |
+
{helpb mprobit}). The estimation sets are named
|
600 |
+
{it:prefix}{it:#}, where {it:#} is the value of the outcome at hand. If no
|
601 |
+
{it:prefix} is provided, the name of the estimation set followed by an
|
602 |
+
underscore is used as the prefix. If the estimation set has no name
|
603 |
+
(because it has not been stored yet) the name of the estimation command
|
604 |
+
followed by an underscore is used as the prefix (e.g. {cmd:ologit_}). The
|
605 |
+
estimation sets stored by the {cmd:split} option are intended for
|
606 |
+
tabulation only and should not be used with other post-estimation
|
607 |
+
commands.
|
608 |
+
|
609 |
+
{p 8 8 2}Depending on model and options, several of the following matrices
|
610 |
+
and scalars are added:
|
611 |
+
|
612 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
613 |
+
{hline 60}
|
614 |
+
Scalars
|
615 |
+
{cmd:centered} {cmd:1} if effects are centered, {cmd:0} else
|
616 |
+
{cmd:delta} Value of {cmd:delta()}
|
617 |
+
{cmd:predval}[{it:#}] Prediction(s) at the base values
|
618 |
+
{cmd:outcome} Outcome value ({cmd:outcome()}/{cmd:split} only)
|
619 |
+
|
620 |
+
Matrices
|
621 |
+
{cmd:dc} Discrete change effects (rows: main, minmax,
|
622 |
+
01, delta, sd [, margefct])
|
623 |
+
{cmd:pattern} Types of effects in the main row of {cmd:e(dc)}
|
624 |
+
{cmd:X} Base values and descriptive statistics
|
625 |
+
(rows: X, SD, Min, Max)
|
626 |
+
{hline 60}
|
627 |
+
|
628 |
+
{p 8 8 2}The {cmd:e(dc)} and {cmd:e(X)} matrices have multiple rows. The
|
629 |
+
{cmd:e(dc)} matrix contains the main results as determined by
|
630 |
+
{cmd:pattern()}, {cmd:binary()}, and {cmd:continuous()} in the first row.
|
631 |
+
The second and following rows contain the separate results for each type of
|
632 |
+
effect using the labels provided by {cmd:prchange} as row names. Type
|
633 |
+
{cmd:dc[}{it:#}{cmd:]} or {cmd:dc[}{it:rowname}{cmd:]} to address the rows
|
634 |
+
in {helpb estout}'s {cmd:cells()} option, where {it:#} is the row number
|
635 |
+
or {it:rowname} is the
|
636 |
+
row name. For example, type {cmd:dc[-+sd/2]} to address the centered
|
637 |
+
standard deviation change effects. To tabulate the main results (1st row),
|
638 |
+
simply type {cmd:dc}. {cmd:e(pattern)} indicates the types of effects
|
639 |
+
contained in the main row of {cmd:e(dc)} using numeric codes. The codes are 1
|
640 |
+
for the minimum to maximum change effect, 2 for the 0 to 1 change effect, 3
|
641 |
+
for the {cmd:delta()} change effect, 4 for the standard deviation change
|
642 |
+
effect, and 5 for the marginal effect. {cmd:e(X)} has four rows
|
643 |
+
containing the base values, standard deviations, minimums, and maximums. If
|
644 |
+
the {cmd:fromto} option is specified, two additional matrices,
|
645 |
+
{cmd:e(dcfrom)} and {cmd:e(dcto)} are added.
|
646 |
+
|
647 |
+
{marker prvalue}
|
648 |
+
{p 4 8 2}
|
649 |
+
{cmd:estadd prvalue} [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [{cmd:,} {cmdab:lab:el:(}{it:string}{cmd:)}
|
650 |
+
{it:{help prvalue:prvalue_options}} ]
|
651 |
+
|
652 |
+
{p 4 8 2}
|
653 |
+
{cmd:estadd prvalue} {cmd:post} [{it:name}] [{cmd:,} {cmdab:t:itle:(}{it:string}{cmd:)} {cmd:swap} ]
|
654 |
+
|
655 |
+
{p 8 8 2} applies {helpb prvalue} from Long and Freese's {helpb SPost}
|
656 |
+
package and adds the returned results to {cmd:e()}. The procedure is to
|
657 |
+
first collect a series of predictions by repeated calls to
|
658 |
+
{cmd:estadd prvalue} and then apply {cmd:estadd prvalue post} to prepare the results
|
659 |
+
for tabulation as in the following example:
|
660 |
+
|
661 |
+
{com}. logit lfp k5 k618 age wc hc lwg inc
|
662 |
+
. estadd prvalue, x(inc 10) label(low inc)
|
663 |
+
. estadd prvalue, x(inc 20) label(med inc)
|
664 |
+
. estadd prvalue, x(inc 30) label(high inc)
|
665 |
+
. estadd prvalue post
|
666 |
+
. estout{txt}
|
667 |
+
|
668 |
+
{p 8 8 2} You may specify {it:prvalue_options} with {cmd:estadd prvalue} as
|
669 |
+
described in help {helpb prvalue}. For example, use {cmd:x()} and
|
670 |
+
{cmd:rest()} to set the values of the independent variables. Use
|
671 |
+
{cmd:label()} to label the single calls. "pred#" is used as label if
|
672 |
+
{cmd:label()} is omitted, where # is the number of the call. Labels may
|
673 |
+
contain spaces but they will be trimmed to a maximum
|
674 |
+
length of 30 characters and some characters ({cmd::},
|
675 |
+
{cmd:.}, {cmd:"}) will be replaced by underscore. The results
|
676 |
+
from the single calls are collected in matrix {cmd:e(_estadd_prvalue)}
|
677 |
+
(predictions) and matrix {cmd:e(_estadd_prvalue_x)} (x-values). Specify
|
678 |
+
{cmd:replace} to drop results from previous calls.
|
679 |
+
|
680 |
+
{p 8 8 2}
|
681 |
+
{cmd:estadd prvalue post} posts the collected predictions in {cmd:e(b)}
|
682 |
+
so that they can be tabulated. The following results are saved:
|
683 |
+
|
684 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
685 |
+
{hline 60}
|
686 |
+
Scalars
|
687 |
+
{cmd:N} number of observations
|
688 |
+
|
689 |
+
Macros
|
690 |
+
{cmd:depvar} name of dependent variable
|
691 |
+
{cmd:cmd} {cmd:estadd_prvalue}
|
692 |
+
{cmd:model} model estimation command
|
693 |
+
{cmd:properties} {cmd:b}
|
694 |
+
|
695 |
+
Matrices
|
696 |
+
{cmd:b} predictions
|
697 |
+
{cmd:se} standard errors
|
698 |
+
{cmd:LB} lower confidence interval bounds
|
699 |
+
{cmd:UB} upper confidence interval bounds
|
700 |
+
{cmd:Category} outcome values
|
701 |
+
{cmd:Cond} conditional predictions (some models only)
|
702 |
+
{cmd:X} values of predictors (for each prediction)
|
703 |
+
{cmd:X2} second equation predictors (some models only)
|
704 |
+
{hline 60}
|
705 |
+
|
706 |
+
{p 8 8 2} {cmd:estadd prvalue post} replaces the current model unless
|
707 |
+
{it:name} is specified, in which case the results are stored under {it:name} and the model
|
708 |
+
remains active. However, if the model has a name
|
709 |
+
(because it has been stored), the name of the model is used as a prefix.
|
710 |
+
If, for example, the model has been stored as {cmd:model1}, then
|
711 |
+
{cmd:estadd prvalue post} stores its results under {cmd:model1}{it:name}.
|
712 |
+
Use {cmd:title()} to specify a title for the stored results.
|
713 |
+
|
714 |
+
{p 8 8 2}The default for {cmd:estadd prvalue post} is to arrange
|
715 |
+
{cmd:e(b)} in a way so that predictions are grouped by outcome (i.e. outcome labels are used
|
716 |
+
as equations). Alternatively, specify {cmd:swap} to group predictions by
|
717 |
+
{cmd:prvalue} calls (i.e. to use the prediction labels as equations).
|
718 |
+
|
719 |
+
{p 8 8 2}{cmd:e(X)} contains one row for each independent variable. To address the rows in
|
720 |
+
{helpb estout}'s {cmd:cells()} option type {cmd:X[}{it:varname}{cmd:]}, where {it:varname} is
|
721 |
+
the name of the variable of interest. {cmd:e(X2)}, if provided, is analogous to {cmd:e(X)}.
|
722 |
+
|
723 |
+
{marker asprvalue}
|
724 |
+
{p 4 8 2}
|
725 |
+
{cmd:estadd asprvalue} [{cmd:,} {cmdab:lab:el:(}{it:string}{cmd:)}
|
726 |
+
{it:{help asprvalue:asprvalue_options}} ]
|
727 |
+
|
728 |
+
{p 4 8 2}
|
729 |
+
{cmd:estadd asprvalue} {cmd:post} [{it:name}] [{cmd:,} {cmdab:t:itle:(}{it:string}{cmd:)} {cmd:swap} ]
|
730 |
+
|
731 |
+
{p 8 8 2} applies {helpb asprvalue} from Long and Freese's {helpb SPost}
|
732 |
+
package and adds the returned results to {cmd:e()}. The procedure is to
|
733 |
+
first collect a series of predictions by repeated calls to
|
734 |
+
{cmd:estadd asprvalue} and then apply {cmd:estadd asprvalue post} to prepare the results
|
735 |
+
for tabulation as in the following example:
|
736 |
+
|
737 |
+
{com}. clogit choice train bus time invc, group(id)
|
738 |
+
. estadd asprvalue, cat(train bus) label(at means)
|
739 |
+
. estadd asprvalue, cat(train bus) rest(asmean) label(at asmeans)
|
740 |
+
. estadd asprvalue post
|
741 |
+
. estout{txt}
|
742 |
+
|
743 |
+
{p 8 8 2} You may specify {it:asprvalue_options} with {cmd:estadd asprvalue} as
|
744 |
+
described in help {helpb asprvalue}. For example, use {cmd:x()} and
|
745 |
+
{cmd:rest()} to set the values of the independent variables. Use
|
746 |
+
{cmd:label()} to label the single calls. "pred#" is used as label if
|
747 |
+
{cmd:label()} is omitted, where # is the number of the call. Labels may
|
748 |
+
contain spaces but they will be trimmed to a maximum
|
749 |
+
length of 30 characters and some characters ({cmd::},
|
750 |
+
{cmd:.}, {cmd:"}) will be replaced by underscore. The results
|
751 |
+
from the single calls are collected in matrices {cmd:e(_estadd_asprval)}
|
752 |
+
(predictions), {cmd:e(_estadd_asprval_asv)} (values of alternative-specific
|
753 |
+
variables), and {cmd:e(_estadd_asprval_csv)} (values of case-specific
|
754 |
+
variables). Specify {cmd:replace} to drop results from previous calls.
|
755 |
+
|
756 |
+
{p 8 8 2}
|
757 |
+
{cmd:estadd asprvalue post} posts the collected predictions in {cmd:e(b)}
|
758 |
+
so that they can be tabulated. The following results are saved:
|
759 |
+
|
760 |
+
{cmd:e(}{it:...}{cmd:)} Contents
|
761 |
+
{hline 60}
|
762 |
+
Scalars
|
763 |
+
{cmd:N} number of observations
|
764 |
+
|
765 |
+
Macros
|
766 |
+
{cmd:depvar} name of dependent variable
|
767 |
+
{cmd:cmd} {cmd:estadd_asprvalue}
|
768 |
+
{cmd:model} model estimation command
|
769 |
+
{cmd:properties} {cmd:b}
|
770 |
+
|
771 |
+
Matrices
|
772 |
+
{cmd:b} predictions
|
773 |
+
{cmd:asv} alternative-specific variables (if available)
|
774 |
+
{cmd:csv} case-specific variables (if available)
|
775 |
+
{hline 60}
|
776 |
+
|
777 |
+
{p 8 8 2} {cmd:estadd asprvalue post} replaces the current model unless
|
778 |
+
{it:name} is specified, in which case the results are stored under
|
779 |
+
{it:name} and the model remains active. However, if the model has a name
|
780 |
+
(because it has been stored), the name of the model is used as a prefix.
|
781 |
+
If, for example, the model has been stored as {cmd:model1}, then
|
782 |
+
{cmd:estadd asprvalue post} stores its results under {cmd:model1}{it:name}.
|
783 |
+
Use {cmd:title()} to specify a title for the stored results.
|
784 |
+
|
785 |
+
{p 8 8 2}The default for {cmd:estadd asprvalue post} is to arrange
|
786 |
+
{cmd:e(b)} in a way so that predictions are grouped by outcome (i.e. outcome labels are used
|
787 |
+
as equations). Alternatively, specify {cmd:swap} to group predictions by
|
788 |
+
{cmd:prvalue} calls (i.e. to use the prediction labels as equations).
|
789 |
+
|
790 |
+
{p 8 8 2}{cmd:e(asv)} and {cmd:e(csv)} contain one row for each variable.
|
791 |
+
To address the rows in {helpb estout}'s {cmd:cells()} option type
|
792 |
+
{cmd:asv[}{it:varname}{cmd:]} or {cmd:csv[}{it:varname}{cmd:]}, where
|
793 |
+
{it:varname} is the name of the variable of interest.
|
794 |
+
|
795 |
+
{marker options}
|
796 |
+
{title:Options}
|
797 |
+
|
798 |
+
{p 4 8 2}
|
799 |
+
{cmd:replace} permits {cmd:estadd} to overwrite existing {cmd:e()}
|
800 |
+
macros, scalars, or matrices.
|
801 |
+
|
802 |
+
{p 4 8 2}
|
803 |
+
{cmd:prefix(}{it:string}{cmd:)} denotes a prefix for the names of the
|
804 |
+
added results. The default prefix is an empty string. For example, if
|
805 |
+
{cmd:prefix(}{it:string}{cmd:)} is specified, the {cmd:beta}
|
806 |
+
subcommand will return the matrix {cmd:e(}{it:string}{cmd:beta)}.
|
807 |
+
|
808 |
+
{p 4 8 2}{cmd:quietly} suppresses the output from the called subcommand and displays only
|
809 |
+
the list of added results. Note that many of {cmd:estadd}'s subcommands do not generate
|
810 |
+
output, in which case {cmd:quietly} has no effect.
|
811 |
+
|
812 |
+
{p 4 8 2}
|
813 |
+
{it:subcmdopts} are subcommand specific options. See the descriptions
|
814 |
+
of the subcommands above.
|
815 |
+
|
816 |
+
{marker examples}
|
817 |
+
{title:Examples}
|
818 |
+
|
819 |
+
{p 4 4 2}Example 1: Add {cmd:r()}-returns from other programs to the
|
820 |
+
current estimates
|
821 |
+
|
822 |
+
{com}. sysuse auto
|
823 |
+
{txt}(1978 Automobile Data)
|
824 |
+
|
825 |
+
{com}. quietly regress price mpg weight
|
826 |
+
{txt}
|
827 |
+
{com}. test mpg=weight
|
828 |
+
|
829 |
+
{txt} ( 1) {res}mpg - weight = 0
|
830 |
+
|
831 |
+
{txt} F( 1, 71) ={res} 0.36
|
832 |
+
{txt}{col 13}Prob > F ={res} 0.5514
|
833 |
+
{txt}
|
834 |
+
{com}. estadd scalar p_diff = r(p)
|
835 |
+
|
836 |
+
{txt}added scalar:
|
837 |
+
e(p_diff) = {res}.55138216
|
838 |
+
{txt}
|
839 |
+
{com}. estout, stats(p_diff)
|
840 |
+
{res}
|
841 |
+
{txt}{hline 25}
|
842 |
+
{txt} b
|
843 |
+
{txt}{hline 25}
|
844 |
+
{txt}mpg {res} -49.51222{txt}
|
845 |
+
{txt}weight {res} 1.746559{txt}
|
846 |
+
{txt}_cons {res} 1946.069{txt}
|
847 |
+
{txt}{hline 25}
|
848 |
+
{txt}p_diff {res} .5513822{txt}
|
849 |
+
{txt}{hline 25}
|
850 |
+
|
851 |
+
|
852 |
+
{p 4 4 2}Example 2: Add means and standard deviations of the model's regressors
|
853 |
+
to the current estimates
|
854 |
+
|
855 |
+
{com}. quietly logit foreign price mpg
|
856 |
+
{txt}
|
857 |
+
{com}. estadd summ, mean sd
|
858 |
+
|
859 |
+
{txt}added matrices:
|
860 |
+
e(sd) : {res}1 x 3
|
861 |
+
{txt}e(mean) : {res}1 x 3
|
862 |
+
{txt}
|
863 |
+
{com}. estout, cells("mean sd") drop(_cons)
|
864 |
+
{res}
|
865 |
+
{txt}{hline 38}
|
866 |
+
{txt} mean sd
|
867 |
+
{txt}{hline 38}
|
868 |
+
{txt}price {res} 6165.257 2949.496{txt}
|
869 |
+
{txt}mpg {res} 21.2973 5.785503{txt}
|
870 |
+
{txt}{hline 38}
|
871 |
+
|
872 |
+
|
873 |
+
{p 4 4 2}
|
874 |
+
Example 3: Add standardized beta coefficients to stored estimates
|
875 |
+
|
876 |
+
{com}. eststo: quietly regress price mpg
|
877 |
+
{txt}({res}est1{txt} stored)
|
878 |
+
|
879 |
+
{com}. eststo: quietly regress price mpg foreign
|
880 |
+
{txt}({res}est2{txt} stored)
|
881 |
+
|
882 |
+
{com}. estadd beta: *
|
883 |
+
{txt}
|
884 |
+
{com}. estout, cells(beta) drop(_cons)
|
885 |
+
{res}
|
886 |
+
{txt}{hline 38}
|
887 |
+
{txt} est1 est2
|
888 |
+
{txt} beta beta
|
889 |
+
{txt}{hline 38}
|
890 |
+
{txt}mpg {res} -.4685967 -.5770712{txt}
|
891 |
+
{txt}foreign {res} .2757378{txt}
|
892 |
+
{txt}{hline 38}
|
893 |
+
|
894 |
+
|
895 |
+
{p 4 4 2}See
|
896 |
+
{browse "http://repec.org/bocode/e/estout":http://repec.org/bocode/e/estout}
|
897 |
+
for additional examples.
|
898 |
+
|
899 |
+
|
900 |
+
{title:Writing one's own subcommands}
|
901 |
+
|
902 |
+
{p 4 4 2}
|
903 |
+
A program providing a new {cmd:estadd} subcommand should be called
|
904 |
+
{cmd:estadd_}{it:mysubcommand} (see help {helpb program} for advice
|
905 |
+
on defining programs). {it:mysubcommand} will be available to {cmd:estadd} as a new
|
906 |
+
{it:subcommand} after the program definition has been executed or
|
907 |
+
saved to a file called "estadd_{it:mysubcommand}.ado" in either the
|
908 |
+
current directory or somewhere else in the {cmd:adopath}
|
909 |
+
(see help {helpb sysdir}).
|
910 |
+
|
911 |
+
{p 4 4 2}
|
912 |
+
Use the subcommands provided within "estadd.ado" as a starting
|
913 |
+
point for writing new subcommands. See
|
914 |
+
{browse "http://repec.org/bocode/e/estout/estadd.html#estadd007":http://repec.org/bocode/e/estout/estadd.html#estadd007}
|
915 |
+
for an example.
|
916 |
+
|
917 |
+
|
918 |
+
{title:Author}
|
919 |
+
|
920 |
+
{p 4 4 2} Ben Jann, Institute of Sociology, University of Bern, [email protected]
|
921 |
+
|
922 |
+
|
923 |
+
{title:Also see}
|
924 |
+
|
925 |
+
Manual: {hi:[R] estimates}
|
926 |
+
|
927 |
+
{p 4 13 2}Online: help for
|
928 |
+
{helpb estimates},
|
929 |
+
{helpb ereturn},
|
930 |
+
{helpb program},
|
931 |
+
{helpb esttab},
|
932 |
+
{helpb estout},
|
933 |
+
{helpb eststo},
|
934 |
+
{helpb estpost}
|
935 |
+
{p_end}
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estout.ado
ADDED
The diff for this file is too large to render.
See raw diff
|
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estout.hlp
ADDED
The diff for this file is too large to render.
See raw diff
|
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estpost.ado
ADDED
@@ -0,0 +1,1839 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 1.1.6 06aug2010 Ben Jann
|
2 |
+
* 1. estpost
|
3 |
+
* 2. estpost_summarize
|
4 |
+
* 3. estpost_tabulate
|
5 |
+
* 4. estpost_tabstat
|
6 |
+
* 5. estpost_ttest
|
7 |
+
* 6. estpost_correlate
|
8 |
+
* 7. estpost_stci (Stata 9 required)
|
9 |
+
* 8. estpost_ci
|
10 |
+
* 9. estpost_prtest
|
11 |
+
* 10. estpost__svy_tabulate
|
12 |
+
* 99. _erepost
|
13 |
+
|
14 |
+
* 1. estpost
|
15 |
+
program estpost, rclass // rclass => remove r()'s left behind by subcommand
|
16 |
+
version 8.2
|
17 |
+
local caller : di _caller()
|
18 |
+
capt syntax [, * ]
|
19 |
+
if _rc==0 { // => for bootstrap
|
20 |
+
_coef_table_header
|
21 |
+
ereturn display, `options'
|
22 |
+
exit
|
23 |
+
}
|
24 |
+
gettoken subcommand rest : 0, parse(" ,:")
|
25 |
+
capt confirm name `subcommand'
|
26 |
+
if _rc {
|
27 |
+
di as err "invalid subcommand"
|
28 |
+
exit 198
|
29 |
+
}
|
30 |
+
|
31 |
+
local l = length(`"`subcommand'"')
|
32 |
+
if `"`subcommand'"'==substr("summarize",1,max(2,`l')) local subcommand "summarize"
|
33 |
+
else if `"`subcommand'"'==substr("tabulate",1,max(2,`l')) local subcommand "tabulate"
|
34 |
+
else if `"`subcommand'"'==substr("correlate",1,max(3,`l')) local subcommand "correlate"
|
35 |
+
else if `"`subcommand'"'=="svy" {
|
36 |
+
_estpost_parse_svy `macval(rest)'
|
37 |
+
}
|
38 |
+
else if substr(`"`subcommand'"',1,5)=="_svy_" {
|
39 |
+
di as err "invalid subcommand"
|
40 |
+
exit 198
|
41 |
+
}
|
42 |
+
|
43 |
+
capt local junk: properties estpost_`subcommand' // does not work in Stata 8
|
44 |
+
if _rc==199 {
|
45 |
+
di as err "invalid subcommand"
|
46 |
+
exit 198
|
47 |
+
}
|
48 |
+
|
49 |
+
version `caller': estpost_`subcommand' `macval(rest)'
|
50 |
+
//eret list
|
51 |
+
end
|
52 |
+
program _estpost_markout2 // marks out obs that are missing on *all* variables
|
53 |
+
gettoken touse varlist: 0
|
54 |
+
if `:list sizeof varlist'>0 {
|
55 |
+
tempname touse2
|
56 |
+
gen byte `touse2' = 0
|
57 |
+
foreach var of local varlist {
|
58 |
+
qui replace `touse2' = 1 if !missing(`var')
|
59 |
+
}
|
60 |
+
qui replace `touse' = 0 if `touse2'==0
|
61 |
+
}
|
62 |
+
end
|
63 |
+
program _estpost_parse_svy
|
64 |
+
version 9.2
|
65 |
+
_on_colon_parse `0'
|
66 |
+
local 0 `"`s(after)'"'
|
67 |
+
gettoken subcommand rest : 0, parse(" ,")
|
68 |
+
local l = length(`"`subcommand'"')
|
69 |
+
if `"`subcommand'"'==substr("tabulate",1,max(2,`l')) local subcommand "tabulate"
|
70 |
+
c_local subcommand `"_svy_`subcommand'"'
|
71 |
+
c_local rest `"`s(before)' : `rest'"'
|
72 |
+
end
|
73 |
+
program _estpost_namesandlabels // used by some routines such as estpost_tabulate
|
74 |
+
version 8.2 // returns locals names, savenames, and labels
|
75 |
+
args varname values0 labels0
|
76 |
+
if `"`values0'"'=="" { // generate values: 1 2 3 ...
|
77 |
+
local i 0
|
78 |
+
foreach label of local labels0 {
|
79 |
+
local values0 `values0' `++i'
|
80 |
+
}
|
81 |
+
}
|
82 |
+
local haslabels 0
|
83 |
+
if `"`labels0'"'=="" & "`varname'"!="" {
|
84 |
+
local vallab: value label `varname'
|
85 |
+
}
|
86 |
+
while (1) {
|
87 |
+
gettoken value values0 : values0
|
88 |
+
if "`value'"=="" continue, break //=> exit loop
|
89 |
+
if `"`vallab'"'!="" {
|
90 |
+
local lbl: label `vallab' `value', strict
|
91 |
+
}
|
92 |
+
else {
|
93 |
+
gettoken lbl labels0 : labels0
|
94 |
+
}
|
95 |
+
if index("`value'",".") {
|
96 |
+
local haslabels 1
|
97 |
+
if `"`lbl'"'=="" {
|
98 |
+
local lbl "`value'"
|
99 |
+
}
|
100 |
+
local value: subinstr local value "." "_missing_"
|
101 |
+
}
|
102 |
+
local names0 `names0' `value'
|
103 |
+
if `"`lbl'"'!="" {
|
104 |
+
local labels `"`labels'`lblspace'`value' `"`lbl'"'"'
|
105 |
+
local lblspace " "
|
106 |
+
}
|
107 |
+
if `haslabels' continue
|
108 |
+
if `"`lbl'"'=="" {
|
109 |
+
local names `"`names'`space'`value'"'
|
110 |
+
local savenames `"`savenames'`space'`value'"'
|
111 |
+
}
|
112 |
+
else {
|
113 |
+
if regexm(`"`lbl'"', `"[:."]"') local haslabels 1
|
114 |
+
else if length(`"`lbl'"')>30 local haslabels 1
|
115 |
+
else {
|
116 |
+
local names `"`names'`space'`"`lbl'"'"'
|
117 |
+
local lbl: subinstr local lbl " " "_", all
|
118 |
+
local savenames `"`savenames'`space'`lbl'"'
|
119 |
+
}
|
120 |
+
}
|
121 |
+
local space " "
|
122 |
+
}
|
123 |
+
if `haslabels' {
|
124 |
+
local names `names0'
|
125 |
+
local savenames `names0'
|
126 |
+
}
|
127 |
+
c_local names `"`names'"' // to be used as matrix row- or colnames
|
128 |
+
c_local savenames `"`savenames'"' // names without spaces (for matlist)
|
129 |
+
if `haslabels' {
|
130 |
+
c_local labels `"`labels'"' // label dictionary
|
131 |
+
}
|
132 |
+
else c_local labels ""
|
133 |
+
end
|
134 |
+
program _estpost_eqnamesandlabels // used by some routines such as estpost_tabulate
|
135 |
+
version 8.2 // returns locals eqnames and eqlabels
|
136 |
+
args varname values0 labels0
|
137 |
+
if `"`values0'"'=="" { // generate values: 1 2 3 ...
|
138 |
+
local i 0
|
139 |
+
foreach label of local labels0 {
|
140 |
+
local values0 `values0' `++i'
|
141 |
+
}
|
142 |
+
}
|
143 |
+
local haslabels 0
|
144 |
+
if `"`labels0'"'=="" & "`varname'"!="" {
|
145 |
+
local vallab: value label `varname'
|
146 |
+
}
|
147 |
+
while (1) {
|
148 |
+
gettoken value values0 : values0
|
149 |
+
if "`value'"=="" continue, break //=> exit loop
|
150 |
+
if `"`vallab'"'!="" {
|
151 |
+
local lbl: label `vallab' `value', strict
|
152 |
+
}
|
153 |
+
else {
|
154 |
+
gettoken lbl labels0 : labels0
|
155 |
+
}
|
156 |
+
if index("`value'",".") {
|
157 |
+
local haslabels 1
|
158 |
+
if `"`lbl'"'=="" {
|
159 |
+
local lbl "`value'"
|
160 |
+
}
|
161 |
+
local value: subinstr local value "." "_missing_"
|
162 |
+
}
|
163 |
+
local names0 `names0' `value'
|
164 |
+
if `"`lbl'"'=="" local lbl "`value'"
|
165 |
+
local labels `"`labels'`lblspace'`"`lbl'"'"'
|
166 |
+
local lblspace " "
|
167 |
+
if `haslabels' continue
|
168 |
+
if `"`lbl'"'=="" {
|
169 |
+
local names `"`names'`space'`value'"'
|
170 |
+
}
|
171 |
+
else {
|
172 |
+
if regexm(`"`lbl'"', `"[:."]"') local haslabels 1
|
173 |
+
else if length(`"`lbl'"')>30 local haslabels 1
|
174 |
+
else {
|
175 |
+
local names `"`names'`space'`"`lbl'"'"'
|
176 |
+
}
|
177 |
+
}
|
178 |
+
local space " "
|
179 |
+
}
|
180 |
+
if `haslabels' {
|
181 |
+
local names `names0'
|
182 |
+
}
|
183 |
+
c_local eqnames `"`names'"' // to be used as matrix roweqs or coleqs
|
184 |
+
if `haslabels' {
|
185 |
+
c_local eqlabels `"`labels'"' // list of labels
|
186 |
+
}
|
187 |
+
else c_local eqlabels ""
|
188 |
+
end
|
189 |
+
|
190 |
+
* 2. estpost_summarize: wrapper for -summarize-
|
191 |
+
prog estpost_summarize, eclass
|
192 |
+
version 8.2
|
193 |
+
local caller : di _caller() // not used
|
194 |
+
|
195 |
+
// syntax
|
196 |
+
syntax [varlist] [if] [in] [aw fw iw] [, ESample Quietly ///
|
197 |
+
LISTwise CASEwise Detail MEANonly ]
|
198 |
+
if "`casewise'"!="" local listwise listwise
|
199 |
+
|
200 |
+
// sample
|
201 |
+
if "`listwise'"!="" marksample touse
|
202 |
+
else {
|
203 |
+
marksample touse, nov
|
204 |
+
_estpost_markout2 `touse' `varlist'
|
205 |
+
}
|
206 |
+
qui count if `touse'
|
207 |
+
local N = r(N)
|
208 |
+
if `N'==0 error 2000
|
209 |
+
|
210 |
+
// gather results
|
211 |
+
local nvars: list sizeof varlist
|
212 |
+
tempname emptymat
|
213 |
+
mat `emptymat' = J(1, `nvars', .)
|
214 |
+
mat coln `emptymat' = `varlist'
|
215 |
+
local i 0
|
216 |
+
local rnames ""
|
217 |
+
foreach v of local varlist {
|
218 |
+
local ++i
|
219 |
+
qui summarize `v' if `touse' [`weight'`exp'], `detail' `meanonly'
|
220 |
+
local rnamesi: r(scalars)
|
221 |
+
local rnamesi: list rnamesi - rnames
|
222 |
+
if `"`rnamesi'"'!="" {
|
223 |
+
foreach name of local rnamesi {
|
224 |
+
tempname _`name'
|
225 |
+
mat `_`name'' = `emptymat'
|
226 |
+
}
|
227 |
+
local rnames: list rnames | rnamesi
|
228 |
+
}
|
229 |
+
foreach rname of local rnames {
|
230 |
+
mat `_`rname''[1,`i'] = r(`rname')
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
// display
|
235 |
+
if "`quietly'"=="" {
|
236 |
+
tempname res
|
237 |
+
local rescoln
|
238 |
+
foreach rname of local rnames {
|
239 |
+
mat `res' = nullmat(`res'), `_`rname'''
|
240 |
+
if "`rname'"=="N" {
|
241 |
+
local rescoln `rescoln' e(count)
|
242 |
+
}
|
243 |
+
else {
|
244 |
+
local rescoln `rescoln' e(`rname')
|
245 |
+
}
|
246 |
+
}
|
247 |
+
mat coln `res' = `rescoln'
|
248 |
+
if c(stata_version)<9 {
|
249 |
+
mat list `res', noheader nohalf format(%9.0g)
|
250 |
+
}
|
251 |
+
else {
|
252 |
+
matlist `res', nohalf lines(oneline)
|
253 |
+
}
|
254 |
+
mat drop `res'
|
255 |
+
}
|
256 |
+
|
257 |
+
// post results
|
258 |
+
local b
|
259 |
+
local V
|
260 |
+
if c(stata_version)<9 { // b and V required in Stata 8
|
261 |
+
tempname b V
|
262 |
+
mat `b' = J(1, `nvars', 0)
|
263 |
+
mat coln `b' = `varlist'
|
264 |
+
mat `V' = `b'' * `b'
|
265 |
+
}
|
266 |
+
if "`esample'"!="" local esample esample(`touse')
|
267 |
+
eret post `b' `V', obs(`N') `esample'
|
268 |
+
|
269 |
+
eret scalar k = `nvars'
|
270 |
+
|
271 |
+
eret local wexp `"`exp'"'
|
272 |
+
eret local wtype `"`weight'"'
|
273 |
+
eret local subcmd "summarize"
|
274 |
+
eret local cmd "estpost"
|
275 |
+
|
276 |
+
local nmat: list sizeof rnames
|
277 |
+
forv i=`nmat'(-1)1 {
|
278 |
+
local rname: word `i' of `rnames'
|
279 |
+
if "`rname'"=="N" {
|
280 |
+
eret matrix count = `_N'
|
281 |
+
continue
|
282 |
+
}
|
283 |
+
eret matrix `rname' = `_`rname''
|
284 |
+
}
|
285 |
+
end
|
286 |
+
|
287 |
+
|
288 |
+
* 2. estpost_tabulate: wrapper for -tabulate-
|
289 |
+
prog estpost_tabulate, eclass
|
290 |
+
version 8.2
|
291 |
+
local caller : di _caller() // not used
|
292 |
+
syntax varlist(min=1 max=2) [if] [in] [fw aw iw pw] [, * ]
|
293 |
+
if `:list sizeof varlist'==1 {
|
294 |
+
version `caller': estpost_tabulate_oneway `0'
|
295 |
+
}
|
296 |
+
else {
|
297 |
+
version `caller': estpost_tabulate_twoway `0'
|
298 |
+
}
|
299 |
+
end
|
300 |
+
prog estpost_tabulate_oneway, eclass
|
301 |
+
version 8.2
|
302 |
+
local caller : di _caller() // not used
|
303 |
+
|
304 |
+
// syntax
|
305 |
+
syntax varname [if] [in] [fw aw iw] [, ESample Quietly ///
|
306 |
+
noTOTal subpop(passthru) Missing sort noLabel ]
|
307 |
+
|
308 |
+
// sample
|
309 |
+
if "`missing'"!="" marksample touse, nov strok
|
310 |
+
else marksample touse, strok
|
311 |
+
qui count if `touse'
|
312 |
+
local N = r(N)
|
313 |
+
if `N'==0 error 2000
|
314 |
+
|
315 |
+
// handle string variables
|
316 |
+
capt confirm numeric variable `varlist'
|
317 |
+
if _rc {
|
318 |
+
tempname varname
|
319 |
+
qui encode `varlist' if `touse', generate(`varname')
|
320 |
+
}
|
321 |
+
else local varname `varlist'
|
322 |
+
|
323 |
+
// gather results
|
324 |
+
tempname count vals
|
325 |
+
tab `varname' if `touse' [`weight'`exp'], nofreq ///
|
326 |
+
matcell(`count') matrow(`vals') `subpop' `missing' `sort'
|
327 |
+
local N = r(N)
|
328 |
+
mat `count' = `count''
|
329 |
+
local R = r(r)
|
330 |
+
forv r = 1/`R' {
|
331 |
+
local value: di `vals'[`r',1]
|
332 |
+
local values `values' `value'
|
333 |
+
}
|
334 |
+
if "`label'"=="" {
|
335 |
+
_estpost_namesandlabels `varname' "`values'" // sets names, savenames, labels
|
336 |
+
}
|
337 |
+
else {
|
338 |
+
_estpost_namesandlabels "" "`values'"
|
339 |
+
}
|
340 |
+
if "`total'"=="" {
|
341 |
+
mat `count' = `count', `N'
|
342 |
+
local names `"`names' Total"'
|
343 |
+
local savenames `"`savenames' Total"'
|
344 |
+
local linesopt "lines(rowtotal)"
|
345 |
+
}
|
346 |
+
mat colname `count' = `names'
|
347 |
+
tempname percent cum
|
348 |
+
mat `percent' = `count'/`N'*100
|
349 |
+
mat `cum' = J(1, colsof(`count'), .z)
|
350 |
+
mat colname `cum' = `names'
|
351 |
+
mat `cum'[1,1] = `count'[1,1]
|
352 |
+
forv r = 2/`R' {
|
353 |
+
mat `cum'[1,`r'] = `cum'[1,`r'-1] + `count'[1,`r']
|
354 |
+
}
|
355 |
+
mat `cum' = `cum'/`N'*100
|
356 |
+
|
357 |
+
// display
|
358 |
+
if "`quietly'"=="" {
|
359 |
+
tempname res
|
360 |
+
mat `res' = `count'', `percent'', `cum''
|
361 |
+
mat coln `res' = e(b) e(pct) e(cumpct)
|
362 |
+
if c(stata_version)<9 {
|
363 |
+
mat list `res', noheader nohalf format(%9.0g) nodotz
|
364 |
+
}
|
365 |
+
else {
|
366 |
+
mat rown `res' = `savenames'
|
367 |
+
matlist `res', nohalf `linesopt' rowtitle(`varlist') nodotz
|
368 |
+
}
|
369 |
+
mat drop `res'
|
370 |
+
if `"`labels'"'!="" {
|
371 |
+
di _n as txt "row labels saved in macro e(labels)"
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
// post results
|
376 |
+
local V
|
377 |
+
if c(stata_version)<9 { // V required in Stata 8
|
378 |
+
tempname V
|
379 |
+
mat `V' = `count'' * `count' * 0
|
380 |
+
}
|
381 |
+
if "`esample'"!="" local esample esample(`touse')
|
382 |
+
eret post `count' `V', depname(`varlist') obs(`N') `esample'
|
383 |
+
eret scalar r = r(r)
|
384 |
+
eret local wexp `"`exp'"'
|
385 |
+
eret local wtype `"`weight'"'
|
386 |
+
eret local labels `"`labels'"'
|
387 |
+
eret local depvar "`varlist'"
|
388 |
+
eret local subcmd "tabulate"
|
389 |
+
eret local cmd "estpost"
|
390 |
+
eret mat cumpct = `cum'
|
391 |
+
eret mat pct = `percent'
|
392 |
+
end
|
393 |
+
prog estpost_tabulate_twoway, eclass
|
394 |
+
version 8.2
|
395 |
+
local caller : di _caller() // not used
|
396 |
+
|
397 |
+
// syntax
|
398 |
+
syntax varlist(min=2 max=2) [if] [in] [fw aw iw] [, ESample Quietly ///
|
399 |
+
noTOTal Missing noLabel ///
|
400 |
+
CHi2 Exact Exact2(passthru) Gamma LRchi2 Taub v All noLOg ]
|
401 |
+
local v = upper("`v'")
|
402 |
+
local qui2 "`quietly'"
|
403 |
+
local hastests = `"`chi2'`exact'`exact2'`gamma'`lrchi2'`taub'`v'`all'"'!=""
|
404 |
+
if `hastests' local nofreq nofreq
|
405 |
+
else local qui2 "quietly"
|
406 |
+
|
407 |
+
// sample
|
408 |
+
if "`missing'"!="" marksample touse, nov strok
|
409 |
+
else marksample touse, strok
|
410 |
+
qui count if `touse'
|
411 |
+
local N = r(N)
|
412 |
+
if `N'==0 error 2000
|
413 |
+
|
414 |
+
// handle string variables
|
415 |
+
gettoken rvar cvar : varlist
|
416 |
+
gettoken cvar : cvar
|
417 |
+
foreach d in r c {
|
418 |
+
capt confirm numeric variable ``d'var'
|
419 |
+
if _rc {
|
420 |
+
tempname `d'varname
|
421 |
+
qui encode ``d'var' if `touse', generate(``d'varname')
|
422 |
+
}
|
423 |
+
else local `d'varname ``d'var'
|
424 |
+
}
|
425 |
+
|
426 |
+
// gather results
|
427 |
+
tempname cell rvals cvals
|
428 |
+
if `hastests' {
|
429 |
+
`quietly' di ""
|
430 |
+
}
|
431 |
+
`qui2' tab `rvarname' `cvarname' if `touse' [`weight'`exp'], `nofreq' ///
|
432 |
+
matcell(`cell') matrow(`rvals') matcol(`cvals') `missing' ///
|
433 |
+
`chi2' `exact' `exact2' `gamma' `lrchi2' `taub' `v' `all' `log'
|
434 |
+
mat `cvals' = `cvals''
|
435 |
+
local N = r(N)
|
436 |
+
tempname rtot ctot
|
437 |
+
mat `ctot' = J(1,rowsof(`cell'),1) * `cell'
|
438 |
+
mat `rtot' = `cell' * J(colsof(`cell'),1,1)
|
439 |
+
foreach d in r c {
|
440 |
+
local I = r(`d')
|
441 |
+
forv i = 1/`I' {
|
442 |
+
local value: di ``d'vals'[`i',1]
|
443 |
+
local `d'values ``d'values' `value'
|
444 |
+
}
|
445 |
+
}
|
446 |
+
if "`label'"=="" {
|
447 |
+
_estpost_namesandlabels `rvarname' "`rvalues'" // sets names, savenames, labels
|
448 |
+
_estpost_eqnamesandlabels `cvarname' "`cvalues'" // sets eqnames, eqlabels
|
449 |
+
}
|
450 |
+
else {
|
451 |
+
_estpost_namesandlabels "" "`rvalues'" // sets names, savenames, labels
|
452 |
+
_estpost_eqnamesandlabels "" "`cvalues'" // sets eqnames, eqlabels
|
453 |
+
}
|
454 |
+
local savenames0 `"`savenames'"'
|
455 |
+
local savenames
|
456 |
+
if "`total'"=="" {
|
457 |
+
mat `ctot' = `ctot', `N'
|
458 |
+
mat `cell' = (`cell', `rtot') \ `ctot'
|
459 |
+
mat `rtot' = `rtot' \ `N'
|
460 |
+
local names `"`names' Total"'
|
461 |
+
local savenames0 `"`savenames0' Total"'
|
462 |
+
local eqnames `"`eqnames' Total"'
|
463 |
+
}
|
464 |
+
mat rowname `cell' = `names'
|
465 |
+
tempname count col row tot tmp
|
466 |
+
forv i = 1/`=colsof(`cell')' {
|
467 |
+
gettoken eq eqnames : eqnames
|
468 |
+
mat `tmp' = `cell'[1...,`i']
|
469 |
+
mat roweq `tmp' = `"`eq'"'
|
470 |
+
mat `tmp' = `tmp''
|
471 |
+
mat `count' = nullmat(`count'), `tmp'
|
472 |
+
mat `col' = nullmat(`col'), `tmp' / `ctot'[1,`i']*100
|
473 |
+
forv j = 1/`=colsof(`tmp')' {
|
474 |
+
mat `tmp'[1,`j'] = `tmp'[1,`j'] / `rtot'[`j',1]*100
|
475 |
+
}
|
476 |
+
mat `row' = nullmat(`row'), `tmp'
|
477 |
+
local savenames `"`savenames' `savenames0'"'
|
478 |
+
}
|
479 |
+
mat `tot' = `count' / `N'*100
|
480 |
+
|
481 |
+
// display
|
482 |
+
if "`quietly'"=="" {
|
483 |
+
tempname res
|
484 |
+
mat `res' = `count'', `tot'', `col'', `row''
|
485 |
+
mat coln `res' = e(b) e(pct) e(colpct) e(rowpct)
|
486 |
+
if c(stata_version)<9 {
|
487 |
+
mat list `res', noheader nohalf format(%9.0g)
|
488 |
+
}
|
489 |
+
else {
|
490 |
+
mat rown `res' = `savenames'
|
491 |
+
di _n as res %-12s abbrev("`cvar'",12) as txt " {c |}{space 44}"
|
492 |
+
matlist `res', twidth(12) format(%9.0g) noblank nohalf rowtitle(`rvar')
|
493 |
+
}
|
494 |
+
mat drop `res'
|
495 |
+
if `"`labels'`eqlabels'"'!="" {
|
496 |
+
di ""
|
497 |
+
if `"`labels'"'!="" {
|
498 |
+
di as txt "row labels saved in macro e(labels)"
|
499 |
+
}
|
500 |
+
if `"`eqlabels'"'!="" {
|
501 |
+
di as txt "column labels saved in macro e(eqlabels)"
|
502 |
+
}
|
503 |
+
}
|
504 |
+
}
|
505 |
+
|
506 |
+
// post results
|
507 |
+
local V
|
508 |
+
if c(stata_version)<9 { // V required in Stata 8
|
509 |
+
tempname V
|
510 |
+
mat `V' = `count'' * `count' * 0
|
511 |
+
}
|
512 |
+
if "`esample'"!="" local esample esample(`touse')
|
513 |
+
eret post `count' `V', obs(`N') `esample'
|
514 |
+
local rscalars: r(scalars)
|
515 |
+
local rscalars: subinstr local rscalars "N" "", word
|
516 |
+
foreach rsc of local rscalars {
|
517 |
+
eret scalar `rsc' = r(`rsc')
|
518 |
+
}
|
519 |
+
eret local wexp `"`exp'"'
|
520 |
+
eret local wtype `"`weight'"'
|
521 |
+
eret local labels `"`labels'"'
|
522 |
+
eret local eqlabels `"`eqlabels'"'
|
523 |
+
eret local colvar "`cvar'"
|
524 |
+
eret local rowvar "`rvar'"
|
525 |
+
eret local subcmd "tabulate"
|
526 |
+
eret local cmd "estpost"
|
527 |
+
eret mat rowpct = `row'
|
528 |
+
eret mat colpct = `col'
|
529 |
+
eret mat pct = `tot'
|
530 |
+
end
|
531 |
+
|
532 |
+
|
533 |
+
* 4. estpost_tabstat: wrapper for -tabstat-
|
534 |
+
prog estpost_tabstat, eclass
|
535 |
+
version 8.2
|
536 |
+
local caller : di _caller() // not used
|
537 |
+
|
538 |
+
// syntax
|
539 |
+
syntax varlist [if] [in] [aw fw] [, ESample Quietly ///
|
540 |
+
Statistics(passthru) stats(passthru) LISTwise CASEwise ///
|
541 |
+
by(varname) noTotal Missing Columns(str) ]
|
542 |
+
if "`casewise'"!="" local listwise listwise
|
543 |
+
local l = length(`"`columns'"')
|
544 |
+
if `"`columns'"'==substr("variables",1,max(1,`l')) local columns "variables"
|
545 |
+
else if `"`columns'"'==substr("statistics",1,max(1,`l')) local columns "statistics"
|
546 |
+
else if `"`columns'"'=="stats" local columns "statistics"
|
547 |
+
else if `"`columns'"'=="" {
|
548 |
+
if `:list sizeof varlist'>1 local columns "variables"
|
549 |
+
else local columns "statistics"
|
550 |
+
}
|
551 |
+
else {
|
552 |
+
di as err `"columns(`columns') invalid"'
|
553 |
+
exit 198
|
554 |
+
}
|
555 |
+
|
556 |
+
// sample
|
557 |
+
if "`listwise'"!="" marksample touse
|
558 |
+
else {
|
559 |
+
marksample touse, nov
|
560 |
+
_estpost_markout2 `touse' `varlist'
|
561 |
+
}
|
562 |
+
if "`by'"!="" {
|
563 |
+
if "`missing'"=="" markout `touse' `by', strok
|
564 |
+
local byopt "by(`by')"
|
565 |
+
}
|
566 |
+
qui count if `touse'
|
567 |
+
local N = r(N)
|
568 |
+
if `N'==0 error 2000
|
569 |
+
|
570 |
+
// gather results
|
571 |
+
if "`total'"!="" & "`by'"=="" {
|
572 |
+
di as txt "nothing to post"
|
573 |
+
eret clear
|
574 |
+
exit
|
575 |
+
}
|
576 |
+
qui tabstat `varlist' if `touse' [`weight'`exp'], save ///
|
577 |
+
`statistics' `stats' `byopt' `total' `missing' columns(`columns')
|
578 |
+
tempname tmp
|
579 |
+
capt confirm matrix r(StatTot)
|
580 |
+
if _rc {
|
581 |
+
mat `tmp' = r(Stat1)
|
582 |
+
}
|
583 |
+
else {
|
584 |
+
mat `tmp' = r(StatTot)
|
585 |
+
}
|
586 |
+
if `"`columns'"'=="statistics" {
|
587 |
+
local cnames: rownames `tmp'
|
588 |
+
local cnames: subinstr local cnames "N" "count", word all
|
589 |
+
local cnames: subinstr local cnames "se(mean)" "semean", word all
|
590 |
+
local R = colsof(`tmp')
|
591 |
+
local stats "`cnames'"
|
592 |
+
local vars: colnames `tmp'
|
593 |
+
}
|
594 |
+
else {
|
595 |
+
local cnames: colnames `tmp'
|
596 |
+
local R = rowsof(`tmp')
|
597 |
+
local stats: rownames `tmp'
|
598 |
+
local stats: subinstr local stats "N" "count", word all
|
599 |
+
local stats: subinstr local stats "se(mean)" "semean", word all
|
600 |
+
local vars "`cnames'"
|
601 |
+
local cnames: subinstr local cnames "b" "_b", word all
|
602 |
+
local cnames: subinstr local cnames "V" "_V", word all
|
603 |
+
}
|
604 |
+
local j 0
|
605 |
+
foreach cname of local cnames {
|
606 |
+
tempname _`++j'
|
607 |
+
}
|
608 |
+
local groups: r(macros)
|
609 |
+
local g: list sizeof groups
|
610 |
+
local space
|
611 |
+
local labels
|
612 |
+
forv i = 1/`g' {
|
613 |
+
local labels `"`labels'`space'`"`r(name`i')'"'"'
|
614 |
+
}
|
615 |
+
if `R'==1 {
|
616 |
+
_estpost_namesandlabels "" "" `"`labels'"' // sets names, savenames, labels
|
617 |
+
}
|
618 |
+
else {
|
619 |
+
_estpost_eqnamesandlabels "" "" `"`labels'"' // sets eqnames, eqlabels
|
620 |
+
local names `"`eqnames'"'
|
621 |
+
local labels `"`eqlabels'"'
|
622 |
+
}
|
623 |
+
forv i = 1/`g' {
|
624 |
+
gettoken name names : names
|
625 |
+
mat `tmp' = r(Stat`i')
|
626 |
+
mat rown `tmp' = `stats'
|
627 |
+
if `"`columns'"'=="statistics" {
|
628 |
+
mat `tmp' = `tmp''
|
629 |
+
}
|
630 |
+
if `R'==1 {
|
631 |
+
mat rown `tmp' = `"`name'"'
|
632 |
+
}
|
633 |
+
else {
|
634 |
+
mat roweq `tmp' = `"`name'"'
|
635 |
+
}
|
636 |
+
local j 0
|
637 |
+
foreach cname of local cnames {
|
638 |
+
local ++j
|
639 |
+
mat `_`j'' = nullmat(`_`j''), `tmp'[1..., `j']'
|
640 |
+
}
|
641 |
+
}
|
642 |
+
if "`total'"=="" {
|
643 |
+
mat `tmp' = r(StatTot)
|
644 |
+
mat rown `tmp' = `stats'
|
645 |
+
if `"`columns'"'=="statistics" {
|
646 |
+
mat `tmp' = `tmp''
|
647 |
+
}
|
648 |
+
if `g'>0 {
|
649 |
+
if `R'==1 {
|
650 |
+
mat rown `tmp' = "Total"
|
651 |
+
local savenames `"`savenames' Total"'
|
652 |
+
local rowtotal "lines(rowtotal)"
|
653 |
+
}
|
654 |
+
else {
|
655 |
+
mat roweq `tmp' = "Total"
|
656 |
+
if `"`labels'"'!="" {
|
657 |
+
local labels `"`labels' Total"'
|
658 |
+
}
|
659 |
+
}
|
660 |
+
}
|
661 |
+
local j 0
|
662 |
+
foreach cname of local cnames {
|
663 |
+
local ++j
|
664 |
+
mat `_`j'' = nullmat(`_`j''), `tmp'[1..., `j']'
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
// display
|
669 |
+
if "`quietly'"=="" {
|
670 |
+
tempname res
|
671 |
+
local rescoln
|
672 |
+
local j 0
|
673 |
+
foreach cname of local cnames {
|
674 |
+
local ++j
|
675 |
+
mat `res' = nullmat(`res'), `_`j'''
|
676 |
+
local rescoln `rescoln' e(`cname')
|
677 |
+
}
|
678 |
+
mat coln `res' = `rescoln'
|
679 |
+
di _n as txt "Summary statistics: `stats'"
|
680 |
+
di as txt " for variables: `vars'"
|
681 |
+
if "`by'"!="" {
|
682 |
+
di as txt " by categories of: `by'"
|
683 |
+
}
|
684 |
+
if c(stata_version)<9 {
|
685 |
+
mat list `res', noheader nohalf format(%9.0g)
|
686 |
+
}
|
687 |
+
else {
|
688 |
+
if `R'==1 & `g'>0 {
|
689 |
+
mat rown `res' = `savenames'
|
690 |
+
}
|
691 |
+
matlist `res', nohalf `rowtotal' rowtitle(`by')
|
692 |
+
}
|
693 |
+
if `"`labels'"'!="" {
|
694 |
+
di _n as txt "category labels saved in macro e(labels)"
|
695 |
+
}
|
696 |
+
mat drop `res'
|
697 |
+
}
|
698 |
+
|
699 |
+
// post results
|
700 |
+
local b
|
701 |
+
local V
|
702 |
+
if c(stata_version)<9 { // b and V required in Stata 8
|
703 |
+
tempname b V
|
704 |
+
mat `b' = `_1' \ J(1, colsof(`_1'), 0)
|
705 |
+
mat `b' = `b'[2,1...]
|
706 |
+
mat `V' = `b'' * `b'
|
707 |
+
}
|
708 |
+
if "`esample'"!="" local esample esample(`touse')
|
709 |
+
eret post `b' `V', obs(`N') `esample'
|
710 |
+
|
711 |
+
eret local labels `"`labels'"'
|
712 |
+
eret local byvar "`by'"
|
713 |
+
eret local vars "`vars'"
|
714 |
+
eret local stats "`stats'"
|
715 |
+
eret local wexp `"`exp'"'
|
716 |
+
eret local wtype `"`weight'"'
|
717 |
+
eret local subcmd "tabstat"
|
718 |
+
eret local cmd "estpost"
|
719 |
+
|
720 |
+
local nmat: list sizeof cnames
|
721 |
+
forv j=`nmat'(-1)1 {
|
722 |
+
local cname: word `j' of `cnames'
|
723 |
+
eret matrix `cname' = `_`j''
|
724 |
+
}
|
725 |
+
end
|
726 |
+
|
727 |
+
|
728 |
+
* 5. estpost_ttest: wrapper for -ttest- (two-sample)
|
729 |
+
prog estpost_ttest, eclass
|
730 |
+
version 8.2
|
731 |
+
local caller : di _caller() // not used
|
732 |
+
|
733 |
+
// syntax
|
734 |
+
syntax varlist(numeric) [if] [in] , by(varname) [ ESample Quietly ///
|
735 |
+
LISTwise CASEwise UNEqual Welch ]
|
736 |
+
if "`casewise'"!="" local listwise listwise
|
737 |
+
|
738 |
+
// sample
|
739 |
+
if "`listwise'"!="" marksample touse
|
740 |
+
else {
|
741 |
+
marksample touse, nov
|
742 |
+
_estpost_markout2 `touse' `varlist'
|
743 |
+
}
|
744 |
+
markout `touse' `by', strok
|
745 |
+
qui count if `touse'
|
746 |
+
local N = r(N)
|
747 |
+
if `N'==0 error 2000
|
748 |
+
|
749 |
+
// gather results
|
750 |
+
local nvars: list sizeof varlist
|
751 |
+
tempname diff count
|
752 |
+
mat `diff' = J(1, `nvars', .)
|
753 |
+
mat coln `diff' = `varlist'
|
754 |
+
mat `count' = `diff'
|
755 |
+
local mnames se /*sd*/ t df_t p_l p p_u N_1 mu_1 /*sd_1*/ N_2 mu_2 /*sd_2*/
|
756 |
+
foreach m of local mnames {
|
757 |
+
tempname `m'
|
758 |
+
mat ``m'' = `diff'
|
759 |
+
}
|
760 |
+
local i 0
|
761 |
+
foreach v of local varlist {
|
762 |
+
local ++i
|
763 |
+
qui ttest `v' if `touse', by(`by') `unequal' `welch'
|
764 |
+
mat `diff'[1,`i'] = r(mu_1) - r(mu_2)
|
765 |
+
mat `count'[1,`i'] = r(N_1) + r(N_2)
|
766 |
+
foreach m of local mnames {
|
767 |
+
mat ``m''[1,`i'] = r(`m')
|
768 |
+
}
|
769 |
+
}
|
770 |
+
|
771 |
+
// display
|
772 |
+
if "`quietly'"=="" {
|
773 |
+
tempname res
|
774 |
+
mat `res' = `diff'', `count''
|
775 |
+
local rescoln "e(b) e(count)"
|
776 |
+
foreach m of local mnames {
|
777 |
+
mat `res' = `res', ``m'''
|
778 |
+
local rescoln `rescoln' e(`m')
|
779 |
+
}
|
780 |
+
mat coln `res' = `rescoln'
|
781 |
+
if c(stata_version)<9 {
|
782 |
+
mat list `res', noheader nohalf format(%9.0g)
|
783 |
+
}
|
784 |
+
else {
|
785 |
+
matlist `res', nohalf lines(oneline)
|
786 |
+
}
|
787 |
+
mat drop `res'
|
788 |
+
}
|
789 |
+
|
790 |
+
// post results
|
791 |
+
local V
|
792 |
+
if c(stata_version)<9 { // V required in Stata 8
|
793 |
+
tempname V
|
794 |
+
mat `V' = diag(vecdiag(`se'' * `se'))
|
795 |
+
}
|
796 |
+
if "`esample'"!="" local esample esample(`touse')
|
797 |
+
eret post `diff' `V', obs(`N') `esample'
|
798 |
+
|
799 |
+
eret scalar k = `nvars'
|
800 |
+
|
801 |
+
eret local wexp `"`exp'"'
|
802 |
+
eret local wtype `"`weight'"'
|
803 |
+
eret local welch "`welch'"
|
804 |
+
eret local unequal "`unequal'"
|
805 |
+
eret local byvar "`by'"
|
806 |
+
eret local subcmd "ttest"
|
807 |
+
eret local cmd "estpost"
|
808 |
+
|
809 |
+
local nmat: list sizeof mnames
|
810 |
+
forv i=`nmat'(-1)1 {
|
811 |
+
local m: word `i' of `mnames'
|
812 |
+
eret matrix `m' = ``m''
|
813 |
+
}
|
814 |
+
eret matrix count = `count'
|
815 |
+
end
|
816 |
+
|
817 |
+
|
818 |
+
* 6. estpost_correlate: wrapper for -correlate-
|
819 |
+
prog estpost_correlate, eclass
|
820 |
+
version 8.2
|
821 |
+
local caller : di _caller() // not used
|
822 |
+
|
823 |
+
// syntax
|
824 |
+
syntax varlist [if] [in] [aw fw iw pw] [, ESample Quietly ///
|
825 |
+
LISTwise CASEwise ///
|
826 |
+
Matrix noHalf Print(real 1) /*Covariance*/ Bonferroni SIDak ]
|
827 |
+
if "`casewise'"!="" local listwise listwise
|
828 |
+
if "`bonferroni'"!="" & "`sidak'"!="" {
|
829 |
+
di as err "only one of bonferroni and sidak allowed"
|
830 |
+
exit 198
|
831 |
+
}
|
832 |
+
local pw = ("`weight'"=="pweight")
|
833 |
+
if `:list sizeof varlist'<=1 & `"`matrix'"'=="" {
|
834 |
+
di as err "too few variables specified"
|
835 |
+
exit 102
|
836 |
+
}
|
837 |
+
if `"`matrix'"'!="" & `"`half'"'!="" local fullmatrix fullmatrix
|
838 |
+
|
839 |
+
// sample
|
840 |
+
if "`listwise'"!="" marksample touse
|
841 |
+
else {
|
842 |
+
marksample touse, nov
|
843 |
+
_estpost_markout2 `touse' `varlist'
|
844 |
+
}
|
845 |
+
qui count if `touse'
|
846 |
+
local N = r(N)
|
847 |
+
if `N'==0 error 2000
|
848 |
+
|
849 |
+
// gather results
|
850 |
+
tempname b rho pval count
|
851 |
+
if "`bonferroni'`sidak'"!="" {
|
852 |
+
local nvars : list sizeof varlist
|
853 |
+
local k = `nvars' * (`nvars'-1) / 2
|
854 |
+
}
|
855 |
+
foreach depvar of local varlist {
|
856 |
+
if `"`fullmatrix'"'!="" {
|
857 |
+
local indepvars `varlist'
|
858 |
+
}
|
859 |
+
else if `"`matrix'"'!="" {
|
860 |
+
local indepvars `depvar' `ferest()'
|
861 |
+
}
|
862 |
+
else {
|
863 |
+
local indepvars `ferest()'
|
864 |
+
}
|
865 |
+
foreach v of local indepvars {
|
866 |
+
qui reg `depvar' `v' [`weight'`exp'] if `touse'
|
867 |
+
local r = sqrt(e(r2)) * (-1)^(_b[`v']<0)
|
868 |
+
local n = e(N)
|
869 |
+
mat `b' = nullmat(`b'), `r'
|
870 |
+
if "`depvar'"=="`v'" {
|
871 |
+
mat `rho' = nullmat(`rho'), `r'
|
872 |
+
mat `count' = nullmat(`count'), `n'
|
873 |
+
mat `pval' = nullmat(`pval'), .z
|
874 |
+
continue
|
875 |
+
}
|
876 |
+
local p = Ftail(e(df_m), e(df_r), e(F))
|
877 |
+
if `pw' {
|
878 |
+
qui reg `v' `depvar' [`weight'`exp'] if `touse'
|
879 |
+
local p = max(`p', Ftail(e(df_m), e(df_r), e(F)))
|
880 |
+
}
|
881 |
+
if "`bonferroni'"!="" {
|
882 |
+
local p = min(1, `k'*`p')
|
883 |
+
}
|
884 |
+
else if "`sidak'"!="" {
|
885 |
+
local p = min(1, 1 - (1-`p')^`k')
|
886 |
+
}
|
887 |
+
if `p'>`print' {
|
888 |
+
local r .z
|
889 |
+
local n .z
|
890 |
+
local p .z
|
891 |
+
}
|
892 |
+
mat `rho' = nullmat(`rho'), `r'
|
893 |
+
mat `count' = nullmat(`count'), `n'
|
894 |
+
mat `pval' = nullmat(`pval'), `p'
|
895 |
+
}
|
896 |
+
if `"`matrix'`fullmatrix'"'=="" {
|
897 |
+
local colnames `indepvars'
|
898 |
+
local depname `depvar'
|
899 |
+
continue, break
|
900 |
+
}
|
901 |
+
foreach v of local indepvars {
|
902 |
+
local colnames `"`colnames'`depvar':`v' "'
|
903 |
+
}
|
904 |
+
}
|
905 |
+
mat coln `b' = `colnames'
|
906 |
+
mat coln `rho' = `colnames'
|
907 |
+
mat coln `count' = `colnames'
|
908 |
+
mat coln `pval' = `colnames'
|
909 |
+
local vce `"`e(vce)'"' // from last -regress- call
|
910 |
+
local vcetype `"`e(vcetype)'"'
|
911 |
+
|
912 |
+
// display
|
913 |
+
if "`quietly'"=="" {
|
914 |
+
tempname res
|
915 |
+
mat `res' = `b'', `rho'', `pval'', `count''
|
916 |
+
mat coln `res' = e(b) e(rho) e(p) e(count)
|
917 |
+
if c(stata_version)<9 {
|
918 |
+
mat list `res', noheader nohalf format(%9.0g) nodotz
|
919 |
+
}
|
920 |
+
else {
|
921 |
+
matlist `res', nohalf lines(oneline) rowtitle(`depname') nodotz
|
922 |
+
}
|
923 |
+
mat drop `res'
|
924 |
+
}
|
925 |
+
|
926 |
+
// post results
|
927 |
+
local V
|
928 |
+
if c(stata_version)<9 { // V required in Stata 8
|
929 |
+
tempname V
|
930 |
+
mat `V' = `b'' * `b' * 0
|
931 |
+
}
|
932 |
+
if "`esample'"!="" local esample esample(`touse')
|
933 |
+
eret post `b' `V', depname(`depname') obs(`N') `esample'
|
934 |
+
eret local vcetype `"`vcetype'"'
|
935 |
+
eret local vce `"`vce'"'
|
936 |
+
eret local wexp `"`exp'"'
|
937 |
+
eret local wtype `"`weight'"'
|
938 |
+
eret local depvar `depname'
|
939 |
+
eret local subcmd "correlate"
|
940 |
+
eret local cmd "estpost"
|
941 |
+
eret matrix count = `count'
|
942 |
+
eret matrix p = `pval'
|
943 |
+
eret matrix rho = `rho'
|
944 |
+
end
|
945 |
+
|
946 |
+
|
947 |
+
* 7. estpost_stci: wrapper for -stci-
|
948 |
+
prog estpost_stci, eclass
|
949 |
+
version 9.2 // Stata 8 not supported because levelsof is used
|
950 |
+
local caller : di _caller() // not used
|
951 |
+
|
952 |
+
// syntax
|
953 |
+
syntax [if] [in] [ , ESample Quietly by(varname) ///
|
954 |
+
Median Rmean Emean p(numlist >0 <100 integer max=1) ///
|
955 |
+
CCorr Level(real `c(level)') ]
|
956 |
+
local stat "p50"
|
957 |
+
if `"`p'"'!="" {
|
958 |
+
local stat `"p`p'"'
|
959 |
+
local p `"p(`p')"'
|
960 |
+
}
|
961 |
+
else if "`rmean'"!="" local stat "rmean"
|
962 |
+
else if "`emean'"!="" local stat "emean"
|
963 |
+
|
964 |
+
// sample
|
965 |
+
marksample touse
|
966 |
+
if `"`by'"'!="" {
|
967 |
+
markout `touse' `by', strok
|
968 |
+
}
|
969 |
+
qui count if `touse'
|
970 |
+
local N = r(N)
|
971 |
+
if `N'==0 error 2000
|
972 |
+
|
973 |
+
// get results
|
974 |
+
tempname _`stat' se N_sub lb ub
|
975 |
+
if "`by'"!="" {
|
976 |
+
qui levelsof `by' if `touse', local(levels)
|
977 |
+
capt confirm string variable `by'
|
978 |
+
if _rc {
|
979 |
+
local vallab: value label `by'
|
980 |
+
if `"`vallab'"'!="" {
|
981 |
+
_estpost_namesandlabels `by' `"`levels'"' // sets names, savenames, labels
|
982 |
+
}
|
983 |
+
else {
|
984 |
+
local names `"`levels'"'
|
985 |
+
local savenames `"`levels'"'
|
986 |
+
}
|
987 |
+
}
|
988 |
+
else {
|
989 |
+
_estpost_namesandlabels `by' "" `"`levels'"' // sets names, savenames, labels
|
990 |
+
}
|
991 |
+
}
|
992 |
+
local levels `"`levels' "total""'
|
993 |
+
local names `"`names' "total""'
|
994 |
+
local savenames `"`savenames' "total""'
|
995 |
+
gettoken l rest : levels, quotes
|
996 |
+
while (`"`l'"'!="") {
|
997 |
+
if `"`rest'"'=="" local lcond
|
998 |
+
else local lcond `" & `by'==`l'"'
|
999 |
+
qui stci if `touse'`lcond', `median' `rmean' `emean' `p' `ccorr' level(`level')
|
1000 |
+
mat `_`stat'' = nullmat(`_`stat''), r(`stat')
|
1001 |
+
mat `se' = nullmat(`se'), r(se)
|
1002 |
+
mat `N_sub' = nullmat(`N_sub'), r(N_sub)
|
1003 |
+
mat `lb' = nullmat(`lb'), r(lb)
|
1004 |
+
mat `ub' = nullmat(`ub'), r(ub)
|
1005 |
+
gettoken l rest : rest, quotes
|
1006 |
+
}
|
1007 |
+
foreach m in _`stat' se N_sub lb ub {
|
1008 |
+
mat coln ``m'' = `names'
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
// display
|
1012 |
+
if "`quietly'"=="" {
|
1013 |
+
tempname res
|
1014 |
+
mat `res' = `N_sub'', `_`stat''', `se'', `lb'', `ub''
|
1015 |
+
mat coln `res' = e(count) e(`stat') e(se) e(lb) e(ub)
|
1016 |
+
di as txt "(confidence level is " `level' "%)"
|
1017 |
+
if c(stata_version)<9 {
|
1018 |
+
mat list `res', noheader nohalf format(%9.0g) nodotz
|
1019 |
+
}
|
1020 |
+
else {
|
1021 |
+
mat rown `res' = `savenames'
|
1022 |
+
matlist `res', nohalf lines(rowtotal) nodotz
|
1023 |
+
}
|
1024 |
+
mat drop `res'
|
1025 |
+
if `"`labels'"'!="" {
|
1026 |
+
di _n as txt "labels saved in macro e(labels)"
|
1027 |
+
}
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
// post results
|
1031 |
+
local b
|
1032 |
+
local V
|
1033 |
+
if c(stata_version)<9 { // b and V required in Stata 8
|
1034 |
+
tempname b V
|
1035 |
+
mat `b' = `_`stat'' \ J(1, colsof(`_`stat''), 0)
|
1036 |
+
mat `b' = `b'[2,1...]
|
1037 |
+
mat `V' = `b'' * `b'
|
1038 |
+
}
|
1039 |
+
if "`esample'"!="" local esample esample(`touse')
|
1040 |
+
eret post `b' `V', obs(`N') `esample'
|
1041 |
+
eret scalar level = `level'
|
1042 |
+
|
1043 |
+
eret local ccorr `ccorr'
|
1044 |
+
eret local labels `"`labels'"'
|
1045 |
+
eret local subcmd "stci"
|
1046 |
+
eret local cmd "estpost"
|
1047 |
+
|
1048 |
+
eret matrix ub = `ub'
|
1049 |
+
eret matrix lb = `lb'
|
1050 |
+
eret matrix se = `se'
|
1051 |
+
eret matrix `stat' = `_`stat''
|
1052 |
+
eret matrix count = `N_sub'
|
1053 |
+
end
|
1054 |
+
|
1055 |
+
|
1056 |
+
* 8. estpost_ci: wrapper for -ci-
|
1057 |
+
prog estpost_ci, eclass
|
1058 |
+
version 8.2
|
1059 |
+
local caller : di _caller() // not used
|
1060 |
+
|
1061 |
+
// syntax
|
1062 |
+
syntax [varlist] [if] [in] [aw fw], [ ESample Quietly ///
|
1063 |
+
LISTwise CASEwise Level(real `c(level)') ///
|
1064 |
+
Binomial EXAct WAld Wilson Agresti Jeffreys ///
|
1065 |
+
Poisson Exposure(varname) ///
|
1066 |
+
]
|
1067 |
+
if "`casewise'"!="" local listwise listwise
|
1068 |
+
if "`exposure'"!="" local exposureopt "exposure(`exposure')"
|
1069 |
+
if "`binomial'"!="" & "`exact'`wald'`wilson'`agresti'`jeffreys'"=="" local exact exact
|
1070 |
+
|
1071 |
+
// sample
|
1072 |
+
if "`listwise'"!="" marksample touse
|
1073 |
+
else {
|
1074 |
+
marksample touse, nov
|
1075 |
+
_estpost_markout2 `touse' `varlist'
|
1076 |
+
}
|
1077 |
+
qui count if `touse'
|
1078 |
+
local N = r(N)
|
1079 |
+
if `N'==0 error 2000
|
1080 |
+
|
1081 |
+
// gather results
|
1082 |
+
local mnames se lb ub
|
1083 |
+
tempname mean count `mnames'
|
1084 |
+
local i 0
|
1085 |
+
foreach v of local varlist {
|
1086 |
+
local ++i
|
1087 |
+
qui ci `v' if `touse' [`weight'`exp'], level(`level') ///
|
1088 |
+
`binomial' `exact' `wald' `wilson' `agresti' `jeffreys' ///
|
1089 |
+
`poisson' `exposureopt'
|
1090 |
+
if r(N)>=. continue
|
1091 |
+
mat `mean' = nullmat(`mean'), r(mean)
|
1092 |
+
mat `count' = nullmat(`count'), r(N)
|
1093 |
+
foreach m of local mnames {
|
1094 |
+
mat ``m'' = nullmat(``m''), r(`m')
|
1095 |
+
}
|
1096 |
+
local rnames "`rnames' `v'"
|
1097 |
+
}
|
1098 |
+
capt confirm matrix `count'
|
1099 |
+
if _rc {
|
1100 |
+
di as txt "nothing to post"
|
1101 |
+
eret clear
|
1102 |
+
exit
|
1103 |
+
}
|
1104 |
+
foreach m in mean count `mnames' {
|
1105 |
+
mat coln ``m'' = `rnames'
|
1106 |
+
}
|
1107 |
+
if "`listwise'"=="" { // update sample
|
1108 |
+
if colsof(`count') < `: list sizeof varlist' {
|
1109 |
+
_estpost_markout2 `touse' `rnames'
|
1110 |
+
qui count if `touse'
|
1111 |
+
local N = r(N)
|
1112 |
+
}
|
1113 |
+
}
|
1114 |
+
|
1115 |
+
// display
|
1116 |
+
if "`quietly'"=="" {
|
1117 |
+
tempname res
|
1118 |
+
mat `res' = `mean'', `count''
|
1119 |
+
local rescoln "e(b) e(count)"
|
1120 |
+
foreach m of local mnames {
|
1121 |
+
mat `res' = `res', ``m'''
|
1122 |
+
local rescoln `rescoln' e(`m')
|
1123 |
+
}
|
1124 |
+
mat coln `res' = `rescoln'
|
1125 |
+
di as txt "(confidence level is " `level' "%)"
|
1126 |
+
if c(stata_version)<9 {
|
1127 |
+
mat list `res', noheader nohalf format(%9.0g)
|
1128 |
+
}
|
1129 |
+
else {
|
1130 |
+
matlist `res', nohalf lines(oneline)
|
1131 |
+
}
|
1132 |
+
mat drop `res'
|
1133 |
+
}
|
1134 |
+
|
1135 |
+
// post results
|
1136 |
+
local V
|
1137 |
+
if c(stata_version)<9 { // V required in Stata 8
|
1138 |
+
tempname V
|
1139 |
+
mat `V' = diag(vecdiag(`se'' * `se'))
|
1140 |
+
}
|
1141 |
+
if "`esample'"!="" local esample esample(`touse')
|
1142 |
+
eret post `mean' `V', obs(`N') `esample'
|
1143 |
+
|
1144 |
+
eret scalar k = colsof(`count')
|
1145 |
+
eret scalar level = `level'
|
1146 |
+
|
1147 |
+
eret local wexp `"`exp'"'
|
1148 |
+
eret local wtype `"`weight'"'
|
1149 |
+
eret local exposure "`exposure'"
|
1150 |
+
eret local poisson "`poisson'"
|
1151 |
+
eret local binomial "`exact'`wald'`wilson'`agresti'`jeffreys'"
|
1152 |
+
eret local subcmd "ci"
|
1153 |
+
eret local cmd "estpost"
|
1154 |
+
|
1155 |
+
local nmat: list sizeof mnames
|
1156 |
+
forv i=`nmat'(-1)1 {
|
1157 |
+
local m: word `i' of `mnames'
|
1158 |
+
eret matrix `m' = ``m''
|
1159 |
+
}
|
1160 |
+
eret matrix count = `count'
|
1161 |
+
end
|
1162 |
+
|
1163 |
+
|
1164 |
+
* 9. estpost_prtest: wrapper for -prtest- (two-sample)
|
1165 |
+
prog estpost_prtest, eclass
|
1166 |
+
version 8.2
|
1167 |
+
local caller : di _caller() // not used
|
1168 |
+
|
1169 |
+
// syntax
|
1170 |
+
syntax varlist(numeric) [if] [in] , by(varname) [ ESample Quietly ///
|
1171 |
+
LISTwise CASEwise ]
|
1172 |
+
if "`casewise'"!="" local listwise listwise
|
1173 |
+
|
1174 |
+
// sample
|
1175 |
+
if "`listwise'"!="" marksample touse
|
1176 |
+
else {
|
1177 |
+
marksample touse, nov
|
1178 |
+
_estpost_markout2 `touse' `varlist'
|
1179 |
+
}
|
1180 |
+
markout `touse' `by', strok
|
1181 |
+
qui count if `touse'
|
1182 |
+
local N = r(N)
|
1183 |
+
if `N'==0 error 2000
|
1184 |
+
|
1185 |
+
// gather results
|
1186 |
+
local nvars: list sizeof varlist
|
1187 |
+
tempname diff count
|
1188 |
+
mat `count' = J(1, `nvars', .)
|
1189 |
+
mat coln `count' = `varlist'
|
1190 |
+
mat `diff' = `count'
|
1191 |
+
local mnames se se0 z p_l p p_u N_1 P_1 N_2 P_2
|
1192 |
+
foreach m of local mnames {
|
1193 |
+
tempname `m'
|
1194 |
+
mat ``m'' = `count'
|
1195 |
+
}
|
1196 |
+
local i 0
|
1197 |
+
foreach v of local varlist {
|
1198 |
+
local ++i
|
1199 |
+
qui prtest `v' if `touse', by(`by')
|
1200 |
+
mat `count'[1,`i'] = r(N_1) + r(N_2)
|
1201 |
+
mat `diff'[1,`i'] = r(P_1) - r(P_2)
|
1202 |
+
mat `se'[1,`i'] = sqrt(r(P_1)*(1-r(P_1))/r(N_1) + r(P_2)*(1-r(P_2))/r(N_2))
|
1203 |
+
mat `se0'[1,`i'] = `diff'[1,`i'] / r(z)
|
1204 |
+
mat `p_l'[1,`i'] = normal(r(z))
|
1205 |
+
mat `p'[1,`i'] = (1-normal(abs(r(z))))*2
|
1206 |
+
mat `p_u'[1,`i'] = 1-normal(r(z))
|
1207 |
+
foreach m in z N_1 P_1 N_2 P_2 {
|
1208 |
+
mat ``m''[1,`i'] = r(`m')
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
// display
|
1213 |
+
if "`quietly'"=="" {
|
1214 |
+
tempname res
|
1215 |
+
mat `res' = `diff'', `count''
|
1216 |
+
local rescoln "e(b) e(count)"
|
1217 |
+
foreach m of local mnames {
|
1218 |
+
mat `res' = `res', ``m'''
|
1219 |
+
local rescoln `rescoln' e(`m')
|
1220 |
+
}
|
1221 |
+
mat coln `res' = `rescoln'
|
1222 |
+
if c(stata_version)<9 {
|
1223 |
+
mat list `res', noheader nohalf format(%9.0g)
|
1224 |
+
}
|
1225 |
+
else {
|
1226 |
+
matlist `res', nohalf lines(oneline)
|
1227 |
+
}
|
1228 |
+
mat drop `res'
|
1229 |
+
}
|
1230 |
+
|
1231 |
+
// post results
|
1232 |
+
local V
|
1233 |
+
if c(stata_version)<9 { // V required in Stata 8
|
1234 |
+
tempname V
|
1235 |
+
mat `V' = diag(vecdiag(`se'' * `se'))
|
1236 |
+
}
|
1237 |
+
if "`esample'"!="" local esample esample(`touse')
|
1238 |
+
eret post `diff' `V', obs(`N') `esample'
|
1239 |
+
|
1240 |
+
eret scalar k = `nvars'
|
1241 |
+
|
1242 |
+
eret local wexp `"`exp'"'
|
1243 |
+
eret local wtype `"`weight'"'
|
1244 |
+
eret local byvar "`by'"
|
1245 |
+
eret local subcmd "prtest"
|
1246 |
+
eret local cmd "estpost"
|
1247 |
+
|
1248 |
+
local nmat: list sizeof mnames
|
1249 |
+
forv i=`nmat'(-1)1 {
|
1250 |
+
local m: word `i' of `mnames'
|
1251 |
+
eret matrix `m' = ``m''
|
1252 |
+
}
|
1253 |
+
eret matrix count = `count'
|
1254 |
+
end
|
1255 |
+
|
1256 |
+
|
1257 |
+
* 10. estpost__svy_tabulate: wrapper for -svy:tabulate-
|
1258 |
+
prog estpost__svy_tabulate
|
1259 |
+
version 9.2
|
1260 |
+
local caller : di _caller()
|
1261 |
+
_on_colon_parse `0'
|
1262 |
+
local svyopts `"svyopts(`s(before)')"'
|
1263 |
+
local 0 `"`s(after)'"'
|
1264 |
+
syntax varlist(min=1 max=2) [if] [in] [ , * ]
|
1265 |
+
if `:list sizeof varlist'==1 {
|
1266 |
+
version `caller': _svy_tabulate_oneway `varlist' `if' `in', ///
|
1267 |
+
`svyopts' `options'
|
1268 |
+
}
|
1269 |
+
else {
|
1270 |
+
version `caller': _svy_tabulate_twoway `varlist' `if' `in', ///
|
1271 |
+
`svyopts' `options'
|
1272 |
+
}
|
1273 |
+
end
|
1274 |
+
prog _svy_tabulate_oneway
|
1275 |
+
version 9.2
|
1276 |
+
local caller : di _caller() // not used
|
1277 |
+
|
1278 |
+
// syntax
|
1279 |
+
syntax varname [if] [in] [, ESample Quietly ///
|
1280 |
+
svyopts(str asis) MISSing Level(cilevel) ///
|
1281 |
+
noTOTal noMARGinals noLabel PROPortion PERcent ///
|
1282 |
+
CELl COUnt se ci deff deft * ]
|
1283 |
+
if "`marginals'"!="" local total "nototal"
|
1284 |
+
else if "`total'"!="" local marginals "nomarginals"
|
1285 |
+
|
1286 |
+
// run svy:tabulate
|
1287 |
+
`quietly' svy `svyopts' : tabulate `varlist' `if' `in', ///
|
1288 |
+
level(`level') `cell' `count' `se' `ci' `deff' `deft' ///
|
1289 |
+
`missing' `marginals' `label' `proportion' `percent' `options'
|
1290 |
+
if "`count'"!="" & "`cell'`se'`ci'`deff'`deft'"=="" { // => return count in e(b)
|
1291 |
+
quietly svy `svyopts' : tabulate `varlist' `if' `in', count se ///
|
1292 |
+
level(`level') `missing' `marginals' `label' `proportion' `percent' `options'
|
1293 |
+
}
|
1294 |
+
|
1295 |
+
// get labels
|
1296 |
+
qui levelsof `varlist' if e(sample), `missing' local(levels)
|
1297 |
+
local R : list sizeof levels
|
1298 |
+
if e(r)!=`R' {
|
1299 |
+
di as err "unexpected error; number of rows unequal number of levels"
|
1300 |
+
exit 499
|
1301 |
+
}
|
1302 |
+
capt confirm string variable `varlist'
|
1303 |
+
if _rc {
|
1304 |
+
if "`label'"=="" {
|
1305 |
+
_estpost_namesandlabels `varlist' "`levels'" // sets names, savenames, labels
|
1306 |
+
}
|
1307 |
+
else {
|
1308 |
+
_estpost_namesandlabels "" "`levels'" // sets names, savenames, labels
|
1309 |
+
}
|
1310 |
+
}
|
1311 |
+
else {
|
1312 |
+
_estpost_namesandlabels "" "" `"`levels'"' // sets names, savenames, labels
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
// collect results
|
1316 |
+
tempname cell count obs b se lb ub deff deft
|
1317 |
+
local N_pop = cond(e(N_subpop)<., e(N_subpop), e(N_pop))
|
1318 |
+
local N_obs = cond(e(N_sub)<., e(N_sub), e(N))
|
1319 |
+
local tval = invttail(e(df_r), (100-`level')/200)
|
1320 |
+
mat `cell' = e(Prop)'
|
1321 |
+
mat `count' = `cell' * `N_pop'
|
1322 |
+
capture confirm matrix e(ObsSub)
|
1323 |
+
if _rc {
|
1324 |
+
mat `obs' = e(Obs)'
|
1325 |
+
}
|
1326 |
+
else {
|
1327 |
+
mat `obs' = e(ObsSub)'
|
1328 |
+
}
|
1329 |
+
capture confirm matrix e(Deff)
|
1330 |
+
if _rc local DEFF ""
|
1331 |
+
else {
|
1332 |
+
local DEFF deff
|
1333 |
+
mat `deff' = e(Deff)
|
1334 |
+
}
|
1335 |
+
capture confirm matrix e(Deft)
|
1336 |
+
if _rc local DEFT ""
|
1337 |
+
else {
|
1338 |
+
local DEFT deft
|
1339 |
+
mat `deft' = e(Deft)
|
1340 |
+
}
|
1341 |
+
mat `b' = e(b)
|
1342 |
+
mata: st_matrix(st_local("se"), sqrt(diagonal(st_matrix("e(V)")))')
|
1343 |
+
if "`total'"=="" {
|
1344 |
+
mat `cell' = `cell', 1
|
1345 |
+
mat `count' = `count', `N_pop'
|
1346 |
+
mat `obs' = `obs', `N_obs'
|
1347 |
+
if "`DEFF'"!="" mat `deff' = `deff', .z
|
1348 |
+
if "`DEFT'"!="" mat `deft' = `deft', .z
|
1349 |
+
if e(setype)=="count" {
|
1350 |
+
mat `b' = `b', `N_pop'
|
1351 |
+
mat `se' = `se', sqrt(el(e(V_col),1,1))
|
1352 |
+
}
|
1353 |
+
else { // e(setype)=="cell"
|
1354 |
+
mat `b' = `b', 1
|
1355 |
+
mat `se' = `se', 0
|
1356 |
+
}
|
1357 |
+
local names `"`names' "Total""'
|
1358 |
+
local savenames `"`savenames' "Total""'
|
1359 |
+
local linesopt "lines(rowtotal)"
|
1360 |
+
|
1361 |
+
}
|
1362 |
+
if e(setype)!="count" {
|
1363 |
+
mata: st_matrix( st_local("lb"), invlogit( ///
|
1364 |
+
logit(st_matrix(st_local("b"))) - strtoreal(st_local("tval")) * ///
|
1365 |
+
st_matrix(st_local("se")) :/ ///
|
1366 |
+
(st_matrix(st_local("b")) :* (1 :- st_matrix(st_local("b"))))))
|
1367 |
+
mata: st_matrix( st_local("ub"), invlogit( ///
|
1368 |
+
logit(st_matrix(st_local("b"))) + strtoreal(st_local("tval")) * ///
|
1369 |
+
st_matrix(st_local("se")) :/ ///
|
1370 |
+
(st_matrix(st_local("b")) :* (1 :- st_matrix(st_local("b"))))))
|
1371 |
+
if "`total'"=="" {
|
1372 |
+
mat `lb'[1, colsof(`lb')] = .z
|
1373 |
+
mat `ub'[1, colsof(`ub')] = .z
|
1374 |
+
}
|
1375 |
+
}
|
1376 |
+
else {
|
1377 |
+
mata: st_matrix( st_local("lb"), st_matrix(st_local("b")) - ///
|
1378 |
+
strtoreal(st_local("tval")) * st_matrix(st_local("se")) )
|
1379 |
+
mata: st_matrix( st_local("ub"), st_matrix(st_local("b")) + ///
|
1380 |
+
strtoreal(st_local("tval")) * st_matrix(st_local("se")) )
|
1381 |
+
}
|
1382 |
+
foreach m in cell count obs b se lb ub `DEFF' `DEFT' {
|
1383 |
+
capt mat coln ``m'' = `names'
|
1384 |
+
}
|
1385 |
+
if "`percent'"!="" {
|
1386 |
+
mat `cell' = `cell' * 100
|
1387 |
+
if e(setype)!="count" {
|
1388 |
+
mat `b' = `b' * 100
|
1389 |
+
mat `se' = `se' * 100
|
1390 |
+
mat `lb' = `lb' * 100
|
1391 |
+
mat `ub' = `ub' * 100
|
1392 |
+
}
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
// display
|
1396 |
+
if "`quietly'"=="" {
|
1397 |
+
/*
|
1398 |
+
tempname res
|
1399 |
+
mat `res' = `b'', `se'', `lb'', `ub'', `deff'', `deft'' ///, `cell'', `count'', `obs''
|
1400 |
+
mat coln `res' = e(b) e(se) e(lb) e(ub) e(deff) e(deft) /// e(cell) e(count) e(obs)
|
1401 |
+
if c(stata_version)<9 {
|
1402 |
+
mat list `res', noheader nohalf format(%9.0g) nodotz
|
1403 |
+
}
|
1404 |
+
else {
|
1405 |
+
mat rown `res' = `savenames'
|
1406 |
+
matlist `res', nohalf `linesopt' rowtitle(`varlist') nodotz
|
1407 |
+
}
|
1408 |
+
mat drop `res'
|
1409 |
+
*/
|
1410 |
+
local plabel = cond("`percent'"!="","percentages","proportions")
|
1411 |
+
local blabel = cond("`e(setype)'"=="count", "weighted counts", "`e(setype)' `plabel'")
|
1412 |
+
di _n as txt "saved vectors:"
|
1413 |
+
di as txt %20s "e(b) = " " " as res "`blabel'"
|
1414 |
+
di as txt %20s "e(se) = " " " as res "standard errors of `blabel'"
|
1415 |
+
di as txt %20s "e(lb) = " " " as res "lower `level'% confidence bounds for `blabel'"
|
1416 |
+
di as txt %20s "e(ub) = " " " as res "upper `level'% confidence bounds for `blabel'"
|
1417 |
+
if "`DEFF'"!="" ///
|
1418 |
+
di as txt %20s "e(deff) = " " " as res "deff for variances of `blabel'"
|
1419 |
+
if "`DEFT'"!="" ///
|
1420 |
+
di as txt %20s "e(deft) = " " " as res "deft for variances of `blabel'"
|
1421 |
+
di as txt %20s "e(cell) = " " " as res "cell `plabel'"
|
1422 |
+
di as txt %20s "e(count) = " " " as res "weighted counts"
|
1423 |
+
di as txt %20s "e(obs) = " " " as res "number of observations"
|
1424 |
+
if `"`labels'"'!="" {
|
1425 |
+
di _n as txt "row labels saved in macro e(labels)"
|
1426 |
+
}
|
1427 |
+
}
|
1428 |
+
|
1429 |
+
// post results
|
1430 |
+
erepost b=`b', cmd(estpost) nov `esample'
|
1431 |
+
qui estadd local labels `"`labels'"'
|
1432 |
+
qui estadd local subcmd "tabulate"
|
1433 |
+
qui estadd scalar level = `level'
|
1434 |
+
foreach m in obs count cell `DEFT' `DEFF' ub lb se {
|
1435 |
+
qui estadd matrix `m' = ``m'', replace
|
1436 |
+
}
|
1437 |
+
end
|
1438 |
+
prog _svy_tabulate_twoway
|
1439 |
+
version 9.2
|
1440 |
+
local caller : di _caller() // not used
|
1441 |
+
|
1442 |
+
// syntax
|
1443 |
+
syntax varlist(min=1 max=2) [if] [in] [, ESample Quietly ///
|
1444 |
+
svyopts(str asis) MISSing Level(cilevel) ///
|
1445 |
+
noTOTal noMARGinals noLabel PROPortion PERcent ///
|
1446 |
+
CELl COUnt COLumn row se ci deff deft * ]
|
1447 |
+
if "`marginals'"!="" local total "nototal"
|
1448 |
+
else if "`total'"!="" local marginals "nomarginals"
|
1449 |
+
|
1450 |
+
// run svy:tabulate
|
1451 |
+
`quietly' svy `svyopts' : tabulate `varlist' `if' `in', ///
|
1452 |
+
level(`level') `cell' `count' `column' `row' `se' `ci' `deff' `deft' ///
|
1453 |
+
`missing' `marginals' `label' `proportion' `percent' `options'
|
1454 |
+
if `: word count `count' `column' `row''==1 & "`cell'`se'`ci'`deff'`deft'"=="" {
|
1455 |
+
quietly svy `svyopts' : tabulate `varlist' `if' `in', `count' `column' `row' se ///
|
1456 |
+
level(`level') `missing' `marginals' `label' `proportion' `percent' `options'
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
// get labels
|
1460 |
+
local rvar `"`e(rowvar)'"'
|
1461 |
+
qui levelsof `rvar' if e(sample), `missing' local(levels)
|
1462 |
+
local R : list sizeof levels
|
1463 |
+
if e(r)!=`R' {
|
1464 |
+
di as err "unexpected error; number of rows unequal number of rowvar levels"
|
1465 |
+
exit 499
|
1466 |
+
}
|
1467 |
+
capt confirm string variable `rvar'
|
1468 |
+
if _rc {
|
1469 |
+
if "`label'"=="" {
|
1470 |
+
_estpost_namesandlabels `rvar' "`levels'" // sets names, savenames, labels
|
1471 |
+
}
|
1472 |
+
else {
|
1473 |
+
_estpost_namesandlabels "" "`levels'" // sets names, savenames, labels
|
1474 |
+
}
|
1475 |
+
}
|
1476 |
+
else {
|
1477 |
+
_estpost_namesandlabels "" "" `"`levels'"' // sets names, savenames, labels
|
1478 |
+
}
|
1479 |
+
local cvar `"`e(colvar)'"'
|
1480 |
+
qui levelsof `cvar' if e(sample), `missing' local(levels)
|
1481 |
+
local C : list sizeof levels
|
1482 |
+
if e(c)!=`C' {
|
1483 |
+
di as err "unexpected error; number of column unequal number of colvar levels"
|
1484 |
+
exit 499
|
1485 |
+
}
|
1486 |
+
local savenames0 `"`savenames'"'
|
1487 |
+
local savenames
|
1488 |
+
capt confirm string variable `cvar'
|
1489 |
+
if _rc {
|
1490 |
+
if "`label'"=="" {
|
1491 |
+
_estpost_eqnamesandlabels `cvar' "`levels'" // sets eqnames, eqlabels
|
1492 |
+
}
|
1493 |
+
else {
|
1494 |
+
_estpost_eqnamesandlabels "" "`levels'" // sets eqnames, eqlabels
|
1495 |
+
}
|
1496 |
+
}
|
1497 |
+
else {
|
1498 |
+
_estpost_eqnamesandlabels "" "" `"`levels'"' // sets eqnames, eqlabels
|
1499 |
+
}
|
1500 |
+
|
1501 |
+
// collect results
|
1502 |
+
tempname tmp cell row col count obs b se lb ub deff deft
|
1503 |
+
local N_pop = cond(e(N_subpop)<., e(N_subpop), e(N_pop))
|
1504 |
+
local N_obs = cond(e(N_sub)<., e(N_sub), e(N))
|
1505 |
+
local tval = invttail(e(df_r), (100-`level')/200)
|
1506 |
+
mat `cell' = e(Prop) // r x c matrix
|
1507 |
+
mat `cell' = (`cell', `cell' * J(`C',1,1)) \ (J(1,`R',1) * `cell', 1)
|
1508 |
+
mat `count' = `cell' * `N_pop'
|
1509 |
+
mat `tmp' = `cell'[1..., `C'+1]
|
1510 |
+
mata: st_matrix(st_local("row"), st_matrix(st_local("cell")) :/ ///
|
1511 |
+
st_matrix(st_local("tmp")))
|
1512 |
+
mat `tmp' = `cell'[`R'+1, 1...]
|
1513 |
+
mata: st_matrix(st_local("col"), st_matrix(st_local("cell")) :/ ///
|
1514 |
+
st_matrix(st_local("tmp")))
|
1515 |
+
mat drop `tmp'
|
1516 |
+
capture confirm matrix e(ObsSub)
|
1517 |
+
if _rc {
|
1518 |
+
mat `obs' = e(Obs) // r x c matrix
|
1519 |
+
}
|
1520 |
+
else {
|
1521 |
+
mat `obs' = e(ObsSub) // r x c matrix
|
1522 |
+
}
|
1523 |
+
capt confirm matrix e(Deff)
|
1524 |
+
if _rc local DEFF ""
|
1525 |
+
else {
|
1526 |
+
local DEFF deff
|
1527 |
+
mat `deff' = e(Deff) // vector
|
1528 |
+
}
|
1529 |
+
capt confirm matrix e(Deft)
|
1530 |
+
if _rc local DEFT ""
|
1531 |
+
else {
|
1532 |
+
local DEFT deft
|
1533 |
+
mat `deft' = e(Deft) // vector
|
1534 |
+
}
|
1535 |
+
mat `b' = e(b) // vector
|
1536 |
+
mata: st_matrix(st_local("se"), sqrt(diagonal(st_matrix("e(V)")))') // vector
|
1537 |
+
if e(setype)=="count" local btype count
|
1538 |
+
else if e(setype)=="row" local btype row
|
1539 |
+
else if e(setype)=="column" local btype col
|
1540 |
+
else local btype cell
|
1541 |
+
foreach m in `DEFF' `DEFT' b se { // vector -> r x c matrix
|
1542 |
+
forv r = 1/`R' {
|
1543 |
+
local from = (`r'-1)*`C' + 1
|
1544 |
+
local to = `r'*`C'
|
1545 |
+
mat `tmp' = nullmat(`tmp') \ ``m''[1, `from'..`to']
|
1546 |
+
}
|
1547 |
+
mat drop ``m''
|
1548 |
+
mat rename `tmp' ``m''
|
1549 |
+
}
|
1550 |
+
if "`total'"=="" {
|
1551 |
+
mat `obs' = (`obs', `obs' * J(`C',1,1)) \ (J(1,`R',1) * `obs', `N_obs')
|
1552 |
+
if "`DEFF'"!="" mat `deff' = (`deff', e(Deff_row)') \ (e(Deff_col), .z)
|
1553 |
+
if "`DEFT'"!="" mat `deft' = (`deft', e(Deft_row)') \ (e(Deft_col), .z)
|
1554 |
+
mat `b' = (`b', ``btype''[1..`R',`C'+1]) \ ``btype''[`R'+1,1...]
|
1555 |
+
mata: st_matrix(st_local("se"), ///
|
1556 |
+
((st_matrix(st_local("se")), sqrt(diagonal(st_matrix("e(V_row)")))) ///
|
1557 |
+
\ (sqrt(diagonal(st_matrix("e(V_col)")))', .z)))
|
1558 |
+
if "`btype'"=="row" {
|
1559 |
+
mat `se' = `se'[1..., 1..`C'], J(`R'+1, 1, .z)
|
1560 |
+
}
|
1561 |
+
else if "`btype'"=="col" {
|
1562 |
+
mat `se' = `se'[1..`R', 1...] \ J(1, `C'+1, .z)
|
1563 |
+
}
|
1564 |
+
local names `"`names' "Total""'
|
1565 |
+
local savenames0 `"`savenames0' "Total""'
|
1566 |
+
local eqnames `"`eqnames' "Total""'
|
1567 |
+
}
|
1568 |
+
else {
|
1569 |
+
mat `cell' = `cell'[1..`R', 1..`C']
|
1570 |
+
mat `count' = `count'[1..`R', 1..`C']
|
1571 |
+
mat `row' = `row'[1..`R', 1..`C']
|
1572 |
+
mat `col' = `col'[1..`R', 1..`C']
|
1573 |
+
}
|
1574 |
+
if "`btype'"!="count" {
|
1575 |
+
mata: st_matrix( st_local("lb"), invlogit( ///
|
1576 |
+
logit(st_matrix(st_local("b"))) - strtoreal(st_local("tval")) * ///
|
1577 |
+
st_matrix(st_local("se")) :/ ///
|
1578 |
+
(st_matrix(st_local("b")) :* (1 :- st_matrix(st_local("b"))))))
|
1579 |
+
mata: st_matrix( st_local("ub"), invlogit( ///
|
1580 |
+
logit(st_matrix(st_local("b"))) + strtoreal(st_local("tval")) * ///
|
1581 |
+
st_matrix(st_local("se")) :/ ///
|
1582 |
+
(st_matrix(st_local("b")) :* (1 :- st_matrix(st_local("b"))))))
|
1583 |
+
}
|
1584 |
+
else {
|
1585 |
+
mata: st_matrix( st_local("lb"), st_matrix(st_local("b")) - ///
|
1586 |
+
strtoreal(st_local("tval")) * st_matrix(st_local("se")) )
|
1587 |
+
mata: st_matrix( st_local("ub"), st_matrix(st_local("b")) + ///
|
1588 |
+
strtoreal(st_local("tval")) * st_matrix(st_local("se")) )
|
1589 |
+
}
|
1590 |
+
if "`total'"=="" {
|
1591 |
+
if "`btype'"=="row" {
|
1592 |
+
mat `lb' = `lb'[1..., 1..`C'] , J(`R'+1, 1, .z)
|
1593 |
+
mat `ub' = `ub'[1..., 1..`C'] , J(`R'+1, 1, .z)
|
1594 |
+
}
|
1595 |
+
else if "`btype'"=="col" {
|
1596 |
+
mat `lb' = `lb'[1..`R', 1...] \ J(1, `C'+1, .z)
|
1597 |
+
mat `ub' = `ub'[1..`R', 1...] \ J(1, `C'+1, .z)
|
1598 |
+
}
|
1599 |
+
else {
|
1600 |
+
mat `lb'[`R'+1, `C'+1] = .z
|
1601 |
+
mat `ub'[`R'+1, `C'+1] = .z
|
1602 |
+
}
|
1603 |
+
}
|
1604 |
+
foreach m in cell count obs row col `DEFF' `DEFT' b se lb ub { // r x c matrix -> vector
|
1605 |
+
mat rown ``m'' = `names'
|
1606 |
+
gettoken eq rest : eqnames
|
1607 |
+
forv c = 1/`=colsof(``m'')' {
|
1608 |
+
mat roweq ``m'' = `"`eq'"'
|
1609 |
+
mat `tmp' = nullmat(`tmp'), ``m''[1...,`c']'
|
1610 |
+
gettoken eq rest : rest
|
1611 |
+
}
|
1612 |
+
mat drop ``m''
|
1613 |
+
mat rename `tmp' ``m''
|
1614 |
+
}
|
1615 |
+
if "`percent'"!="" {
|
1616 |
+
mat `cell' = `cell' * 100
|
1617 |
+
mat `col' = `col' * 100
|
1618 |
+
mat `row' = `row' * 100
|
1619 |
+
if e(setype)!="count" {
|
1620 |
+
mat `b' = `b' * 100
|
1621 |
+
mat `se' = `se' * 100
|
1622 |
+
mat `lb' = `lb' * 100
|
1623 |
+
mat `ub' = `ub' * 100
|
1624 |
+
}
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
// display
|
1628 |
+
if "`quietly'"=="" {
|
1629 |
+
/*
|
1630 |
+
forv c = 1/`=colsof(`cell')' {
|
1631 |
+
local savenames `"`savenames' `savenames0'"'
|
1632 |
+
}
|
1633 |
+
tempname res
|
1634 |
+
mat `res' = `b'', `se'', `lb'', `ub'', `deff'', `deft'', `cell'', `row'', `col'', `count'', `obs''
|
1635 |
+
mat coln `res' = e(b) e(se) e(lb) e(ub) e(deff) e(deft) e(cell) e(row) e(col) e(count) e(obs)
|
1636 |
+
if c(stata_version)<9 {
|
1637 |
+
mat list `res', noheader nohalf format(%9.0g) nodotz
|
1638 |
+
}
|
1639 |
+
else {
|
1640 |
+
mat rown `res' = `savenames'
|
1641 |
+
di _n as res %-12s abbrev("`cvar'",12) as txt " {c |}{space 44}"
|
1642 |
+
matlist `res', twidth(12) format(%9.0g) noblank nohalf ///
|
1643 |
+
rowtitle(`rvar') nodotz
|
1644 |
+
}
|
1645 |
+
mat drop `res'
|
1646 |
+
*/
|
1647 |
+
local plabel = cond("`percent'"!="","percentages","proportions")
|
1648 |
+
local blabel = cond("`e(setype)'"=="count", "weighted counts", "`e(setype)' `plabel'")
|
1649 |
+
di _n as txt "saved vectors:"
|
1650 |
+
di as txt %20s "e(b) = " " " as res "`blabel'"
|
1651 |
+
di as txt %20s "e(se) = " " " as res "standard errors of `blabel'"
|
1652 |
+
di as txt %20s "e(lb) = " " " as res "lower `level'% confidence bounds for `blabel'"
|
1653 |
+
di as txt %20s "e(ub) = " " " as res "upper `level'% confidence bounds for `blabel'"
|
1654 |
+
if "`DEFF'"!="" ///
|
1655 |
+
di as txt %20s "e(deff) = " " " as res "deff for variances of `blabel'"
|
1656 |
+
if "`DEFT'"!="" ///
|
1657 |
+
di as txt %20s "e(deft) = " " " as res "deft for variances of `blabel'"
|
1658 |
+
di as txt %20s "e(cell) = " " " as res "cell `plabel'"
|
1659 |
+
di as txt %20s "e(row) = " " " as res "row `plabel'"
|
1660 |
+
di as txt %20s "e(col) = " " " as res "column `plabel'"
|
1661 |
+
di as txt %20s "e(count) = " " " as res "weighted counts"
|
1662 |
+
di as txt %20s "e(obs) = " " " as res "number of observations"
|
1663 |
+
if `"`labels'`eqlabels'"'!="" {
|
1664 |
+
di ""
|
1665 |
+
if `"`labels'"'!="" {
|
1666 |
+
di as txt "row labels saved in macro e(labels)"
|
1667 |
+
}
|
1668 |
+
if `"`eqlabels'"'!="" {
|
1669 |
+
di as txt "column labels saved in macro e(eqlabels)"
|
1670 |
+
}
|
1671 |
+
}
|
1672 |
+
}
|
1673 |
+
|
1674 |
+
// post results
|
1675 |
+
erepost b=`b', cmd(estpost) nov `esample'
|
1676 |
+
qui estadd local eqlabels `"`eqlabels'"'
|
1677 |
+
qui estadd local labels `"`labels'"'
|
1678 |
+
qui estadd local subcmd "tabulate"
|
1679 |
+
qui estadd scalar level = `level'
|
1680 |
+
foreach m in obs count row col cell `DEFT' `DEFF' ub lb se {
|
1681 |
+
qui estadd matrix `m' = ``m'', replace
|
1682 |
+
}
|
1683 |
+
end
|
1684 |
+
|
1685 |
+
* 11. estpost_margins: wrapper for -margins- (Stata 11)
|
1686 |
+
prog estpost_margins, eclass
|
1687 |
+
version 11
|
1688 |
+
local caller : di _caller()
|
1689 |
+
|
1690 |
+
// syntax
|
1691 |
+
_parse comma anything 0 : 0
|
1692 |
+
syntax [ , /*ESample*/ Quietly ///
|
1693 |
+
post * ]
|
1694 |
+
if "`post'"!="" {
|
1695 |
+
di as err "post not allowed"
|
1696 |
+
exit 198
|
1697 |
+
}
|
1698 |
+
|
1699 |
+
// run margins
|
1700 |
+
`quietly' version `caller': margins `anything', `options'
|
1701 |
+
|
1702 |
+
// post results
|
1703 |
+
capt postrtoe, noclear resize
|
1704 |
+
if _rc<=1 { // -postrtoe- does not work, e.g., with -regress-
|
1705 |
+
error _rc // _rc=1 (break)
|
1706 |
+
exit
|
1707 |
+
}
|
1708 |
+
tempname b V
|
1709 |
+
mat `b' = r(b)
|
1710 |
+
mat `V' = r(V)
|
1711 |
+
erepost b = `b' V = `V' /*, `esample'*/
|
1712 |
+
foreach r in `:r(scalars)' {
|
1713 |
+
eret scalar `r' = r(`r')
|
1714 |
+
}
|
1715 |
+
foreach r in `:r(macros)' {
|
1716 |
+
eret local `r' `"`r(`r')'"'
|
1717 |
+
}
|
1718 |
+
tempname tmp
|
1719 |
+
foreach r in `:r(matrices)' {
|
1720 |
+
if inlist("`r'", "b", "V") continue
|
1721 |
+
mat `tmp' = r(`r')
|
1722 |
+
eret matrix `r' = `tmp'
|
1723 |
+
}
|
1724 |
+
end
|
1725 |
+
|
1726 |
+
* 99.
|
1727 |
+
* copy of erepost.ado, version 1.0.1, Ben Jann, 30jul2007
|
1728 |
+
* 14jan2009: noV option added => repost e(b) and remove e(V) if not specified
|
1729 |
+
prog erepost, eclass
|
1730 |
+
version 8.2
|
1731 |
+
syntax [anything(equalok)] [, NOV cmd(str) noEsample Esample2(varname) REName ///
|
1732 |
+
Obs(passthru) Dof(passthru) PROPerties(passthru) * ]
|
1733 |
+
if "`esample'"!="" & "`esample2'"!="" {
|
1734 |
+
di as err "only one allowed of noesample and esample()"
|
1735 |
+
exit 198
|
1736 |
+
}
|
1737 |
+
// parse [b = b] [V = V]
|
1738 |
+
if `"`anything'"'!="" {
|
1739 |
+
tokenize `"`anything'"', parse(" =")
|
1740 |
+
if `"`7'"'!="" error 198
|
1741 |
+
if `"`1'"'=="b" {
|
1742 |
+
if `"`2'"'=="=" & `"`3'"'!="" {
|
1743 |
+
local b `"`3'"'
|
1744 |
+
confirm matrix `b'
|
1745 |
+
}
|
1746 |
+
else error 198
|
1747 |
+
if `"`4'"'=="V" {
|
1748 |
+
if `"`5'"'=="=" & `"`6'"'!="" {
|
1749 |
+
local v `"`6'"'
|
1750 |
+
confirm matrix `b'
|
1751 |
+
}
|
1752 |
+
else error 198
|
1753 |
+
}
|
1754 |
+
else if `"`4'"'!="" error 198
|
1755 |
+
}
|
1756 |
+
else if `"`1'"'=="V" {
|
1757 |
+
if `"`4'"'!="" error 198
|
1758 |
+
if `"`2'"'=="=" & `"`3'"'!="" {
|
1759 |
+
local v `"`3'"'
|
1760 |
+
confirm matrix `v'
|
1761 |
+
}
|
1762 |
+
else error 198
|
1763 |
+
}
|
1764 |
+
else error 198
|
1765 |
+
}
|
1766 |
+
//backup existing e()'s
|
1767 |
+
if "`esample2'"!="" {
|
1768 |
+
local sample "`esample2'"
|
1769 |
+
}
|
1770 |
+
else if "`esample'"=="" {
|
1771 |
+
tempvar sample
|
1772 |
+
gen byte `sample' = e(sample)
|
1773 |
+
}
|
1774 |
+
local emacros: e(macros)
|
1775 |
+
if `"`properties'"'!="" {
|
1776 |
+
local emacros: subinstr local emacros "properties" "", word
|
1777 |
+
}
|
1778 |
+
foreach emacro of local emacros {
|
1779 |
+
local e_`emacro' `"`e(`emacro')'"'
|
1780 |
+
}
|
1781 |
+
local escalars: e(scalars)
|
1782 |
+
if `"`obs'"'!="" {
|
1783 |
+
local escalars: subinstr local escalars "N" "", word
|
1784 |
+
}
|
1785 |
+
if `"`dof'"'!="" {
|
1786 |
+
local escalars: subinstr local escalars "df_r" "", word
|
1787 |
+
}
|
1788 |
+
foreach escalar of local escalars {
|
1789 |
+
tempname e_`escalar'
|
1790 |
+
scalar `e_`escalar'' = e(`escalar')
|
1791 |
+
}
|
1792 |
+
local ematrices: e(matrices)
|
1793 |
+
if "`v'"=="" & "`nov'"!="" { // added 14jan2009
|
1794 |
+
local nov V
|
1795 |
+
local ematrices : list ematrices - nov
|
1796 |
+
}
|
1797 |
+
if "`b'"=="" & `:list posof "b" in ematrices' {
|
1798 |
+
tempname b
|
1799 |
+
mat `b' = e(b)
|
1800 |
+
}
|
1801 |
+
if "`v'"=="" & `:list posof "V" in ematrices' {
|
1802 |
+
tempname v
|
1803 |
+
mat `v' = e(V)
|
1804 |
+
}
|
1805 |
+
local bV "b V"
|
1806 |
+
local ematrices: list ematrices - bV
|
1807 |
+
foreach ematrix of local ematrices {
|
1808 |
+
tempname e_`ematrix'
|
1809 |
+
matrix `e_`ematrix'' = e(`ematrix')
|
1810 |
+
}
|
1811 |
+
// rename
|
1812 |
+
if "`b'"!="" & "`v'"!="" & "`rename'"!="" {
|
1813 |
+
local eqnames: coleq `b', q
|
1814 |
+
local vnames: colnames `b'
|
1815 |
+
mat coleq `v' = `eqnames'
|
1816 |
+
mat coln `v' = `vnames'
|
1817 |
+
mat roweq `v' = `eqnames'
|
1818 |
+
mat rown `v' = `vnames'
|
1819 |
+
}
|
1820 |
+
// post results
|
1821 |
+
if "`esample'"=="" {
|
1822 |
+
eret post `b' `v', esample(`sample') `obs' `dof' `properties' `options'
|
1823 |
+
}
|
1824 |
+
else {
|
1825 |
+
eret post `b' `v', `obs' `dof' `properties' `options'
|
1826 |
+
}
|
1827 |
+
foreach emacro of local emacros {
|
1828 |
+
eret local `emacro' `"`e_`emacro''"'
|
1829 |
+
}
|
1830 |
+
if `"`cmd'"'!="" {
|
1831 |
+
eret local cmd `"`cmd'"'
|
1832 |
+
}
|
1833 |
+
foreach escalar of local escalars {
|
1834 |
+
eret scalar `escalar' = scalar(`e_`escalar'')
|
1835 |
+
}
|
1836 |
+
foreach ematrix of local ematrices {
|
1837 |
+
eret matrix `ematrix' = `e_`ematrix''
|
1838 |
+
}
|
1839 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/estpost.hlp
ADDED
@@ -0,0 +1,1322 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 13sep2013}{...}
|
3 |
+
{hi:help estpost}{right:also see: {helpb esttab}, {helpb estout}, {helpb eststo}, {helpb estadd}}
|
4 |
+
{right: {browse "http://repec.org/bocode/e/estout"}}
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{p 4 4 2}{hi:estpost} {hline 2} Post results from various commands in {cmd:e()}
|
10 |
+
|
11 |
+
|
12 |
+
{title:Syntax}
|
13 |
+
|
14 |
+
{p 8 15 2}
|
15 |
+
{cmd:estpost} {it:{help estpost##commands:command}} [...]
|
16 |
+
|
17 |
+
{marker commands}
|
18 |
+
{it:command}{col 26}description
|
19 |
+
{hline 66}
|
20 |
+
{helpb estpost##summarize:{ul:su}mmarize}{col 26}{...}
|
21 |
+
post summary statistics
|
22 |
+
{helpb estpost##tabstat:tabstat}{col 26}{...}
|
23 |
+
post summary statistics
|
24 |
+
{helpb estpost##ttest:ttest}{col 26}{...}
|
25 |
+
post two-group mean-comparison tests
|
26 |
+
{helpb estpost##prtest:prtest}{col 26}{...}
|
27 |
+
post two-group tests of proportions
|
28 |
+
{helpb estpost##tabulate:{ul:ta}bulate}{col 26}{...}
|
29 |
+
post one-way or two-way frequency table
|
30 |
+
{helpb estpost##svy_tabulate:svy: {ul:ta}bulate}{col 26}{...}
|
31 |
+
post frequency table for survey data
|
32 |
+
{helpb estpost##correlate:{ul:cor}relate}{col 26}{...}
|
33 |
+
post correlations
|
34 |
+
{helpb estpost##ci:ci}{col 26}{...}
|
35 |
+
post confidence intervals for means,
|
36 |
+
{col 26}{...}
|
37 |
+
proportions, or counts
|
38 |
+
{helpb estpost##stci:stci}{col 26}{...}
|
39 |
+
post confidence intervals for means
|
40 |
+
{col 26}{...}
|
41 |
+
and percentiles of survival time
|
42 |
+
{helpb estpost##margins:margins}{col 26}{...}
|
43 |
+
post results from {cmd:margins} (Stata 11 or newer)
|
44 |
+
{hline 66}
|
45 |
+
|
46 |
+
|
47 |
+
{title:Description}
|
48 |
+
|
49 |
+
{p 4 4 2}
|
50 |
+
{cmd:estpost} posts results from various Stata commands in {cmd:e()}
|
51 |
+
so that they can be tabulated using {helpb esttab} or {helpb estout}. Type
|
52 |
+
{helpb ereturn:ereturn list} after {cmd:estpost} to list the elements saved
|
53 |
+
in {cmd:e()}.
|
54 |
+
|
55 |
+
|
56 |
+
{title:Commands}
|
57 |
+
{marker summarize}
|
58 |
+
{dlgtab:summarize}
|
59 |
+
|
60 |
+
{p 4 15 2}
|
61 |
+
{cmd:estpost} {cmdab:su:mmarize}
|
62 |
+
[{it:{help varlist}}] [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
63 |
+
[{cmd:,}
|
64 |
+
{cmdab:d:etail}
|
65 |
+
{cmdab:mean:only}
|
66 |
+
{cmdab:list:wise}
|
67 |
+
{cmdab:case:wise}
|
68 |
+
{cmdab:q:uietly}
|
69 |
+
{cmdab:es:ample}
|
70 |
+
]
|
71 |
+
|
72 |
+
{p 4 4 2}
|
73 |
+
posts summary statistics computed by {helpb summarize}. If no
|
74 |
+
{it:varlist} is specified, summary statistics are calculated for all
|
75 |
+
variables in the dataset.
|
76 |
+
|
77 |
+
{p 4 4 2}
|
78 |
+
{cmd:aweight}s, {cmd:fweight}s, and {cmd:iweight}s are allowed
|
79 |
+
(however, {cmd:iweight}s may not be used with the {cmd:detail} option);
|
80 |
+
see {help weight}.
|
81 |
+
|
82 |
+
{p 4 4 2}
|
83 |
+
Options are:
|
84 |
+
|
85 |
+
{p 8 12 2}
|
86 |
+
{cmd:detail} and {cmd:meanonly} as described in help {helpb summarize}.
|
87 |
+
|
88 |
+
{p 8 12 2}
|
89 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
90 |
+
meaning that an observation is omitted from the estimation
|
91 |
+
sample if any of the variables in {it:varlist} is missing for that
|
92 |
+
observation. The default is to determine the used observations for
|
93 |
+
each variable separately without regard to whether other variables
|
94 |
+
are missing. {cmd:casewise} is a synonym for {cmd:listwise}.
|
95 |
+
|
96 |
+
{p 8 12 2}
|
97 |
+
{cmd:quietly} to suppress the output.
|
98 |
+
|
99 |
+
{p 8 12 2}
|
100 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
101 |
+
|
102 |
+
{p 4 4 2}The following results vectors are saved in {cmd:e()}:
|
103 |
+
|
104 |
+
{lalign 13:{cmd:e(count)}}number of observations
|
105 |
+
{lalign 13:{cmd:e(mean)}}mean
|
106 |
+
{lalign 13:{cmd:e(min)}}minimum
|
107 |
+
{lalign 13:{cmd:e(max)}}maximum
|
108 |
+
{lalign 13:{cmd:e(sum)}}sum of variable
|
109 |
+
{lalign 13:{cmd:e(sum_w)}}sum of the weights
|
110 |
+
{lalign 13:{cmd:e(Var)}}variance (unless {cmd:meanonly})
|
111 |
+
{lalign 13:{cmd:e(sd)}}standard deviation (unless {cmd:meanonly})
|
112 |
+
{lalign 13:{cmd:e(p1)}}1st percentile ({cmd:detail} only)
|
113 |
+
{lalign 13:{cmd:e(p5)}}5th percentile ({cmd:detail} only)
|
114 |
+
{lalign 13:{cmd:e(p10)}}10th percentile ({cmd:detail} only)
|
115 |
+
{lalign 13:{cmd:e(p25)}}25th percentile ({cmd:detail} only)
|
116 |
+
{lalign 13:{cmd:e(p50)}}50th percentile ({cmd:detail} only)
|
117 |
+
{lalign 13:{cmd:e(p75)}}75th percentile ({cmd:detail} only)
|
118 |
+
{lalign 13:{cmd:e(p90)}}90th percentile ({cmd:detail} only)
|
119 |
+
{lalign 13:{cmd:e(p95)}}95th percentile ({cmd:detail} only)
|
120 |
+
{lalign 13:{cmd:e(p99)}}99th percentile ({cmd:detail} only)
|
121 |
+
{lalign 13:{cmd:e(skewness)}}skewness ({cmd:detail} only)
|
122 |
+
{lalign 13:{cmd:e(kurtosis)}}kurtosis ({cmd:detail} only)
|
123 |
+
|
124 |
+
{p 4 4 2}
|
125 |
+
Example:
|
126 |
+
|
127 |
+
{* begin example summarize }{...}
|
128 |
+
{com}. sysuse auto, clear
|
129 |
+
{txt}(1978 Automobile Data)
|
130 |
+
|
131 |
+
{com}. estpost summarize price mpg rep78 foreign
|
132 |
+
|
133 |
+
{txt}{ralign 12:} {c |} {ralign 9:e(count)} {ralign 9:e(sum_w)} {ralign 9:e(mean)} {ralign 9:e(Var)} {ralign 9:e(sd)}
|
134 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
135 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 6165.257}}} {ralign 9:{res:{sf: 8699526}}} {ralign 9:{res:{sf: 2949.496}}}
|
136 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 21.2973}}} {ralign 9:{res:{sf: 33.47205}}} {ralign 9:{res:{sf: 5.785503}}}
|
137 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: 3.405797}}} {ralign 9:{res:{sf: .9799659}}} {ralign 9:{res:{sf: .9899323}}}
|
138 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: .2972973}}} {ralign 9:{res:{sf: .2117734}}} {ralign 9:{res:{sf: .4601885}}}
|
139 |
+
|
140 |
+
{ralign 12:} {c |} {ralign 9:e(min)} {ralign 9:e(max)} {ralign 9:e(sum)}
|
141 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}
|
142 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 3291}}} {ralign 9:{res:{sf: 15906}}} {ralign 9:{res:{sf: 456229}}}
|
143 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 12}}} {ralign 9:{res:{sf: 41}}} {ralign 9:{res:{sf: 1576}}}
|
144 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 5}}} {ralign 9:{res:{sf: 235}}}
|
145 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 22}}}
|
146 |
+
|
147 |
+
{com}. esttab ., cells("mean sd count") noobs
|
148 |
+
{res}
|
149 |
+
{txt}{hline 51}
|
150 |
+
{txt} (1)
|
151 |
+
{txt}
|
152 |
+
{txt} mean sd count
|
153 |
+
{txt}{hline 51}
|
154 |
+
{txt}price {res} 6165.257 2949.496 74{txt}
|
155 |
+
{txt}mpg {res} 21.2973 5.785503 74{txt}
|
156 |
+
{txt}rep78 {res} 3.405797 .9899323 69{txt}
|
157 |
+
{txt}foreign {res} .2972973 .4601885 74{txt}
|
158 |
+
{txt}{hline 51}
|
159 |
+
{* end example }{txt}{...}
|
160 |
+
|
161 |
+
{marker tabstat}
|
162 |
+
{dlgtab:tabstat}
|
163 |
+
|
164 |
+
{p 4 15 2}
|
165 |
+
{cmd:estpost} {cmdab:tabstat}
|
166 |
+
{it:{help varlist}} [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
167 |
+
[{cmd:,}
|
168 |
+
{cmdab:s:tatistics:(}{it:{help tabstat##statname:statname}} [{it:...}]{cmd:)}
|
169 |
+
{cmdab:c:olumns:(}{cmdab:v:ariables}|{cmdab:s:tatistics:)}
|
170 |
+
{cmd:by(}{it:varname}{cmd:)}
|
171 |
+
{cmdab:not:otal}
|
172 |
+
{cmdab:m:issing}
|
173 |
+
{cmdab:list:wise}
|
174 |
+
{cmdab:case:wise}
|
175 |
+
{cmdab:q:uietly}
|
176 |
+
{cmdab:es:ample}
|
177 |
+
]
|
178 |
+
|
179 |
+
{p 4 4 2}
|
180 |
+
posts summary statistics computed by {helpb tabstat}. {cmd:aweight}s and
|
181 |
+
{cmd:fweight}s are allowed; see {help weight}.
|
182 |
+
|
183 |
+
{p 4 4 2}
|
184 |
+
Options are:
|
185 |
+
|
186 |
+
{p 8 12 2}
|
187 |
+
{cmd:statistics()}, {cmd:columns()}, {cmd:by()}, {cmd:nototal},
|
188 |
+
and {cmd:missing} as described in help {helpb tabstat}.
|
189 |
+
|
190 |
+
{p 8 12 2}
|
191 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
192 |
+
meaning that an observation is omitted from the estimation
|
193 |
+
sample if any of the variables in {it:varlist} is missing for that
|
194 |
+
observation. The default is to determine the used observations for
|
195 |
+
each variable separately without regard to whether other variables
|
196 |
+
are missing. {cmd:casewise} is a synonym for {cmd:listwise}.
|
197 |
+
|
198 |
+
{p 8 12 2}
|
199 |
+
{cmd:quietly} to suppress the output.
|
200 |
+
|
201 |
+
{p 8 12 2}
|
202 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
203 |
+
|
204 |
+
{p 4 4 2}A vector of results is saved in {cmd:e()} for each specified
|
205 |
+
variable or statistic, depending on {cmd:columns()}.
|
206 |
+
|
207 |
+
{p 4 4 2}
|
208 |
+
Examples:
|
209 |
+
|
210 |
+
{* begin example tabstat }{...}
|
211 |
+
{com}. sysuse auto, clear
|
212 |
+
{txt}(1978 Automobile Data)
|
213 |
+
|
214 |
+
{com}. estpost tabstat price mpg rep78, listwise ///
|
215 |
+
> statistics(mean sd)
|
216 |
+
|
217 |
+
{txt}Summary statistics: mean sd
|
218 |
+
for variables: price mpg rep78
|
219 |
+
|
220 |
+
{ralign 12:} {c |} {ralign 9:e(price)} {ralign 9:e(mpg)} {ralign 9:e(rep78)}
|
221 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}
|
222 |
+
{ralign 12:mean} {c |} {ralign 9:{res:{sf: 6146.043}}} {ralign 9:{res:{sf: 21.28986}}} {ralign 9:{res:{sf: 3.405797}}}
|
223 |
+
{ralign 12:sd} {c |} {ralign 9:{res:{sf: 2912.44}}} {ralign 9:{res:{sf: 5.866408}}} {ralign 9:{res:{sf: .9899323}}}
|
224 |
+
|
225 |
+
{com}. esttab ., cells("price mpg rep78")
|
226 |
+
{res}
|
227 |
+
{txt}{hline 51}
|
228 |
+
{txt} (1)
|
229 |
+
{txt}
|
230 |
+
{txt} price mpg rep78
|
231 |
+
{txt}{hline 51}
|
232 |
+
{txt}mean {res} 6146.043 21.28986 3.405797{txt}
|
233 |
+
{txt}sd {res} 2912.44 5.866408 .9899323{txt}
|
234 |
+
{txt}{hline 51}
|
235 |
+
{txt}N {res} 69 {txt}
|
236 |
+
{txt}{hline 51}
|
237 |
+
|
238 |
+
{com}. estpost tabstat price mpg rep78, listwise ///
|
239 |
+
> statistics(mean sd) columns(statistics)
|
240 |
+
|
241 |
+
{txt}Summary statistics: mean sd
|
242 |
+
for variables: price mpg rep78
|
243 |
+
|
244 |
+
{ralign 12:} {c |} {ralign 9:e(mean)} {ralign 9:e(sd)}
|
245 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
246 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 6146.043}}} {ralign 9:{res:{sf: 2912.44}}}
|
247 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 21.28986}}} {ralign 9:{res:{sf: 5.866408}}}
|
248 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 3.405797}}} {ralign 9:{res:{sf: .9899323}}}
|
249 |
+
|
250 |
+
{com}. esttab ., cells("mean(fmt(a3)) sd")
|
251 |
+
{res}
|
252 |
+
{txt}{hline 38}
|
253 |
+
{txt} (1)
|
254 |
+
{txt}
|
255 |
+
{txt} mean sd
|
256 |
+
{txt}{hline 38}
|
257 |
+
{txt}price {res} 6146.0 2912.4{txt}
|
258 |
+
{txt}mpg {res} 21.29 5.866{txt}
|
259 |
+
{txt}rep78 {res} 3.406 0.990{txt}
|
260 |
+
{txt}{hline 38}
|
261 |
+
{txt}N {res} 69 {txt}
|
262 |
+
{txt}{hline 38}
|
263 |
+
|
264 |
+
{com}. estpost tabstat price mpg rep78, by(foreign) ///
|
265 |
+
> statistics(mean sd) columns(statistics) listwise
|
266 |
+
|
267 |
+
{txt}Summary statistics: mean sd
|
268 |
+
for variables: price mpg rep78
|
269 |
+
by categories of: foreign
|
270 |
+
|
271 |
+
{ralign 12:foreign} {c |} {ralign 9:e(mean)} {ralign 9:e(sd)}
|
272 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
273 |
+
{res:{lalign 13:Domestic}}{c |}{space 11}{space 11}
|
274 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 6179.25}}} {ralign 9:{res:{sf: 3188.969}}}
|
275 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 19.54167}}} {ralign 9:{res:{sf: 4.753312}}}
|
276 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 3.020833}}} {ralign 9:{res:{sf: .837666}}}
|
277 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
278 |
+
{res:{lalign 13:Foreign}}{c |}{space 11}{space 11}
|
279 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 6070.143}}} {ralign 9:{res:{sf: 2220.984}}}
|
280 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 25.28571}}} {ralign 9:{res:{sf: 6.309856}}}
|
281 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 4.285714}}} {ralign 9:{res:{sf: .7171372}}}
|
282 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
283 |
+
{res:{lalign 13:Total}}{c |}{space 11}{space 11}
|
284 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 6146.043}}} {ralign 9:{res:{sf: 2912.44}}}
|
285 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 21.28986}}} {ralign 9:{res:{sf: 5.866408}}}
|
286 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 3.405797}}} {ralign 9:{res:{sf: .9899323}}}
|
287 |
+
|
288 |
+
{com}. esttab ., main(mean) aux(sd) nostar unstack ///
|
289 |
+
> noobs nonote label
|
290 |
+
{res}
|
291 |
+
{txt}{hline 59}
|
292 |
+
{txt} (1)
|
293 |
+
{txt}
|
294 |
+
{txt} Domestic Foreign Total
|
295 |
+
{txt}{hline 59}
|
296 |
+
{txt}Price {res} 6179.3 6070.1 6146.0{txt}
|
297 |
+
{res} {ralign 12:{txt:(}3189.0{txt:)}} {ralign 12:{txt:(}2221.0{txt:)}} {ralign 12:{txt:(}2912.4{txt:)}}{txt}
|
298 |
+
|
299 |
+
{txt}Mileage (mpg) {res} 19.54 25.29 21.29{txt}
|
300 |
+
{res} {ralign 12:{txt:(}4.753{txt:)}} {ralign 12:{txt:(}6.310{txt:)}} {ralign 12:{txt:(}5.866{txt:)}}{txt}
|
301 |
+
|
302 |
+
{txt}Repair Record 1978 {res} 3.021 4.286 3.406{txt}
|
303 |
+
{res} {ralign 12:{txt:(}0.838{txt:)}} {ralign 12:{txt:(}0.717{txt:)}} {ralign 12:{txt:(}0.990{txt:)}}{txt}
|
304 |
+
{txt}{hline 59}
|
305 |
+
{* end example }{txt}{...}
|
306 |
+
|
307 |
+
{marker ttest}
|
308 |
+
{dlgtab:ttest}
|
309 |
+
|
310 |
+
{p 4 15 2}
|
311 |
+
{cmd:estpost} {cmdab:ttest}
|
312 |
+
{it:{help varlist}} [{it:{help if}}] [{it:{help in}}]{cmd:,}
|
313 |
+
{cmd:by(}{it:groupvar}{cmd:)}
|
314 |
+
[
|
315 |
+
{cmdab:une:qual} {cmdab:w:elch}
|
316 |
+
{cmdab:list:wise}
|
317 |
+
{cmdab:case:wise}
|
318 |
+
{cmdab:q:uietly}
|
319 |
+
{cmdab:es:ample}
|
320 |
+
]
|
321 |
+
|
322 |
+
{p 4 4 2}
|
323 |
+
posts two-group mean-comparison tests computed by {helpb ttest}.
|
324 |
+
|
325 |
+
{p 4 4 2}
|
326 |
+
Options are:
|
327 |
+
|
328 |
+
{p 8 12 2}
|
329 |
+
{cmd:by()}, {cmd:unequal}, and {cmd:welch} as described in
|
330 |
+
help {helpb ttest}.
|
331 |
+
|
332 |
+
{p 8 12 2}
|
333 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
334 |
+
meaning that an observation is omitted from the estimation
|
335 |
+
sample if any of the variables in {it:varlist} is missing for that
|
336 |
+
observation. The default is to determine the used observations for
|
337 |
+
each variable separately without regard to whether other variables
|
338 |
+
are missing. {cmd:casewise} is a synonym for {cmd:listwise}.
|
339 |
+
|
340 |
+
{p 8 12 2}
|
341 |
+
{cmd:quietly} to suppress the output.
|
342 |
+
|
343 |
+
{p 8 12 2}
|
344 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
345 |
+
|
346 |
+
{p 4 4 2}The following results vectors are saved in {cmd:e()}:
|
347 |
+
|
348 |
+
{lalign 13:{cmd:e(b)}}mean difference
|
349 |
+
{lalign 13:{cmd:e(count)}}number of observations
|
350 |
+
{lalign 13:{cmd:e(se)}}standard error of difference
|
351 |
+
{lalign 13:{cmd:e(t)}}t statistic
|
352 |
+
{lalign 13:{cmd:e(df_t)}}degrees of freedom
|
353 |
+
{lalign 13:{cmd:e(p_l)}}lower one-sided p-value
|
354 |
+
{lalign 13:{cmd:e(p)}}two-sided p-value
|
355 |
+
{lalign 13:{cmd:e(p_u)}}upper one-sided p-value
|
356 |
+
{lalign 13:{cmd:e(N_1)}}number of observations in group 1
|
357 |
+
{lalign 13:{cmd:e(mu_1)}}mean in group 1
|
358 |
+
{lalign 13:{cmd:e(N_2)}}number of observations in group 2
|
359 |
+
{lalign 13:{cmd:e(mu_2)}}mean in group 2
|
360 |
+
|
361 |
+
{p 4 4 2}
|
362 |
+
Example:
|
363 |
+
|
364 |
+
{* begin example ttest }{...}
|
365 |
+
{com}. sysuse auto, clear
|
366 |
+
{txt}(1978 Automobile Data)
|
367 |
+
|
368 |
+
{com}. estpost ttest price mpg headroom trunk, by(foreign)
|
369 |
+
|
370 |
+
{txt}{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(count)} {ralign 9:e(se)} {ralign 9:e(t)} {ralign 9:e(df_t)}
|
371 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
372 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf:-312.2587}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 754.4488}}} {ralign 9:{res:{sf:-.4138899}}} {ralign 9:{res:{sf: 72}}}
|
373 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf:-4.945804}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 1.362162}}} {ralign 9:{res:{sf:-3.630848}}} {ralign 9:{res:{sf: 72}}}
|
374 |
+
{ralign 12:headroom} {c |} {ralign 9:{res:{sf: .5402098}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: .2070884}}} {ralign 9:{res:{sf: 2.608596}}} {ralign 9:{res:{sf: 72}}}
|
375 |
+
{ralign 12:trunk} {c |} {ralign 9:{res:{sf: 3.340909}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 1.022208}}} {ralign 9:{res:{sf: 3.268327}}} {ralign 9:{res:{sf: 72}}}
|
376 |
+
|
377 |
+
{ralign 12:} {c |} {ralign 9:e(p_l)} {ralign 9:e(p)} {ralign 9:e(p_u)} {ralign 9:e(N_1)} {ralign 9:e(mu_1)}
|
378 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
379 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: .3400925}}} {ralign 9:{res:{sf: .6801851}}} {ralign 9:{res:{sf: .6599075}}} {ralign 9:{res:{sf: 52}}} {ralign 9:{res:{sf: 6072.423}}}
|
380 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: .0002627}}} {ralign 9:{res:{sf: .0005254}}} {ralign 9:{res:{sf: .9997373}}} {ralign 9:{res:{sf: 52}}} {ralign 9:{res:{sf: 19.82692}}}
|
381 |
+
{ralign 12:headroom} {c |} {ralign 9:{res:{sf: .9944757}}} {ralign 9:{res:{sf: .0110486}}} {ralign 9:{res:{sf: .0055243}}} {ralign 9:{res:{sf: 52}}} {ralign 9:{res:{sf: 3.153846}}}
|
382 |
+
{ralign 12:trunk} {c |} {ralign 9:{res:{sf: .99917}}} {ralign 9:{res:{sf: .00166}}} {ralign 9:{res:{sf: .00083}}} {ralign 9:{res:{sf: 52}}} {ralign 9:{res:{sf: 14.75}}}
|
383 |
+
|
384 |
+
{ralign 12:} {c |} {ralign 9:e(N_2)} {ralign 9:e(mu_2)}
|
385 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
386 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 22}}} {ralign 9:{res:{sf: 6384.682}}}
|
387 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 22}}} {ralign 9:{res:{sf: 24.77273}}}
|
388 |
+
{ralign 12:headroom} {c |} {ralign 9:{res:{sf: 22}}} {ralign 9:{res:{sf: 2.613636}}}
|
389 |
+
{ralign 12:trunk} {c |} {ralign 9:{res:{sf: 22}}} {ralign 9:{res:{sf: 11.40909}}}
|
390 |
+
|
391 |
+
{com}. esttab ., wide
|
392 |
+
{res}
|
393 |
+
{txt}{hline 41}
|
394 |
+
{txt} (1)
|
395 |
+
{txt}
|
396 |
+
{txt}{hline 41}
|
397 |
+
{txt}price {res} -312.3 {ralign 12:{txt:(}-0.41{txt:)}}{txt}
|
398 |
+
{txt}mpg {res} -4.946*** {ralign 12:{txt:(}-3.63{txt:)}}{txt}
|
399 |
+
{txt}headroom {res} 0.540* {ralign 12:{txt:(}2.61{txt:)}}{txt}
|
400 |
+
{txt}trunk {res} 3.341** {ralign 12:{txt:(}3.27{txt:)}}{txt}
|
401 |
+
{txt}{hline 41}
|
402 |
+
{txt}N {res} 74 {txt}
|
403 |
+
{txt}{hline 41}
|
404 |
+
{txt}t statistics in parentheses
|
405 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
406 |
+
{* end example }{txt}{...}
|
407 |
+
|
408 |
+
{marker prtest}
|
409 |
+
{dlgtab:prtest}
|
410 |
+
|
411 |
+
{p 4 15 2}
|
412 |
+
{cmd:estpost} {cmdab:prtest}
|
413 |
+
{it:{help varlist}} [{it:{help if}}] [{it:{help in}}]{cmd:,}
|
414 |
+
{cmd:by(}{it:groupvar}{cmd:)}
|
415 |
+
[
|
416 |
+
{cmdab:list:wise}
|
417 |
+
{cmdab:case:wise}
|
418 |
+
{cmdab:q:uietly}
|
419 |
+
{cmdab:es:ample}
|
420 |
+
]
|
421 |
+
|
422 |
+
{p 4 4 2}
|
423 |
+
posts two-group tests of proportions computed by {helpb prtest}.
|
424 |
+
|
425 |
+
{p 4 4 2}
|
426 |
+
Options are:
|
427 |
+
|
428 |
+
{p 8 12 2}
|
429 |
+
{cmd:by()} as described in
|
430 |
+
help {helpb prtest}.
|
431 |
+
|
432 |
+
{p 8 12 2}
|
433 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
434 |
+
meaning that an observation is omitted from the estimation
|
435 |
+
sample if any of the variables in {it:varlist} is missing for that
|
436 |
+
observation. The default is to determine the used observations for
|
437 |
+
each variable separately without regard to whether other variables
|
438 |
+
are missing. {cmd:casewise} is a synonym for {cmd:listwise}.
|
439 |
+
|
440 |
+
{p 8 12 2}
|
441 |
+
{cmd:quietly} to suppress the output.
|
442 |
+
|
443 |
+
{p 8 12 2}
|
444 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
445 |
+
|
446 |
+
{p 4 4 2}The following results vectors are saved in {cmd:e()}:
|
447 |
+
|
448 |
+
{lalign 13:{cmd:e(b)}}difference in proportions
|
449 |
+
{lalign 13:{cmd:e(count)}}number of observations
|
450 |
+
{lalign 13:{cmd:e(se)}}standard error of difference
|
451 |
+
{lalign 13:{cmd:e(se0)}}standard error under Ho
|
452 |
+
{lalign 13:{cmd:e(z)}}z statistic
|
453 |
+
{lalign 13:{cmd:e(p_l)}}lower one-sided p-value
|
454 |
+
{lalign 13:{cmd:e(p)}}two-sided p-value
|
455 |
+
{lalign 13:{cmd:e(p_u)}}upper one-sided p-value
|
456 |
+
{lalign 13:{cmd:e(N_1)}}number of observations in group 1
|
457 |
+
{lalign 13:{cmd:e(P_1)}}proportion in group 1
|
458 |
+
{lalign 13:{cmd:e(N_2)}}number of observations in group 2
|
459 |
+
{lalign 13:{cmd:e(P_2)}}proportion in group 2
|
460 |
+
|
461 |
+
{p 4 4 2}
|
462 |
+
Example:
|
463 |
+
|
464 |
+
{* begin example prtest }{...}
|
465 |
+
{com}. webuse cure2, clear
|
466 |
+
{txt}
|
467 |
+
{com}. estpost prtest cure, by(sex)
|
468 |
+
|
469 |
+
{txt}{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(count)} {ralign 9:e(se)} {ralign 9:e(se0)} {ralign 9:e(z)}
|
470 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
471 |
+
{ralign 12:cure} {c |} {ralign 9:{res:{sf:-.0729167}}} {ralign 9:{res:{sf: 109}}} {ralign 9:{res:{sf: .0933123}}} {ralign 9:{res:{sf: .0942404}}} {ralign 9:{res:{sf:-.7737309}}}
|
472 |
+
|
473 |
+
{ralign 12:} {c |} {ralign 9:e(p_l)} {ralign 9:e(p)} {ralign 9:e(p_u)} {ralign 9:e(N_1)} {ralign 9:e(P_1)}
|
474 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
475 |
+
{ralign 12:cure} {c |} {ralign 9:{res:{sf: .219545}}} {ralign 9:{res:{sf: .43909}}} {ralign 9:{res:{sf: .780455}}} {ralign 9:{res:{sf: 64}}} {ralign 9:{res:{sf: .59375}}}
|
476 |
+
|
477 |
+
{ralign 12:} {c |} {ralign 9:e(N_2)} {ralign 9:e(P_2)}
|
478 |
+
{hline 13}{c +}{hline 11}{hline 11}
|
479 |
+
{ralign 12:cure} {c |} {ralign 9:{res:{sf: 45}}} {ralign 9:{res:{sf: .6666667}}}
|
480 |
+
|
481 |
+
{com}. esttab ., cell("b se0 z p")
|
482 |
+
{res}
|
483 |
+
{txt}{hline 64}
|
484 |
+
{txt} (1)
|
485 |
+
{txt}
|
486 |
+
{txt} b se0 z p
|
487 |
+
{txt}{hline 64}
|
488 |
+
{txt}cure {res} -.0729167 .0942404 -.7737309 .43909{txt}
|
489 |
+
{txt}{hline 64}
|
490 |
+
{txt}N {res} 109 {txt}
|
491 |
+
{txt}{hline 64}
|
492 |
+
{* end example }{txt}{...}
|
493 |
+
|
494 |
+
{marker tabulate}
|
495 |
+
{dlgtab:tabulate}
|
496 |
+
|
497 |
+
{p 4 4 2}One-way table:
|
498 |
+
|
499 |
+
{p 8 15 2}
|
500 |
+
{cmd:estpost} {cmdab:ta:bulate}
|
501 |
+
{it:varname} [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
502 |
+
[{cmd:,}
|
503 |
+
{cmdab:m:issing}
|
504 |
+
{cmdab:nol:abel}
|
505 |
+
{cmd:sort}
|
506 |
+
{cmd:subpop(}{it:varname}{cmd:)}
|
507 |
+
{cmdab:notot:al}
|
508 |
+
{cmdab:q:uietly}
|
509 |
+
{cmdab:es:ample}
|
510 |
+
]
|
511 |
+
|
512 |
+
{p 4 4 2}Two-way table:
|
513 |
+
|
514 |
+
{p 8 15 2}
|
515 |
+
{cmd:estpost} {cmdab:ta:bulate}
|
516 |
+
{it:varname1} {it:varname2} [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
517 |
+
[{cmd:,}
|
518 |
+
{cmdab:m:issing}
|
519 |
+
{cmdab:nol:abel}
|
520 |
+
{cmdab:ch:i2}
|
521 |
+
{cmdab:e:xact}[{cmd:(}{it:#}{cmd:)}]
|
522 |
+
{cmdab:g:amma}
|
523 |
+
{cmdab:lr:chi2}
|
524 |
+
{cmdab:t:aub}
|
525 |
+
{cmdab:v}
|
526 |
+
{cmdab:notot:al}
|
527 |
+
{cmdab:q:uietly}
|
528 |
+
{cmdab:es:ample}
|
529 |
+
]
|
530 |
+
|
531 |
+
{p 4 4 2}
|
532 |
+
{cmd:estpost tabulate} posts a one-way or two-way table
|
533 |
+
computed by {helpb tabulate}. {cmd:aweight}s, {cmd:fweight}s,
|
534 |
+
and {cmd:iweight}s are allowed; see {help weight}.
|
535 |
+
|
536 |
+
{p 4 4 2}
|
537 |
+
Options are:
|
538 |
+
|
539 |
+
{p 8 12 2}
|
540 |
+
{cmd:missing},
|
541 |
+
{cmd:nolabel},
|
542 |
+
{cmd:sort},
|
543 |
+
{cmd:subpop()},
|
544 |
+
{cmd:chi2},
|
545 |
+
{cmd:exact},
|
546 |
+
{cmd:gamma},
|
547 |
+
{cmd:lrchi2},
|
548 |
+
{cmd:taub}, and
|
549 |
+
{cmd:v}
|
550 |
+
as described in help {helpb tabulate}.
|
551 |
+
|
552 |
+
{p 8 12 2}
|
553 |
+
{cmdab:nototal} to omit row and column totals.
|
554 |
+
|
555 |
+
{p 8 12 2}
|
556 |
+
{cmd:quietly} to suppress the output.
|
557 |
+
|
558 |
+
{p 8 12 2}
|
559 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
560 |
+
|
561 |
+
{p 4 4 2}The following vectors are saved in {cmd:e()}:
|
562 |
+
|
563 |
+
{lalign 13:{cmd:e(b)}}frequency counts
|
564 |
+
{lalign 13:{cmd:e(pct)}}percent
|
565 |
+
{lalign 13:{cmd:e(cumpct)}}cumulative percent (one-way only)
|
566 |
+
{lalign 13:{cmd:e(colpct)}}column percent (two-way only)
|
567 |
+
{lalign 13:{cmd:e(rowpct)}}row percent (two-way only)
|
568 |
+
|
569 |
+
{p 4 4 2}If two-way options such as, e.g., {cmd:chi2} or {cmd:exact} are
|
570 |
+
specified, the results of the tests added as scalars in {cmd:e()} using the
|
571 |
+
names documented in {helpb tabulate:{bind:[R] tabulate}}.
|
572 |
+
|
573 |
+
{p 4 4 2}The value labels of the row variable are stored as names in the
|
574 |
+
saved vectors, unless
|
575 |
+
no label exceeds 30 characters or contains unsuitable characters in which case
|
576 |
+
the labels are stored in macro {cmd:e(labels)}. Type
|
577 |
+
{cmd:varlabels(`e(labels)')} in {helpb esttab} or {helpb estout} to
|
578 |
+
use the labels stored {cmd:e(labels)}. The value labels of the column variable
|
579 |
+
are stored as equation names or, alternatively,
|
580 |
+
in macro {cmd:e(eqlabels)}. Type {cmd:eqlabels(`e(eqlabels)')} in
|
581 |
+
{helpb esttab} or {helpb estout} to use the labels stored in {cmd:e(eqlabels)}.
|
582 |
+
|
583 |
+
{p 4 4 2}Examples:
|
584 |
+
|
585 |
+
{* begin example tabulate }{...}
|
586 |
+
{com}. sysuse auto, clear
|
587 |
+
{txt}(1978 Automobile Data)
|
588 |
+
|
589 |
+
{com}. estpost tabulate foreign
|
590 |
+
|
591 |
+
{txt}{ralign 12:foreign} {c |} {ralign 9:e(b)} {ralign 9:e(pct)} {ralign 9:e(cumpct)}
|
592 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}
|
593 |
+
{ralign 12:Domestic} {c |} {ralign 9:{res:{sf: 52}}} {ralign 9:{res:{sf: 70.27027}}} {ralign 9:{res:{sf: 70.27027}}}
|
594 |
+
{ralign 12:Foreign} {c |} {ralign 9:{res:{sf: 22}}} {ralign 9:{res:{sf: 29.72973}}} {ralign 9:{res:{sf: 100}}}
|
595 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}
|
596 |
+
{ralign 12:Total} {c |} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: 100}}} {ralign 9:{res:{sf:{space 9}}}}
|
597 |
+
|
598 |
+
{com}. esttab ., cells("b pct(fmt(2)) cumpct(fmt(2))") noobs
|
599 |
+
{res}
|
600 |
+
{txt}{hline 51}
|
601 |
+
{txt} (1)
|
602 |
+
{txt} foreign
|
603 |
+
{txt} b pct cumpct
|
604 |
+
{txt}{hline 51}
|
605 |
+
{txt}Domestic {res} 52 70.27 70.27{txt}
|
606 |
+
{txt}Foreign {res} 22 29.73 100.00{txt}
|
607 |
+
{txt}Total {res} 74 100.00 {txt}
|
608 |
+
{txt}{hline 51}
|
609 |
+
|
610 |
+
{com}. estpost tabulate rep78 foreign
|
611 |
+
|
612 |
+
{res}foreign {txt} {c |}{space 44}
|
613 |
+
{ralign 12:rep78} {c |} {ralign 9:e(b)} {ralign 9:e(pct)} {ralign 9:e(colpct)} {ralign 9:e(rowpct)}
|
614 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
615 |
+
{res:{lalign 13:Domestic}}{c |}{space 11}{space 11}{space 11}{space 11}
|
616 |
+
{ralign 12:1} {c |} {ralign 9:{res:{sf: 2}}} {ralign 9:{res:{sf: 2.898551}}} {ralign 9:{res:{sf: 4.166667}}} {ralign 9:{res:{sf: 100}}}
|
617 |
+
{ralign 12:2} {c |} {ralign 9:{res:{sf: 8}}} {ralign 9:{res:{sf: 11.5942}}} {ralign 9:{res:{sf: 16.66667}}} {ralign 9:{res:{sf: 100}}}
|
618 |
+
{ralign 12:3} {c |} {ralign 9:{res:{sf: 27}}} {ralign 9:{res:{sf: 39.13043}}} {ralign 9:{res:{sf: 56.25}}} {ralign 9:{res:{sf: 90}}}
|
619 |
+
{ralign 12:4} {c |} {ralign 9:{res:{sf: 9}}} {ralign 9:{res:{sf: 13.04348}}} {ralign 9:{res:{sf: 18.75}}} {ralign 9:{res:{sf: 50}}}
|
620 |
+
{ralign 12:5} {c |} {ralign 9:{res:{sf: 2}}} {ralign 9:{res:{sf: 2.898551}}} {ralign 9:{res:{sf: 4.166667}}} {ralign 9:{res:{sf: 18.18182}}}
|
621 |
+
{ralign 12:Total} {c |} {ralign 9:{res:{sf: 48}}} {ralign 9:{res:{sf: 69.56522}}} {ralign 9:{res:{sf: 100}}} {ralign 9:{res:{sf: 69.56522}}}
|
622 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
623 |
+
{res:{lalign 13:Foreign}}{c |}{space 11}{space 11}{space 11}{space 11}
|
624 |
+
{ralign 12:1} {c |} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}}
|
625 |
+
{ralign 12:2} {c |} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}} {ralign 9:{res:{sf: 0}}}
|
626 |
+
{ralign 12:3} {c |} {ralign 9:{res:{sf: 3}}} {ralign 9:{res:{sf: 4.347826}}} {ralign 9:{res:{sf: 14.28571}}} {ralign 9:{res:{sf: 10}}}
|
627 |
+
{ralign 12:4} {c |} {ralign 9:{res:{sf: 9}}} {ralign 9:{res:{sf: 13.04348}}} {ralign 9:{res:{sf: 42.85714}}} {ralign 9:{res:{sf: 50}}}
|
628 |
+
{ralign 12:5} {c |} {ralign 9:{res:{sf: 9}}} {ralign 9:{res:{sf: 13.04348}}} {ralign 9:{res:{sf: 42.85714}}} {ralign 9:{res:{sf: 81.81818}}}
|
629 |
+
{ralign 12:Total} {c |} {ralign 9:{res:{sf: 21}}} {ralign 9:{res:{sf: 30.43478}}} {ralign 9:{res:{sf: 100}}} {ralign 9:{res:{sf: 30.43478}}}
|
630 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
631 |
+
{res:{lalign 13:Total}}{c |}{space 11}{space 11}{space 11}{space 11}
|
632 |
+
{ralign 12:1} {c |} {ralign 9:{res:{sf: 2}}} {ralign 9:{res:{sf: 2.898551}}} {ralign 9:{res:{sf: 2.898551}}} {ralign 9:{res:{sf: 100}}}
|
633 |
+
{ralign 12:2} {c |} {ralign 9:{res:{sf: 8}}} {ralign 9:{res:{sf: 11.5942}}} {ralign 9:{res:{sf: 11.5942}}} {ralign 9:{res:{sf: 100}}}
|
634 |
+
{ralign 12:3} {c |} {ralign 9:{res:{sf: 30}}} {ralign 9:{res:{sf: 43.47826}}} {ralign 9:{res:{sf: 43.47826}}} {ralign 9:{res:{sf: 100}}}
|
635 |
+
{ralign 12:4} {c |} {ralign 9:{res:{sf: 18}}} {ralign 9:{res:{sf: 26.08696}}} {ralign 9:{res:{sf: 26.08696}}} {ralign 9:{res:{sf: 100}}}
|
636 |
+
{ralign 12:5} {c |} {ralign 9:{res:{sf: 11}}} {ralign 9:{res:{sf: 15.94203}}} {ralign 9:{res:{sf: 15.94203}}} {ralign 9:{res:{sf: 100}}}
|
637 |
+
{ralign 12:Total} {c |} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: 100}}} {ralign 9:{res:{sf: 100}}} {ralign 9:{res:{sf: 100}}}
|
638 |
+
|
639 |
+
{com}. esttab ., cell(colpct(fmt(2))) unstack noobs
|
640 |
+
{res}
|
641 |
+
{txt}{hline 51}
|
642 |
+
{txt} (1)
|
643 |
+
{txt}
|
644 |
+
{txt} Domestic Foreign Total
|
645 |
+
{txt} colpct colpct colpct
|
646 |
+
{txt}{hline 51}
|
647 |
+
{txt}1 {res} 4.17 0.00 2.90{txt}
|
648 |
+
{txt}2 {res} 16.67 0.00 11.59{txt}
|
649 |
+
{txt}3 {res} 56.25 14.29 43.48{txt}
|
650 |
+
{txt}4 {res} 18.75 42.86 26.09{txt}
|
651 |
+
{txt}5 {res} 4.17 42.86 15.94{txt}
|
652 |
+
{txt}Total {res} 100.00 100.00 100.00{txt}
|
653 |
+
{txt}{hline 51}
|
654 |
+
|
655 |
+
{com}. esttab ., cell(colpct(fmt(2)) count(fmt(g) par keep(Total))) ///
|
656 |
+
> collabels(none) unstack noobs nonumber nomtitle ///
|
657 |
+
> eqlabels(, lhs("Repair Rec.")) ///
|
658 |
+
> varlabels(, blist(Total "{c -(}hline @width{c )-}{c -(}break{c )-}"))
|
659 |
+
{res}
|
660 |
+
{txt}{hline 51}
|
661 |
+
{txt}Repair Rec. Domestic Foreign Total
|
662 |
+
{txt}{hline 51}
|
663 |
+
{txt}1 {res} 4.17 0.00 2.90{txt}
|
664 |
+
{txt}2 {res} 16.67 0.00 11.59{txt}
|
665 |
+
{txt}3 {res} 56.25 14.29 43.48{txt}
|
666 |
+
{txt}4 {res} 18.75 42.86 26.09{txt}
|
667 |
+
{txt}5 {res} 4.17 42.86 15.94{txt}
|
668 |
+
{txt}{hline 51}{break} Total {res} 100.00 100.00 100.00{txt}
|
669 |
+
{res} {txt}
|
670 |
+
{txt}{hline 51}
|
671 |
+
{* end example }{txt}{...}
|
672 |
+
|
673 |
+
{marker svy_tabulate}
|
674 |
+
{dlgtab:svy: tabulate}
|
675 |
+
|
676 |
+
{p 4 4 2}One-way table:
|
677 |
+
|
678 |
+
{p 8 15 2}
|
679 |
+
{cmd:estpost} {cmd:svy} [{it:vcetype}] [, {it:svy_options}] {cmd::} {cmdab:ta:bulate}
|
680 |
+
{it:varname} [{it:{help if}}] [{it:{help in}}]
|
681 |
+
[{cmd:,}
|
682 |
+
{cmdab:notot:al}
|
683 |
+
{cmdab:q:uietly}
|
684 |
+
{cmdab:es:ample}
|
685 |
+
{help svy_tabulate_oneway:{it:svy_tabulate_opts}}
|
686 |
+
]
|
687 |
+
|
688 |
+
{p 4 4 2}Two-way table:
|
689 |
+
|
690 |
+
{p 8 15 2}
|
691 |
+
{cmd:estpost} {cmd:svy} [{it:vcetype}] [, {it:svy_options}] {cmd::} {cmdab:ta:bulate}
|
692 |
+
{it:varname1} {it:varname2} [{it:{help if}}] [{it:{help in}}]
|
693 |
+
[{cmd:,}
|
694 |
+
{cmdab:notot:al}
|
695 |
+
{cmdab:q:uietly}
|
696 |
+
{cmdab:es:ample}
|
697 |
+
{help svy_tabulate_oneway:{it:svy_tabulate_opts}}
|
698 |
+
]
|
699 |
+
|
700 |
+
{p 4 4 2}
|
701 |
+
{cmd:estpost svy: tabulate} posts a one-way or two-way table
|
702 |
+
for complex survey data computed by {helpb svy_tabulate:svy: tabulate}. Stata 9 or newer
|
703 |
+
is required.
|
704 |
+
|
705 |
+
{p 4 4 2}
|
706 |
+
Options are as described in {helpb svy_tabulate_oneway:[SVY] svy: tabulate oneway} or
|
707 |
+
{helpb svy_tabulate_twoway:[SVY] svy: tabulate twoway}, respectively, and:
|
708 |
+
|
709 |
+
{p 8 12 2}
|
710 |
+
{cmdab:nototal} to omit row and column totals (synonym for {cmd:nomarginals}).
|
711 |
+
|
712 |
+
{p 8 12 2}
|
713 |
+
{cmd:quietly} to suppress the output.
|
714 |
+
|
715 |
+
{p 8 12 2}
|
716 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
717 |
+
|
718 |
+
{p 4 4 2}{cmd:estpost svy: tabulate} posts results in {cmd:e()} (except {cmd:e(V)})
|
719 |
+
as documented in {helpb svy_tabulate_oneway:[SVY] svy: tabulate oneway} and
|
720 |
+
{helpb svy_tabulate_twoway:[SVY] svy: tabulate twoway}, respectively,
|
721 |
+
and adds or replaces the following matrices:
|
722 |
+
|
723 |
+
{lalign 10:{cmd:e(b)}}cell, column, or row proportions or percentages,
|
724 |
+
or weighted counts, depending on options
|
725 |
+
{lalign 10:{cmd:e(se)}}standard errors of {cmd:e(b)}
|
726 |
+
{lalign 10:{cmd:e(lb)}}lower confidence bounds for {cmd:e(b)}
|
727 |
+
{lalign 10:{cmd:e(ub)}}upper confidence bounds for {cmd:e(b)}
|
728 |
+
{lalign 10:{cmd:e(deff)}}deff for variances of {cmd:e(b)}
|
729 |
+
{lalign 10:{cmd:e(deft)}}deft for variances of {cmd:e(b)}
|
730 |
+
{lalign 10:{cmd:e(cell)}}cell proportion or percentages
|
731 |
+
{lalign 10:{cmd:e(row)}}row proportion or percentages (two-way only)
|
732 |
+
{lalign 10:{cmd:e(col)}}column proportion or percentages (two-way only)
|
733 |
+
{lalign 10:{cmd:e(count)}}weighted counts
|
734 |
+
{lalign 10:{cmd:e(obs)}}number of observations
|
735 |
+
|
736 |
+
{p 4 4 2}The value labels of the row variable are stored as names in the
|
737 |
+
saved vectors, unless
|
738 |
+
no label exceeds 30 characters or contains unsuitable characters in which case
|
739 |
+
the labels are stored in macro {cmd:e(labels)}. Type
|
740 |
+
{cmd:varlabels(`e(labels)')} in {helpb esttab} or {helpb estout} to
|
741 |
+
use the labels stored {cmd:e(labels)}. The value labels of the column variable
|
742 |
+
are stored as equation names or, alternatively,
|
743 |
+
in macro {cmd:e(eqlabels)}. Type {cmd:eqlabels(`e(eqlabels)')} in
|
744 |
+
{helpb esttab} or {helpb estout} to use the labels stored in {cmd:e(eqlabels)}.
|
745 |
+
|
746 |
+
{p 4 4 2}Examples:
|
747 |
+
|
748 |
+
{* begin example svy_tabulate }{...}
|
749 |
+
{com}. webuse nhanes2b, clear
|
750 |
+
{txt}
|
751 |
+
{com}. svyset psuid [pweight=finalwgt], strata(stratid)
|
752 |
+
|
753 |
+
{txt}pweight:{col 16}{res}finalwgt
|
754 |
+
{txt}VCE:{col 16}{res}linearized
|
755 |
+
{txt}Single unit:{col 16}{res}missing
|
756 |
+
{txt}Strata 1:{col 16}{res}stratid
|
757 |
+
{txt}SU 1:{col 16}{res}psuid
|
758 |
+
{txt}FPC 1:{col 16}<zero>
|
759 |
+
{p2colreset}{...}
|
760 |
+
|
761 |
+
{com}. estpost svy: tabulate race
|
762 |
+
{txt}(running tabulate on estimation sample)
|
763 |
+
|
764 |
+
{col 1}Number of strata{col 20}= {res} 31{txt}{col 48}Number of obs{col 67}= {res} 10351
|
765 |
+
{txt}{col 1}Number of PSUs{col 20}= {res} 62{txt}{col 48}Population size{col 67}={res} 117157513
|
766 |
+
{txt}{col 48}Design df{col 67}= {res} 31
|
767 |
+
|
768 |
+
{txt}{hline 10}{c TT}{hline 12}
|
769 |
+
1=white, {c |}
|
770 |
+
2=black, {c |}
|
771 |
+
3=other {c |} proportions
|
772 |
+
{hline 10}{c +}{hline 12}
|
773 |
+
White {c |} {res}.8792
|
774 |
+
{txt}Black {c |} {res}.0955
|
775 |
+
{txt}Other {c |} {res}.0253
|
776 |
+
{txt}{c |}
|
777 |
+
Total {c |} {res}1
|
778 |
+
{txt}{hline 10}{c BT}{hline 12}
|
779 |
+
Key: {col 1}proportions = {res}cell proportions
|
780 |
+
|
781 |
+
{txt}saved vectors:
|
782 |
+
e(b) = {res}cell proportions
|
783 |
+
{txt}e(se) = {res}standard errors of cell proportions
|
784 |
+
{txt}e(lb) = {res}lower 95% confidence bounds for cell proportions
|
785 |
+
{txt}e(ub) = {res}upper 95% confidence bounds for cell proportions
|
786 |
+
{txt}e(deff) = {res}deff for variances of cell proportions
|
787 |
+
{txt}e(deft) = {res}deft for variances of cell proportions
|
788 |
+
{txt}e(cell) = {res}cell proportions
|
789 |
+
{txt}e(count) = {res}weighted counts
|
790 |
+
{txt}e(obs) = {res}number of observations
|
791 |
+
{txt}
|
792 |
+
{com}. esttab ., cell("b(f(4)) se deft")
|
793 |
+
{res}
|
794 |
+
{txt}{hline 51}
|
795 |
+
{txt} (1)
|
796 |
+
{txt}
|
797 |
+
{txt} b se deft
|
798 |
+
{txt}{hline 51}
|
799 |
+
{txt}White {res} 0.8792 0.0167 5.2090{txt}
|
800 |
+
{txt}Black {res} 0.0955 0.0127 4.4130{txt}
|
801 |
+
{txt}Other {res} 0.0253 0.0105 6.8246{txt}
|
802 |
+
{txt}Total {res} 1.0000 0.0000 {txt}
|
803 |
+
{txt}{hline 51}
|
804 |
+
{txt}N {res} 10351 {txt}
|
805 |
+
{txt}{hline 51}
|
806 |
+
|
807 |
+
{com}. estpost svy: tabulate race diabetes, row percent
|
808 |
+
{txt}(running tabulate on estimation sample)
|
809 |
+
|
810 |
+
{col 1}Number of strata{col 20}= {res} 31{txt}{col 48}Number of obs{col 67}= {res} 10349
|
811 |
+
{txt}{col 1}Number of PSUs{col 20}= {res} 62{txt}{col 48}Population size{col 67}={res} 117131111
|
812 |
+
{txt}{col 48}Design df{col 67}= {res} 31
|
813 |
+
|
814 |
+
{txt}{hline 10}{c TT}{hline 20}
|
815 |
+
1=white, {c |} diabetes, 1=yes,
|
816 |
+
2=black, {c |} 0=no
|
817 |
+
3=other {c |} 0 1 Total
|
818 |
+
{hline 10}{c +}{hline 20}
|
819 |
+
White {c |} {res}96.8 3.195 100
|
820 |
+
{txt}Black {c |} {res}94.1 5.903 100
|
821 |
+
{txt}Other {c |} {res}97.97 2.034 100
|
822 |
+
{txt}{c |}
|
823 |
+
Total {c |} {res}96.58 3.425 100
|
824 |
+
{txt}{hline 10}{c BT}{hline 20}
|
825 |
+
Key: {col 1}{res}row percentages
|
826 |
+
|
827 |
+
{txt} Pearson:
|
828 |
+
{col 5}Uncorrected{col 19}chi2({res}2{txt}){col 35}= {res} 21.3483
|
829 |
+
{txt}{col 5}Design-based{col 19}F({res}1.52{txt}, {res}47.26{txt}){col 35}= {res} 15.0056{col 51}{txt}P = {res}0.0000
|
830 |
+
|
831 |
+
{txt}saved vectors:
|
832 |
+
e(b) = {res}row percentages
|
833 |
+
{txt}e(se) = {res}standard errors of row percentages
|
834 |
+
{txt}e(lb) = {res}lower 95% confidence bounds for row percentages
|
835 |
+
{txt}e(ub) = {res}upper 95% confidence bounds for row percentages
|
836 |
+
{txt}e(deff) = {res}deff for variances of row percentages
|
837 |
+
{txt}e(deft) = {res}deft for variances of row percentages
|
838 |
+
{txt}e(cell) = {res}cell percentages
|
839 |
+
{txt}e(row) = {res}row percentages
|
840 |
+
{txt}e(col) = {res}column percentages
|
841 |
+
{txt}e(count) = {res}weighted counts
|
842 |
+
{txt}e(obs) = {res}number of observations
|
843 |
+
{txt}
|
844 |
+
{com}. esttab ., b(2) se(2) scalars(F_Pear) nostar unstack ///
|
845 |
+
> mtitle(`e(colvar)')
|
846 |
+
{res}
|
847 |
+
{txt}{hline 51}
|
848 |
+
{txt} (1)
|
849 |
+
{txt} diabetes
|
850 |
+
{txt} 0 1 Total
|
851 |
+
{txt}{hline 51}
|
852 |
+
{txt}White {res} 96.80 3.20 100.00{txt}
|
853 |
+
{res} {ralign 12:{txt:(}0.20{txt:)}} {ralign 12:{txt:(}0.20{txt:)}} {txt}
|
854 |
+
|
855 |
+
{txt}Black {res} 94.10 5.90 100.00{txt}
|
856 |
+
{res} {ralign 12:{txt:(}0.61{txt:)}} {ralign 12:{txt:(}0.61{txt:)}} {txt}
|
857 |
+
|
858 |
+
{txt}Other {res} 97.97 2.03 100.00{txt}
|
859 |
+
{res} {ralign 12:{txt:(}0.76{txt:)}} {ralign 12:{txt:(}0.76{txt:)}} {txt}
|
860 |
+
|
861 |
+
{txt}Total {res} 96.58 3.42 100.00{txt}
|
862 |
+
{res} {ralign 12:{txt:(}0.18{txt:)}} {ralign 12:{txt:(}0.18{txt:)}} {txt}
|
863 |
+
{txt}{hline 51}
|
864 |
+
{txt}N {res} 10349 {txt}
|
865 |
+
{txt}F_Pear {res} 15.01 {txt}
|
866 |
+
{txt}{hline 51}
|
867 |
+
{txt}Standard errors in parentheses
|
868 |
+
{* end example }{txt}{...}
|
869 |
+
|
870 |
+
{marker correlate}
|
871 |
+
{dlgtab:correlate}
|
872 |
+
|
873 |
+
{p 4 15 2}
|
874 |
+
{cmd:estpost} {cmdab:cor:relate}
|
875 |
+
{it:{help varlist}} [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
876 |
+
[{cmd:,}
|
877 |
+
{cmdab:m:atrix}
|
878 |
+
{cmdab:noh:alf}
|
879 |
+
{cmdab:print:(}{it:#}{cmd:)}
|
880 |
+
{cmdab:b:onferroni}
|
881 |
+
{cmdab:sid:ak}
|
882 |
+
{cmdab:list:wise}
|
883 |
+
{cmdab:case:wise}
|
884 |
+
{cmdab:q:uietly}
|
885 |
+
{cmdab:es:ample}
|
886 |
+
]
|
887 |
+
|
888 |
+
{p 4 4 2}
|
889 |
+
posts the pairwise correlations between the first variable in
|
890 |
+
{it:varlist} and the remaining variables. Alternatively, if the
|
891 |
+
{cmd:matrix} option is specified, all pairwise correlations among the
|
892 |
+
variable in {it:varlist} are posted.
|
893 |
+
|
894 |
+
{p 4 4 2}
|
895 |
+
{cmd:aweight}s, {cmd:fweight}s,
|
896 |
+
{cmd:iweight}s and {cmd:pweight}s are allowed; see {help weight}.
|
897 |
+
|
898 |
+
{p 4 4 2}
|
899 |
+
Methods and formulas are as described in
|
900 |
+
{helpb correlate:{bind:[R] correlate}}. However, if {cmd:pweight}s
|
901 |
+
are specified, the p-values of the correlations are computed
|
902 |
+
as suggested in the Stata FAQ on
|
903 |
+
{browse "http://www.stata.com/support/faqs/stat/survey.html":"Estimating correlations with survey data"}.
|
904 |
+
|
905 |
+
{p 4 4 2}
|
906 |
+
Options are:
|
907 |
+
|
908 |
+
{p 8 12 2}
|
909 |
+
{cmd:matrix} to return the (lower triangle) of the correlation
|
910 |
+
matrix of the variables in {it:varlist}. The default is to return
|
911 |
+
the pairwise correlations between the first variable in
|
912 |
+
{it:varlist} and the remaining variables.
|
913 |
+
|
914 |
+
{p 8 12 2}
|
915 |
+
{cmd:nohalf} to return the full correlation matrix rather than just
|
916 |
+
the lower triangle. {cmd:nohalf} has no effect unless {cmd:matrix}
|
917 |
+
is specified.
|
918 |
+
|
919 |
+
{p 8 12 2}
|
920 |
+
{cmd:print(}{it:#}{cmd:)} to suppress (leave blank)
|
921 |
+
correlation coefficients with a p-value larger than
|
922 |
+
{it:#}. {cmd:print()} only affects what is saved in
|
923 |
+
{cmd:e(rho)}, {cmd:e(p)}, and {cmd:e(count)}, but
|
924 |
+
not what is saved in {cmd:e(b)}.
|
925 |
+
|
926 |
+
{p 8 12 2}
|
927 |
+
{cmd:bonferroni} to apply the Bonferroni adjustment to the
|
928 |
+
p-values.
|
929 |
+
|
930 |
+
{p 8 12 2}
|
931 |
+
{cmd:sidak} to apply the Sidak adjustment to the
|
932 |
+
p-values.
|
933 |
+
|
934 |
+
{p 8 12 2}
|
935 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
936 |
+
meaning that an observation is omitted from the estimation sample
|
937 |
+
if any of the variables in {it:varlist} is missing for that
|
938 |
+
observation. The default is to handle missing values by pairwise
|
939 |
+
deletion, i.e. all available observations are used to calculate a
|
940 |
+
pairwise correlation without regard to whether variables outside
|
941 |
+
that pair are missing. {cmd:casewise} is a synonym for
|
942 |
+
{cmd:listwise}.
|
943 |
+
|
944 |
+
{p 8 12 2}
|
945 |
+
{cmd:quietly} to suppress the output.
|
946 |
+
|
947 |
+
{p 8 12 2}
|
948 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
949 |
+
|
950 |
+
{p 4 4 2}The following vectors are saved in {cmd:e()}:
|
951 |
+
|
952 |
+
{lalign 13:{cmd:e(b)}}correlation coefficients
|
953 |
+
{lalign 13:{cmd:e(rho)}}correlation coefficients
|
954 |
+
{lalign 13:{cmd:e(p)}}p-values
|
955 |
+
{lalign 13:{cmd:e(count)}}number of observations
|
956 |
+
|
957 |
+
{p 4 4 2}Examples:
|
958 |
+
|
959 |
+
{* begin example correlate }{...}
|
960 |
+
{com}. sysuse auto, clear
|
961 |
+
{txt}(1978 Automobile Data)
|
962 |
+
|
963 |
+
{com}. estpost correlate price mpg turn foreign, matrix
|
964 |
+
|
965 |
+
{txt}{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(rho)} {ralign 9:e(p)} {ralign 9:e(count)}
|
966 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
967 |
+
{res:{lalign 13:price}}{c |}{space 11}{space 11}{space 11}{space 11}
|
968 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf:{space 9}}}} {ralign 9:{res:{sf: 74}}}
|
969 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf:-.4685967}}} {ralign 9:{res:{sf:-.4685967}}} {ralign 9:{res:{sf: .0000255}}} {ralign 9:{res:{sf: 74}}}
|
970 |
+
{ralign 12:turn} {c |} {ralign 9:{res:{sf: .3096174}}} {ralign 9:{res:{sf: .3096174}}} {ralign 9:{res:{sf: .0072662}}} {ralign 9:{res:{sf: 74}}}
|
971 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: .0487195}}} {ralign 9:{res:{sf: .0487195}}} {ralign 9:{res:{sf: .6801851}}} {ralign 9:{res:{sf: 74}}}
|
972 |
+
{res:{lalign 13:mpg}}{c |}{space 11}{space 11}{space 11}{space 11}
|
973 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf:{space 9}}}} {ralign 9:{res:{sf: 74}}}
|
974 |
+
{ralign 12:turn} {c |} {ralign 9:{res:{sf:-.7191863}}} {ralign 9:{res:{sf:-.7191863}}} {ralign 9:{res:{sf: 5.30e-13}}} {ralign 9:{res:{sf: 74}}}
|
975 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: .3933974}}} {ralign 9:{res:{sf: .3933974}}} {ralign 9:{res:{sf: .0005254}}} {ralign 9:{res:{sf: 74}}}
|
976 |
+
{res:{lalign 13:turn}}{c |}{space 11}{space 11}{space 11}{space 11}
|
977 |
+
{ralign 12:turn} {c |} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf:{space 9}}}} {ralign 9:{res:{sf: 74}}}
|
978 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf:-.6310965}}} {ralign 9:{res:{sf:-.6310965}}} {ralign 9:{res:{sf: 1.66e-09}}} {ralign 9:{res:{sf: 74}}}
|
979 |
+
{res:{lalign 13:foreign}}{c |}{space 11}{space 11}{space 11}{space 11}
|
980 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf: 1}}} {ralign 9:{res:{sf:{space 9}}}} {ralign 9:{res:{sf: 74}}}
|
981 |
+
|
982 |
+
{com}. esttab ., not unstack compress noobs
|
983 |
+
{res}
|
984 |
+
{txt}{hline 62}
|
985 |
+
{txt} (1)
|
986 |
+
{txt}
|
987 |
+
{txt} price mpg turn foreign
|
988 |
+
{txt}{hline 62}
|
989 |
+
{txt}price {res} 1 {txt}
|
990 |
+
{txt}mpg {res} -0.469*** 1 {txt}
|
991 |
+
{txt}turn {res} 0.310** -0.719*** 1 {txt}
|
992 |
+
{txt}foreign {res} 0.0487 0.393*** -0.631*** 1 {txt}
|
993 |
+
{txt}{hline 62}
|
994 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
995 |
+
|
996 |
+
{com}. bysort foreign: eststo: ///
|
997 |
+
> estpost correlate price turn weight rep78, listwise
|
998 |
+
|
999 |
+
{txt}{hline 60}
|
1000 |
+
-> Domestic
|
1001 |
+
|
1002 |
+
{ralign 12:price} {c |} {ralign 9:e(b)} {ralign 9:e(rho)} {ralign 9:e(p)} {ralign 9:e(count)}
|
1003 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
1004 |
+
{ralign 12:turn} {c |} {ralign 9:{res:{sf: .4328091}}} {ralign 9:{res:{sf: .4328091}}} {ralign 9:{res:{sf: .0021229}}} {ralign 9:{res:{sf: 48}}}
|
1005 |
+
{ralign 12:weight} {c |} {ralign 9:{res:{sf: .6864719}}} {ralign 9:{res:{sf: .6864719}}} {ralign 9:{res:{sf: 7.19e-08}}} {ralign 9:{res:{sf: 48}}}
|
1006 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf:-.0193249}}} {ralign 9:{res:{sf:-.0193249}}} {ralign 9:{res:{sf: .8962741}}} {ralign 9:{res:{sf: 48}}}
|
1007 |
+
({res}est1{txt} stored)
|
1008 |
+
|
1009 |
+
{hline 60}
|
1010 |
+
-> Foreign
|
1011 |
+
|
1012 |
+
{ralign 12:price} {c |} {ralign 9:e(b)} {ralign 9:e(rho)} {ralign 9:e(p)} {ralign 9:e(count)}
|
1013 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}
|
1014 |
+
{ralign 12:turn} {c |} {ralign 9:{res:{sf: .5102425}}} {ralign 9:{res:{sf: .5102425}}} {ralign 9:{res:{sf: .0181155}}} {ralign 9:{res:{sf: 21}}}
|
1015 |
+
{ralign 12:weight} {c |} {ralign 9:{res:{sf: .8315886}}} {ralign 9:{res:{sf: .8315886}}} {ralign 9:{res:{sf: 2.99e-06}}} {ralign 9:{res:{sf: 21}}}
|
1016 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: .1797879}}} {ralign 9:{res:{sf: .1797879}}} {ralign 9:{res:{sf: .4354917}}} {ralign 9:{res:{sf: 21}}}
|
1017 |
+
({res}est2{txt} stored)
|
1018 |
+
|
1019 |
+
{com}. esttab est1 est2, not mtitles
|
1020 |
+
{res}
|
1021 |
+
{txt}{hline 44}
|
1022 |
+
{txt} (1) (2)
|
1023 |
+
{txt} Domestic Foreign
|
1024 |
+
{txt}{hline 44}
|
1025 |
+
{txt}turn {res} 0.433** 0.510* {txt}
|
1026 |
+
{txt}weight {res} 0.686*** 0.832***{txt}
|
1027 |
+
{txt}rep78 {res} -0.0193 0.180 {txt}
|
1028 |
+
{txt}{hline 44}
|
1029 |
+
{txt}N {res} 48 21 {txt}
|
1030 |
+
{txt}{hline 44}
|
1031 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
1032 |
+
{* end example }{txt}{...}
|
1033 |
+
|
1034 |
+
{marker ci}
|
1035 |
+
{dlgtab:ci}
|
1036 |
+
|
1037 |
+
{p 4 15 2}
|
1038 |
+
{cmd:estpost} {cmdab:ci}
|
1039 |
+
[{it:{help varlist}}] [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
1040 |
+
[{cmd:,}
|
1041 |
+
{cmdab:b:inomial}
|
1042 |
+
{cmdab:p:oisson} {cmdab:e:xposure:(}{it:varname}{cmd:)}
|
1043 |
+
{cmdab:ex:act} {cmdab:wa:ld} {cmdab:w:ilson} {cmdab:a:gresti} {cmdab:j:effreys}
|
1044 |
+
{cmdab:l:evel:(}{it:#}{cmd:)}
|
1045 |
+
{cmdab:list:wise}
|
1046 |
+
{cmdab:case:wise}
|
1047 |
+
{cmdab:q:uietly}
|
1048 |
+
{cmdab:es:ample}
|
1049 |
+
]
|
1050 |
+
|
1051 |
+
{p 4 4 2}
|
1052 |
+
posts standard errors and confidence intervals computed by
|
1053 |
+
{helpb ci}. {cmd:aweight}s and {cmd:fweight}s are allowed,
|
1054 |
+
but {cmd:aweight}s may not be specified with options
|
1055 |
+
{cmd:binomial} or {cmd:poisson};
|
1056 |
+
see {help weight}.
|
1057 |
+
|
1058 |
+
{p 4 4 2}
|
1059 |
+
Options are:
|
1060 |
+
|
1061 |
+
{p 8 12 2}
|
1062 |
+
{cmd:binomial}, {cmd:poisson}, {cmd:exposure()},
|
1063 |
+
{cmd:exact}, {cmd:wald}, {cmd:wilson}, {cmd:agresti},
|
1064 |
+
{cmd:jeffreys}, and {cmd:level()}
|
1065 |
+
as described in help {helpb ci}.
|
1066 |
+
|
1067 |
+
{p 8 12 2}
|
1068 |
+
{cmd:listwise} to handle missing values through listwise deletion,
|
1069 |
+
meaning that an observation is omitted from the estimation
|
1070 |
+
sample if any of the variables in {it:varlist} is missing for that
|
1071 |
+
observation. The default is to determine the used observations for
|
1072 |
+
each variable separately without regard to whether other variables
|
1073 |
+
are missing. {cmd:casewise} is a synonym for {cmd:listwise}.
|
1074 |
+
|
1075 |
+
{p 8 12 2}
|
1076 |
+
{cmd:quietly} to suppress the output.
|
1077 |
+
|
1078 |
+
{p 8 12 2}
|
1079 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
1080 |
+
|
1081 |
+
{p 4 4 2}The following results vectors are saved in {cmd:e()}:
|
1082 |
+
|
1083 |
+
{lalign 13:{cmd:e(b)}}mean
|
1084 |
+
{lalign 13:{cmd:e(count)}}number of observations
|
1085 |
+
{lalign 13:{cmd:e(se)}}estimate of standard error
|
1086 |
+
{lalign 13:{cmd:e(lb)}}lower bound of confidence interval
|
1087 |
+
{lalign 13:{cmd:e(ub)}}upper bound of confidence interval
|
1088 |
+
|
1089 |
+
{p 4 4 2}
|
1090 |
+
Examples:
|
1091 |
+
|
1092 |
+
{* begin example ci }{...}
|
1093 |
+
{com}. sysuse auto, clear
|
1094 |
+
{txt}(1978 Automobile Data)
|
1095 |
+
|
1096 |
+
{com}. estpost ci price mpg rep78, listwise
|
1097 |
+
{txt}(confidence level is 95%)
|
1098 |
+
|
1099 |
+
{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(count)} {ralign 9:e(se)} {ralign 9:e(lb)} {ralign 9:e(ub)}
|
1100 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1101 |
+
{ralign 12:price} {c |} {ralign 9:{res:{sf: 6146.043}}} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: 350.6166}}} {ralign 9:{res:{sf: 5446.399}}} {ralign 9:{res:{sf: 6845.688}}}
|
1102 |
+
{ralign 12:mpg} {c |} {ralign 9:{res:{sf: 21.28986}}} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: .7062326}}} {ralign 9:{res:{sf: 19.88059}}} {ralign 9:{res:{sf: 22.69912}}}
|
1103 |
+
{ralign 12:rep78} {c |} {ralign 9:{res:{sf: 3.405797}}} {ralign 9:{res:{sf: 69}}} {ralign 9:{res:{sf: .1191738}}} {ralign 9:{res:{sf: 3.167989}}} {ralign 9:{res:{sf: 3.643605}}}
|
1104 |
+
|
1105 |
+
{com}. esttab ., cells("b lb ub") label
|
1106 |
+
{res}
|
1107 |
+
{txt}{hline 59}
|
1108 |
+
{txt} (1)
|
1109 |
+
{txt}
|
1110 |
+
{txt} b lb ub
|
1111 |
+
{txt}{hline 59}
|
1112 |
+
{txt}Price {res} 6146.043 5446.399 6845.688{txt}
|
1113 |
+
{txt}Mileage (mpg) {res} 21.28986 19.88059 22.69912{txt}
|
1114 |
+
{txt}Repair Record 1978 {res} 3.405797 3.167989 3.643605{txt}
|
1115 |
+
{txt}{hline 59}
|
1116 |
+
{txt}Observations {res} 69 {txt}
|
1117 |
+
{txt}{hline 59}
|
1118 |
+
|
1119 |
+
{com}. eststo exact: estpost ci foreign, binomial exact
|
1120 |
+
{txt}(confidence level is 95%)
|
1121 |
+
|
1122 |
+
{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(count)} {ralign 9:e(se)} {ralign 9:e(lb)} {ralign 9:e(ub)}
|
1123 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1124 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: .2972973}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: .0531331}}} {ralign 9:{res:{sf: .196584}}} {ralign 9:{res:{sf: .4148353}}}
|
1125 |
+
|
1126 |
+
{com}. eststo agresti: estpost ci foreign, binomial agresti
|
1127 |
+
{txt}(confidence level is 95%)
|
1128 |
+
|
1129 |
+
{ralign 12:} {c |} {ralign 9:e(b)} {ralign 9:e(count)} {ralign 9:e(se)} {ralign 9:e(lb)} {ralign 9:e(ub)}
|
1130 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1131 |
+
{ralign 12:foreign} {c |} {ralign 9:{res:{sf: .2972973}}} {ralign 9:{res:{sf: 74}}} {ralign 9:{res:{sf: .0531331}}} {ralign 9:{res:{sf: .204807}}} {ralign 9:{res:{sf: .4097942}}}
|
1132 |
+
|
1133 |
+
{com}. esttab exact agresti, cells(lb ub) mtitles
|
1134 |
+
{res}
|
1135 |
+
{txt}{hline 38}
|
1136 |
+
{txt} (1) (2)
|
1137 |
+
{txt} exact agresti
|
1138 |
+
{txt} lb/ub lb/ub
|
1139 |
+
{txt}{hline 38}
|
1140 |
+
{txt}foreign {res} .196584 .204807{txt}
|
1141 |
+
{res} .4148353 .4097942{txt}
|
1142 |
+
{txt}{hline 38}
|
1143 |
+
{txt}N {res} 74 74{txt}
|
1144 |
+
{txt}{hline 38}
|
1145 |
+
{* end example }{txt}{...}
|
1146 |
+
|
1147 |
+
{marker stci}
|
1148 |
+
{dlgtab:stci}
|
1149 |
+
|
1150 |
+
{p 4 15 2}
|
1151 |
+
{cmd:estpost} {cmd:stci}
|
1152 |
+
[{it:{help if}}] [{it:{help in}}]
|
1153 |
+
[{cmd:,}
|
1154 |
+
{cmd:by(}{it:groupvar}{cmd:)}
|
1155 |
+
{cmdab:m:edian}
|
1156 |
+
{cmdab:r:mean}
|
1157 |
+
{cmdab:e:mean}
|
1158 |
+
{cmd:p(}{it:#}{cmd:)}
|
1159 |
+
{cmdab:cc:orr}
|
1160 |
+
{cmdab:l:evel:(}{it:#}{cmd:)}
|
1161 |
+
{cmdab:q:uietly}
|
1162 |
+
{cmdab:es:ample}
|
1163 |
+
]
|
1164 |
+
|
1165 |
+
{p 4 4 2}
|
1166 |
+
posts confidence intervals for means
|
1167 |
+
and percentiles of survival time computed by {helpb stci}. Stata 9 or
|
1168 |
+
newer is required.
|
1169 |
+
|
1170 |
+
{p 4 4 2}
|
1171 |
+
Options are:
|
1172 |
+
|
1173 |
+
{p 8 12 2}
|
1174 |
+
{cmd:by(}{it:groupvar}{cmd:)}
|
1175 |
+
to report separate summaries for each group defined by
|
1176 |
+
{it:groupvar}, along with an overall total.
|
1177 |
+
|
1178 |
+
{p 8 12 2}
|
1179 |
+
{cmd:median},
|
1180 |
+
{cmd:rmean},
|
1181 |
+
{cmd:emean},
|
1182 |
+
{cmd:p()},
|
1183 |
+
{cmd:ccorr}, and
|
1184 |
+
{cmd:level()}
|
1185 |
+
as described in help {helpb stci}.
|
1186 |
+
|
1187 |
+
{p 8 12 2}
|
1188 |
+
{cmd:quietly} to suppress the output.
|
1189 |
+
|
1190 |
+
{p 8 12 2}
|
1191 |
+
{cmd:esample} to mark the estimation sample in {cmd:e(sample)}.
|
1192 |
+
|
1193 |
+
{p 4 4 2}The following vectors are saved in {cmd:e()}:
|
1194 |
+
|
1195 |
+
{lalign 13:{cmd:e(count)}}number of subjects
|
1196 |
+
{lalign 13:{cmd:e(p50)}}median (if {cmd:median} specified; the default)
|
1197 |
+
{lalign 13:{cmd:e(p}{it:#}{cmd:)}}#th percentile (if {cmd:p(}{it:#}{cmd:)} specified)
|
1198 |
+
{lalign 13:{cmd:e(rmean)}}restricted mean (if {cmd:rmean} specified)
|
1199 |
+
{lalign 13:{cmd:e(emean)}}extended mean (if {cmd:emean} specified)
|
1200 |
+
{lalign 13:{cmd:e(se)}}standard error
|
1201 |
+
{lalign 13:{cmd:e(lb)}}lower bound of CI
|
1202 |
+
{lalign 13:{cmd:e(ub)}}upper bound of CI
|
1203 |
+
|
1204 |
+
{p 4 4 2}
|
1205 |
+
Examples:
|
1206 |
+
|
1207 |
+
{* begin example stci }{...}
|
1208 |
+
{com}. webuse page2, clear
|
1209 |
+
{txt}
|
1210 |
+
{com}. estpost stci
|
1211 |
+
{txt}(confidence level is 95%)
|
1212 |
+
|
1213 |
+
{ralign 12:} {c |} {ralign 9:e(count)} {ralign 9:e(p50)} {ralign 9:e(se)} {ralign 9:e(lb)} {ralign 9:e(ub)}
|
1214 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1215 |
+
{ralign 12:total} {c |} {ralign 9:{res:{sf: 40}}} {ralign 9:{res:{sf: 232}}} {ralign 9:{res:{sf: 2.562933}}} {ralign 9:{res:{sf: 213}}} {ralign 9:{res:{sf: 239}}}
|
1216 |
+
|
1217 |
+
{com}. esttab ., cell("count p50 se lb ub") noobs compress
|
1218 |
+
{res}
|
1219 |
+
{txt}{hline 60}
|
1220 |
+
{txt} (1)
|
1221 |
+
{txt}
|
1222 |
+
{txt} count p50 se lb ub
|
1223 |
+
{txt}{hline 60}
|
1224 |
+
{txt}total {res} 40 232 2.562933 213 239{txt}
|
1225 |
+
{txt}{hline 60}
|
1226 |
+
|
1227 |
+
{com}. estpost stci, by(group)
|
1228 |
+
{txt}(confidence level is 95%)
|
1229 |
+
|
1230 |
+
{ralign 12:} {c |} {ralign 9:e(count)} {ralign 9:e(p50)} {ralign 9:e(se)} {ralign 9:e(lb)} {ralign 9:e(ub)}
|
1231 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1232 |
+
{ralign 12:1} {c |} {ralign 9:{res:{sf: 19}}} {ralign 9:{res:{sf: 216}}} {ralign 9:{res:{sf: 5.171042}}} {ralign 9:{res:{sf: 190}}} {ralign 9:{res:{sf: 234}}}
|
1233 |
+
{ralign 12:2} {c |} {ralign 9:{res:{sf: 21}}} {ralign 9:{res:{sf: 233}}} {ralign 9:{res:{sf: 2.179595}}} {ralign 9:{res:{sf: 232}}} {ralign 9:{res:{sf: 280}}}
|
1234 |
+
{hline 13}{c +}{hline 11}{hline 11}{hline 11}{hline 11}{hline 11}
|
1235 |
+
{ralign 12:total} {c |} {ralign 9:{res:{sf: 40}}} {ralign 9:{res:{sf: 232}}} {ralign 9:{res:{sf: 2.562933}}} {ralign 9:{res:{sf: 213}}} {ralign 9:{res:{sf: 239}}}
|
1236 |
+
|
1237 |
+
{com}. esttab ., cell("count p50 se lb ub") noobs compress
|
1238 |
+
{res}
|
1239 |
+
{txt}{hline 60}
|
1240 |
+
{txt} (1)
|
1241 |
+
{txt}
|
1242 |
+
{txt} count p50 se lb ub
|
1243 |
+
{txt}{hline 60}
|
1244 |
+
{txt}1 {res} 19 216 5.171042 190 234{txt}
|
1245 |
+
{txt}2 {res} 21 233 2.179595 232 280{txt}
|
1246 |
+
{txt}total {res} 40 232 2.562933 213 239{txt}
|
1247 |
+
{txt}{hline 60}
|
1248 |
+
{* end example }{txt}{...}
|
1249 |
+
|
1250 |
+
{marker margins}
|
1251 |
+
{dlgtab:margins}
|
1252 |
+
|
1253 |
+
{p 4 15 2}
|
1254 |
+
{cmd:estpost} {cmd:margins}
|
1255 |
+
[{it:{help fvvarlist:marginlist}}] [{it:{help if}}] [{it:{help in}}] [{it:{help weight}}]
|
1256 |
+
[{cmd:,}
|
1257 |
+
{cmdab:q:uietly}
|
1258 |
+
{it:{help margins:margins_opions}}
|
1259 |
+
]
|
1260 |
+
|
1261 |
+
{p 4 4 2}
|
1262 |
+
posts results from the {helpb margins} command, that was introduced in
|
1263 |
+
Stata 11.
|
1264 |
+
|
1265 |
+
{p 4 4 2}
|
1266 |
+
Options are:
|
1267 |
+
|
1268 |
+
{p 8 12 2}
|
1269 |
+
{cmd:quietly} to suppress the output.
|
1270 |
+
|
1271 |
+
{p 8 12 2}
|
1272 |
+
{it:margins_opions} as described in help {helpb margins} (except {cmd:post}).
|
1273 |
+
|
1274 |
+
{p 4 4 2}{cmd:estpost margins} replaces the current {cmd:e(b)} and
|
1275 |
+
{cmd:e(V)} with {cmd:r(b)} and {cmd:r(V)} from {helpb margins} and
|
1276 |
+
also copies all other matrixes, scalars, and macros from {helpb margins} into
|
1277 |
+
{cmd:e()} (possibly replacing identically named existing entries).
|
1278 |
+
|
1279 |
+
{p 4 4 2}
|
1280 |
+
Examples:
|
1281 |
+
|
1282 |
+
{* begin example margins }{...}
|
1283 |
+
{com}. sysuse auto, clear
|
1284 |
+
{txt}(1978 Automobile Data)
|
1285 |
+
|
1286 |
+
{com}. quietly logit foreign price mpg weight
|
1287 |
+
{txt}
|
1288 |
+
{com}. estpost margins, dydx(*) quietly
|
1289 |
+
{txt}
|
1290 |
+
{com}. esttab ., cell("b se") pr2
|
1291 |
+
{res}
|
1292 |
+
{txt}{hline 38}
|
1293 |
+
{txt} (1)
|
1294 |
+
{txt} foreign
|
1295 |
+
{txt} b se
|
1296 |
+
{txt}{hline 38}
|
1297 |
+
{txt}price {res} .0000686 .0000136{txt}
|
1298 |
+
{txt}mpg {res} -.0089607 .006596{txt}
|
1299 |
+
{txt}weight {res} -.0005069 .000055{txt}
|
1300 |
+
{txt}{hline 38}
|
1301 |
+
{txt}N {res} 74 {txt}
|
1302 |
+
{txt}pseudo R-sq {res} 0.619 {txt}
|
1303 |
+
{txt}{hline 38}
|
1304 |
+
{* end example }{txt}{...}
|
1305 |
+
|
1306 |
+
|
1307 |
+
{title:Author}
|
1308 |
+
|
1309 |
+
{p 4 4 2} Ben Jann, Institute of Sociology, University of Bern, [email protected]
|
1310 |
+
|
1311 |
+
|
1312 |
+
{title:Also see}
|
1313 |
+
|
1314 |
+
Manual: {hi:[R] estimates}
|
1315 |
+
|
1316 |
+
{p 4 13 2}Online: help for
|
1317 |
+
{helpb estimates},
|
1318 |
+
{helpb estout},
|
1319 |
+
{helpb esttab},
|
1320 |
+
{helpb eststo},
|
1321 |
+
{helpb estadd}
|
1322 |
+
{p_end}
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/eststo.ado
ADDED
@@ -0,0 +1,343 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 1.1.0 05nov2008 Ben Jann
|
2 |
+
|
3 |
+
program define eststo, byable(onecall)
|
4 |
+
version 8.2
|
5 |
+
local caller : di _caller()
|
6 |
+
// --- eststo clear ---
|
7 |
+
if `"`1'"'=="clear" {
|
8 |
+
if `"`0'"'!="clear" {
|
9 |
+
di as err "invalid syntax"
|
10 |
+
exit 198
|
11 |
+
}
|
12 |
+
if "`_byvars'"!="" error 190
|
13 |
+
_eststo_clear
|
14 |
+
exit
|
15 |
+
}
|
16 |
+
// --- update globals ---
|
17 |
+
_eststo_cleanglobal
|
18 |
+
// --- eststo dir ---
|
19 |
+
if `"`1'"'=="dir" {
|
20 |
+
if `"`0'"'!="dir" {
|
21 |
+
di as err "invalid syntax"
|
22 |
+
exit 198
|
23 |
+
}
|
24 |
+
if "`_byvars'"!="" error 190
|
25 |
+
_eststo_dir
|
26 |
+
exit
|
27 |
+
}
|
28 |
+
// --- eststo drop ---
|
29 |
+
if `"`1'"'=="drop" {
|
30 |
+
if "`_byvars'"!="" error 190
|
31 |
+
_eststo_`0'
|
32 |
+
exit
|
33 |
+
}
|
34 |
+
// --- eststo store (no by) ---
|
35 |
+
if "`_byvars'"=="" {
|
36 |
+
version `caller': _eststo_store `0'
|
37 |
+
exit
|
38 |
+
}
|
39 |
+
// --- eststo store (by) ---
|
40 |
+
// - check sorting
|
41 |
+
local sortedby : sortedby
|
42 |
+
local i 0
|
43 |
+
foreach byvar of local _byvars {
|
44 |
+
local sortedbyi : word `++i' of `sortedby'
|
45 |
+
if "`byvar'"!="`sortedbyi'" error 5
|
46 |
+
}
|
47 |
+
// - parse command on if qualified
|
48 |
+
capt _on_colon_parse `0'
|
49 |
+
if _rc error 190
|
50 |
+
if `"`s(after)'"'=="" error 190
|
51 |
+
local estcom `"`s(after)'"'
|
52 |
+
local 0 `"`s(before)'"'
|
53 |
+
if substr(trim(`"`estcom'"'),1,3)=="svy" {
|
54 |
+
di as err "svy commands not allowed with by ...: eststo:"
|
55 |
+
exit 190
|
56 |
+
}
|
57 |
+
AddBygrpToIfqualifier `estcom'
|
58 |
+
// - parse syntax of _eststo_store call in order to determine
|
59 |
+
// whether title() or missing was specified (note that
|
60 |
+
// -estimates change- cannot be used to set the titles since
|
61 |
+
// it does not work with -noesample-)
|
62 |
+
TitleAndMissing `0'
|
63 |
+
// - generate byindex
|
64 |
+
tempname _byindex
|
65 |
+
qui egen long `_byindex' = group(`_byvars'), label `missing'
|
66 |
+
qui su `_byindex', meanonly
|
67 |
+
if r(N)==0 error 2000
|
68 |
+
local Nby = r(max)
|
69 |
+
// - loop over bygroups
|
70 |
+
forv i = 1/`Nby' {
|
71 |
+
local ibylab: label (`_byindex') `i'
|
72 |
+
di as txt _n "{hline}"
|
73 |
+
di as txt `"-> `ibylab'"' // could be improved
|
74 |
+
if `titleopt'==0 local ibytitle
|
75 |
+
else if `titleopt'==1 local ibytitle `" title(`ibylab')"'
|
76 |
+
else if `titleopt'==2 local ibytitle `", title(`ibylab')"'
|
77 |
+
capture noisily {
|
78 |
+
version `caller': _eststo_store `0'`ibytitle' : `estcmd'
|
79 |
+
}
|
80 |
+
if _rc {
|
81 |
+
if "`_byrc0'"=="" error _rc
|
82 |
+
}
|
83 |
+
}
|
84 |
+
end
|
85 |
+
|
86 |
+
prog TitleAndMissing
|
87 |
+
capt syntax [anything] , Title(string) [ MISsing * ]
|
88 |
+
if _rc==0 {
|
89 |
+
c_local titleopt 0
|
90 |
+
c_local missing "`missing'"
|
91 |
+
}
|
92 |
+
else {
|
93 |
+
syntax [anything] [ , MISsing * ]
|
94 |
+
if `"`missing'`options'"'!="" c_local titleopt 1
|
95 |
+
else c_local titleopt 2
|
96 |
+
c_local missing "`missing'"
|
97 |
+
}
|
98 |
+
end
|
99 |
+
|
100 |
+
program AddBygrpToIfqualifier
|
101 |
+
syntax anything(equalok) [if/] [in] [using] [fw aw pw iw] [, * ]
|
102 |
+
local estcom `"`macval(anything)' if (\`_byindex'==\`i')"'
|
103 |
+
if `"`macval(if)'"'!="" {
|
104 |
+
local estcom `"`macval(estcom)' & (`macval(if)')"'
|
105 |
+
}
|
106 |
+
if `"`macval(in)'"'!="" {
|
107 |
+
local estcom `"`macval(estcom)' `macval(in)'"'
|
108 |
+
}
|
109 |
+
if `"`macval(using)'"'!="" {
|
110 |
+
local estcom `"`macval(estcom)' `macval(using)'"'
|
111 |
+
}
|
112 |
+
if `"`macval(weight)'"'!="" {
|
113 |
+
local estcom `"`macval(estcom)' [`macval(weight)'`macval(exp)']"'
|
114 |
+
}
|
115 |
+
if `"`macval(options)'"'!="" {
|
116 |
+
local estcom `"`macval(estcom)', `macval(options)'"'
|
117 |
+
}
|
118 |
+
c_local estcmd `"`macval(estcom)'"'
|
119 |
+
end
|
120 |
+
|
121 |
+
program define _eststo_clear
|
122 |
+
local names $eststo
|
123 |
+
foreach name of local names {
|
124 |
+
capt estimates drop `name'
|
125 |
+
}
|
126 |
+
global eststo
|
127 |
+
global eststo_counter
|
128 |
+
end
|
129 |
+
|
130 |
+
program define _eststo_dir
|
131 |
+
if `"$eststo"'!="" {
|
132 |
+
estimates dir $eststo
|
133 |
+
}
|
134 |
+
end
|
135 |
+
|
136 |
+
program define _eststo_cleanglobal
|
137 |
+
local enames $eststo
|
138 |
+
if `"`enames'"'!="" {
|
139 |
+
tempname hcurrent
|
140 |
+
_return hold `hcurrent'
|
141 |
+
qui _estimates dir
|
142 |
+
local snames `r(names)'
|
143 |
+
_return restore `hcurrent'
|
144 |
+
}
|
145 |
+
local names: list enames & snames
|
146 |
+
global eststo `names'
|
147 |
+
if "`names'"=="" global eststo_counter
|
148 |
+
end
|
149 |
+
|
150 |
+
program define _eststo_drop
|
151 |
+
local droplist `0'
|
152 |
+
if `"`droplist'"'=="" {
|
153 |
+
di as error "someting required"
|
154 |
+
exit 198
|
155 |
+
}
|
156 |
+
local names $eststo
|
157 |
+
foreach item of local droplist {
|
158 |
+
capt confirm integer number `item'
|
159 |
+
if _rc {
|
160 |
+
local dropname `item'
|
161 |
+
}
|
162 |
+
else {
|
163 |
+
if `item'<1 {
|
164 |
+
di as error "`item' not allowed"
|
165 |
+
exit 198
|
166 |
+
}
|
167 |
+
local dropname est`item'
|
168 |
+
}
|
169 |
+
local found 0
|
170 |
+
foreach name in `names' {
|
171 |
+
if match("`name'",`"`dropname'"') {
|
172 |
+
local found 1
|
173 |
+
estimates drop `name'
|
174 |
+
local names: list names - name
|
175 |
+
di as txt "(" as res "`name'" as txt " dropped)"
|
176 |
+
}
|
177 |
+
}
|
178 |
+
if `found'==0 {
|
179 |
+
di as txt "(no matches found for " as res `"`dropname'"' as txt ")"
|
180 |
+
}
|
181 |
+
}
|
182 |
+
global eststo `names'
|
183 |
+
end
|
184 |
+
|
185 |
+
|
186 |
+
program define _eststo_store, eclass
|
187 |
+
local caller : di _caller()
|
188 |
+
capt _on_colon_parse `0'
|
189 |
+
if !_rc {
|
190 |
+
local command `"`s(after)'"'
|
191 |
+
local 0 `"`s(before)'"'
|
192 |
+
}
|
193 |
+
syntax [name] [, ///
|
194 |
+
Title(passthru) ///
|
195 |
+
Prefix(name) ///
|
196 |
+
Refresh Refresh2(numlist integer max=1 >0) ///
|
197 |
+
ADDscalars(string asis) ///
|
198 |
+
noEsample ///
|
199 |
+
noCopy ///
|
200 |
+
MISsing svy /// doesn't do anything
|
201 |
+
]
|
202 |
+
if `"`prefix'"'=="" local prefix "est"
|
203 |
+
|
204 |
+
// get previous eststo names and counter
|
205 |
+
local names $eststo
|
206 |
+
local counter $eststo_counter
|
207 |
+
if `"`counter'"'=="" local counter 0
|
208 |
+
|
209 |
+
// if name provided; set refresh on if name already in list
|
210 |
+
if "`namelist'"!="" {
|
211 |
+
if "`refresh2'"!="" {
|
212 |
+
di as error "refresh() not allowed"
|
213 |
+
exit 198
|
214 |
+
}
|
215 |
+
local name `namelist'
|
216 |
+
if `:list name in names' local refresh refresh
|
217 |
+
else {
|
218 |
+
if "`refresh'"!="" {
|
219 |
+
di as txt "(" as res "`name'" as txt " not found)"
|
220 |
+
}
|
221 |
+
local refresh
|
222 |
+
}
|
223 |
+
if "`refresh'"=="" local ++counter
|
224 |
+
}
|
225 |
+
// if no name provided
|
226 |
+
else {
|
227 |
+
if "`refresh2'"!="" local refresh refresh
|
228 |
+
if "`refresh'"!="" {
|
229 |
+
// refresh2 not provided => refresh last (if available)
|
230 |
+
if "`refresh2'"=="" {
|
231 |
+
if "`names'"=="" {
|
232 |
+
di as txt "(nothing to refresh)"
|
233 |
+
local refresh
|
234 |
+
}
|
235 |
+
else local name: word `:list sizeof names' of `names'
|
236 |
+
}
|
237 |
+
// refresh2 provided => check availability
|
238 |
+
else {
|
239 |
+
if `:list posof "`prefix'`refresh2'" in names' {
|
240 |
+
local name `prefix'`refresh2'
|
241 |
+
}
|
242 |
+
else {
|
243 |
+
di as txt "(" as res "`prefix'`refresh2'" as txt " not found)"
|
244 |
+
local refresh
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
if "`refresh'"=="" local ++counter
|
249 |
+
// set default name
|
250 |
+
if "`name'"=="" local name `prefix'`counter'
|
251 |
+
}
|
252 |
+
|
253 |
+
// run estimation command if provided
|
254 |
+
if `"`command'"'!="" {
|
255 |
+
version `caller': `command'
|
256 |
+
}
|
257 |
+
|
258 |
+
// add scalars to e()
|
259 |
+
if `"`addscalars'"'!="" {
|
260 |
+
capt ParseAddscalars `addscalars'
|
261 |
+
if _rc {
|
262 |
+
di as err `"addscalars() invalid"'
|
263 |
+
exit 198
|
264 |
+
}
|
265 |
+
if "`replace'"=="" {
|
266 |
+
local elist `: e(scalars)' `: e(macros)' `: e(matrices)' `: e(functions)'
|
267 |
+
}
|
268 |
+
local forbidden b V sample
|
269 |
+
while (1) {
|
270 |
+
gettoken lhs rest: rest
|
271 |
+
if `:list lhs in forbidden' {
|
272 |
+
di as err `"`lhs' not allowed in addscalars()"'
|
273 |
+
exit 198
|
274 |
+
}
|
275 |
+
if "`replace'"=="" {
|
276 |
+
if `:list lhs in elist' {
|
277 |
+
di as err `"e(`lhs') already defined"'
|
278 |
+
exit 110
|
279 |
+
}
|
280 |
+
}
|
281 |
+
gettoken rhs rest: rest, bind
|
282 |
+
capt eret scalar `lhs' = `rhs'
|
283 |
+
if _rc {
|
284 |
+
di as err `"addscalars() invalid"'
|
285 |
+
exit 198
|
286 |
+
}
|
287 |
+
capture local result = e(`lhs')
|
288 |
+
di as txt "(e(" as res `"`lhs'"' as txt ") = " ///
|
289 |
+
as res `result' as txt " added)"
|
290 |
+
if `"`rest'"'=="" continue, break
|
291 |
+
}
|
292 |
+
}
|
293 |
+
// add e(cmd) if missing
|
294 |
+
if `"`e(cmd)'"'=="" {
|
295 |
+
if `"`: e(scalars)'`: e(macros)'`: e(matrices)'`: e(functions)'"'!="" {
|
296 |
+
eret local cmd "."
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
+
// store estimates with e(sample)
|
301 |
+
estimates store `name' , `copy' `title'
|
302 |
+
|
303 |
+
// remove e(sample) if -noesample- specified
|
304 |
+
if "`esample'"!="" {
|
305 |
+
capt confirm new var _est_`name'
|
306 |
+
if _rc {
|
307 |
+
tempname hcurrent
|
308 |
+
_est hold `hcurrent', restore estsystem nullok
|
309 |
+
qui replace _est_`name' = . in 1
|
310 |
+
_est unhold `name'
|
311 |
+
capt confirm new var _est_`name'
|
312 |
+
if _rc qui drop _est_`name'
|
313 |
+
else {
|
314 |
+
di as error "somethings wrong; please contact author of -eststo- " ///
|
315 |
+
"(see e-mail in help {help eststo})"
|
316 |
+
exit 498
|
317 |
+
}
|
318 |
+
_est hold `name', estimates varname(_est_`name')
|
319 |
+
// varname() only needed so that _est hold does not return error
|
320 |
+
// if variable `name' exists
|
321 |
+
}
|
322 |
+
}
|
323 |
+
|
324 |
+
// report
|
325 |
+
if "`refresh'"=="" {
|
326 |
+
global eststo `names' `name'
|
327 |
+
global eststo_counter `counter'
|
328 |
+
if `"`namelist'"'=="" {
|
329 |
+
di as txt "(" as res "`name'" as txt " stored)"
|
330 |
+
}
|
331 |
+
}
|
332 |
+
else {
|
333 |
+
if `"`namelist'"'=="" {
|
334 |
+
di as txt "(" as res "`name'" as txt " refreshed)"
|
335 |
+
}
|
336 |
+
}
|
337 |
+
end
|
338 |
+
|
339 |
+
program ParseAddscalars
|
340 |
+
syntax anything [ , Replace ]
|
341 |
+
c_local rest `"`anything'"'
|
342 |
+
c_local replace `replace'
|
343 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/eststo.hlp
ADDED
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 13sep2013}{...}
|
3 |
+
{hi:help eststo}{right:also see: {helpb esttab}, {helpb estout}, {helpb estadd}, {helpb estpost}}
|
4 |
+
{right: {browse "http://repec.org/bocode/e/estout"}}
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{p 4 4 2}{hi:eststo} {hline 2} Store estimates
|
10 |
+
|
11 |
+
|
12 |
+
{title:Syntax}{smcl}
|
13 |
+
|
14 |
+
{p 8 15 2}
|
15 |
+
[{cmd:_}]{cmd:eststo} [{it:name}]
|
16 |
+
[{cmd:,} {it:{help eststo##options:options}} ]
|
17 |
+
[ {cmd::} {it:{help estimation_command}} ]
|
18 |
+
|
19 |
+
{p 8 15 2}
|
20 |
+
[{cmd:_}]{cmd:eststo dir}
|
21 |
+
|
22 |
+
{p 8 15 2}
|
23 |
+
[{cmd:_}]{cmd:eststo drop} {{it:#}|{it:name}} [ {{it:#}|{it:name}} ... ]
|
24 |
+
|
25 |
+
{p 8 15 2}
|
26 |
+
[{cmd:_}]{cmd:eststo clear}
|
27 |
+
|
28 |
+
{marker options}
|
29 |
+
{it:options}{col 23}description
|
30 |
+
{hline 56}
|
31 |
+
[{ul:{cmd:no}}]{cmdab:e:sample}{col 23}{...}
|
32 |
+
do not/do store {cmd:e(sample)}
|
33 |
+
{cmdab:t:itle:(}{it:string}{cmd:)}{col 23}{...}
|
34 |
+
specify a title for the stored set
|
35 |
+
{cmdab:p:refix:(}{it:prefix}{cmd:)}{col 23}{...}
|
36 |
+
specify a name prefix; default is {cmd:est}
|
37 |
+
{cmdab:add:scalars(}{it:...}{cmd:)}{col 23}{...}
|
38 |
+
add scalar statistics
|
39 |
+
{cmdab:r:efresh}[{cmd:(}{it:#}{cmd:)}]{col 23}{...}
|
40 |
+
overwrite a previously stored set
|
41 |
+
{cmdab:noc:opy}{col 23}{...}
|
42 |
+
clear {cmd:e()} after storing the set
|
43 |
+
{cmdab:mis:sing}{col 23}{...}
|
44 |
+
use missing values in the {cmd:by} groups
|
45 |
+
{hline 56}
|
46 |
+
|
47 |
+
{p 4 4 2}
|
48 |
+
{cmd:by} is allowed with {cmd:eststo} if {cmd:eststo}
|
49 |
+
is used as a prefix command, i.e. specify
|
50 |
+
|
51 |
+
{cmd:by} {it:...} {cmd::} {cmd:eststo} {it:...} {cmd::} {it:estimation_command}
|
52 |
+
|
53 |
+
{p 4 4 2}
|
54 |
+
to apply {it:estimation_command} to each {cmd:by} group and store an estimation
|
55 |
+
set for each group; see help {help by}. Note that the implementation of {cmd:by}
|
56 |
+
with {cmd:eststo} requires {it:estimation_command}
|
57 |
+
to follow {help language:standard Stata syntax} and
|
58 |
+
allow the {it:{help if}} qualifier. Do not use the
|
59 |
+
{bind:{cmd:by} {it:...}{cmd:: eststo:}} construct with
|
60 |
+
{cmd:svy} commands.
|
61 |
+
|
62 |
+
|
63 |
+
{title:Description}
|
64 |
+
|
65 |
+
{p 4 4 2}
|
66 |
+
{cmd:eststo} stores a copy of the active estimation results for later
|
67 |
+
tabulation. If {it:name} is provided, the estimation set is stored
|
68 |
+
under {it:name}. If {it:name} is not provided, the estimation set is
|
69 |
+
stored under {cmd:est}{it:#}, where {it:#} is a counter for the
|
70 |
+
number of stored estimation sets.
|
71 |
+
|
72 |
+
{p 4 4 2}
|
73 |
+
{cmd:eststo} may be used in two ways: Either after fitting a model as
|
74 |
+
in
|
75 |
+
|
76 |
+
{com}. regress y x
|
77 |
+
. eststo{txt}
|
78 |
+
|
79 |
+
{p 4 4 2}
|
80 |
+
or as a prefix command (see help {help prefix}):
|
81 |
+
|
82 |
+
{com}. eststo: regress y x{txt}
|
83 |
+
|
84 |
+
{p 4 4 2}
|
85 |
+
{cmd:_eststo} is a variant on {cmd:eststo} that, by default, does not
|
86 |
+
store the estimation sample information contained in {cmd:e(sample)}.
|
87 |
+
Essentially, {cmd:_eststo} is a shortcut to {cmd:eststo, noesample}.
|
88 |
+
|
89 |
+
{p 4 4 2}
|
90 |
+
{cmd:eststo dir} displays a list of the stored estimates.
|
91 |
+
|
92 |
+
{p 4 4 2}
|
93 |
+
{cmd:eststo drop} drops estimation sets stored by {cmd:eststo}. If {it:name} is
|
94 |
+
provided, the estimation set stored under {it:name}
|
95 |
+
is dropped (if {cmd:*} or {cmd:?} wildcards are used {it:name},
|
96 |
+
all matching sets are dropped). Alternatively, if {it:#} is provided,
|
97 |
+
the estimation set stored as {cmd:est}{it:#} is dropped.
|
98 |
+
|
99 |
+
{p 4 4 2}
|
100 |
+
{cmd:eststo clear} drops all estimation sets stored by {cmd:eststo} (and clears
|
101 |
+
{cmd:eststo}'s global macros).
|
102 |
+
|
103 |
+
{p 4 4 2}
|
104 |
+
{cmd:eststo} is an alternative to official Stata's
|
105 |
+
{helpb estimates store}. The main differences are:
|
106 |
+
|
107 |
+
{p 8 12 2}
|
108 |
+
{space 1}o{space 2}{cmd:eststo} does not require the user to specify a
|
109 |
+
name for the stored estimation set.
|
110 |
+
|
111 |
+
{p 8 12 2}
|
112 |
+
{space 1}o{space 2}{cmd:eststo} may be used as a prefix command (see
|
113 |
+
help {help prefix}).
|
114 |
+
|
115 |
+
{p 8 12 2}
|
116 |
+
{space 1}o{space 2}{cmd:eststo} provides the possibility to store
|
117 |
+
estimates without the {cmd:e(sample)} function (either specify the
|
118 |
+
{cmd:noesample} option or use the {cmd:_eststo} command). Omitting
|
119 |
+
{cmd:e(sample)} saves memory and also speeds up tabulation programs
|
120 |
+
such as {helpb estimates table}, {helpb estout} or {helpb esttab}.
|
121 |
+
{hi:Warning:} Some post-estimation commands may not work with
|
122 |
+
estimation sets that do not contain the {cmd:e(sample)}.
|
123 |
+
|
124 |
+
{p 8 12 2}
|
125 |
+
{space 1}o{space 2}{cmd:eststo} can add additional scalar statistics to
|
126 |
+
be stored with the estimation set.
|
127 |
+
|
128 |
+
|
129 |
+
{title:Options}
|
130 |
+
{marker esample}
|
131 |
+
{p 4 8 2}
|
132 |
+
{cmd:esample} causes the information in {cmd:e(sample)} to be stored
|
133 |
+
with the estimates. This is the default in {cmd:eststo}. Type
|
134 |
+
{cmd:noesample} or use the {cmd:_eststo} command to omit the
|
135 |
+
{cmd:e(sample)}. Note that some post-estimation commands may not be
|
136 |
+
working correctly with estimation sets that have been stored without
|
137 |
+
{cmd:e(sample)}.
|
138 |
+
|
139 |
+
{p 4 8 2}
|
140 |
+
{cmd:title(}{it:string}{cmd:)} specifies a title for the stored
|
141 |
+
estimation set.
|
142 |
+
{p_end}
|
143 |
+
{marker addscalars}
|
144 |
+
{p 4 8 2}
|
145 |
+
{cmd:addscalars(}{it:name exp} [{it:...}] [{cmd:,} {cmdab:r:eplace}]{cmd:)}
|
146 |
+
may be used to add additional results to the {cmd:e()}-scalars of the
|
147 |
+
estimation set before storing it. Specify the names and values of the
|
148 |
+
scalars in pairs. For example, {cmd:addscalars(one 1 two 2)} would
|
149 |
+
add {cmd:e(one)} = {cmd:1} and {cmd:e(two)} = {cmd:2}. See below for
|
150 |
+
an example. The {cmd:replace} suboption permits overwriting existing
|
151 |
+
{cmd:e()}-returns. Not allowed as names are "b", "V", or "sample".
|
152 |
+
See {helpb estadd} for a more sophisticated tool to add additional
|
153 |
+
results to {cmd:e()}-returns.
|
154 |
+
|
155 |
+
{p 4 8 2}
|
156 |
+
{cmd:prefix(}{it:prefix}{cmd:)} specifies a custom prefix for the
|
157 |
+
automatic names of the stored estimation sets. The default prefix
|
158 |
+
is {cmd:est}.
|
159 |
+
|
160 |
+
{p 4 8 2}
|
161 |
+
{cmd:refresh}[{cmd:(}{it:#}{cmd:)}] may be used to overwrite a
|
162 |
+
previously stored estimation set instead of storing the estimates
|
163 |
+
under a new name. {cmd:refresh}, specified without argument, will
|
164 |
+
overwrite the last saved set. Alternatively,
|
165 |
+
{cmd:refresh(}{it:#}{cmd:)} will overwrite the set named
|
166 |
+
{cmd:est}{it:#} if it exists. If {it:name} is provided to {cmd:eststo},
|
167 |
+
existing sets of the same name will always be overwritten whether or
|
168 |
+
not {cmd:refresh} is specified. {cmd:refresh()} with argument is not
|
169 |
+
allowed in this case.
|
170 |
+
|
171 |
+
{p 4 8 2}
|
172 |
+
{cmd:nocopy} specifies that after the estimation set has been stored,
|
173 |
+
it no longer be available as the active estimation set.
|
174 |
+
|
175 |
+
{p 4 8 2}
|
176 |
+
{cmd:missing} is for use of {cmd:eststo} with the {cmd:by} prefix command and
|
177 |
+
causes missing values to be treated like any other values in the {cmd:by}
|
178 |
+
variables. The default is to discard observations with missing values in the
|
179 |
+
{cmd:by} variables.
|
180 |
+
|
181 |
+
|
182 |
+
{title:Examples}
|
183 |
+
|
184 |
+
{p 4 4 2}
|
185 |
+
Applying {cmd:eststo} after fiting a model to store the model's results,
|
186 |
+
as in the following example:
|
187 |
+
|
188 |
+
{com}. sysuse auto
|
189 |
+
{txt}(1978 Automobile Data)
|
190 |
+
|
191 |
+
{com}. quietly regress price weight
|
192 |
+
{txt}
|
193 |
+
{com}. eststo model1
|
194 |
+
{txt}
|
195 |
+
{com}. quietly regress turn weight foreign
|
196 |
+
{txt}
|
197 |
+
{com}. eststo model2
|
198 |
+
{txt}
|
199 |
+
{com}. estout
|
200 |
+
{res}
|
201 |
+
{txt}{hline 38}
|
202 |
+
{txt} model1 model2
|
203 |
+
{txt} b b
|
204 |
+
{txt}{hline 38}
|
205 |
+
{txt}weight {res} 2.044063 .0042183{txt}
|
206 |
+
{txt}foreign {res} -1.809802{txt}
|
207 |
+
{txt}_cons {res} -6.707353 27.44963{txt}
|
208 |
+
{txt}{hline 38}
|
209 |
+
|
210 |
+
|
211 |
+
{p 4 4 2}
|
212 |
+
Applying {cmd:eststo} as a prefix commmand to fit and store a model in one step:
|
213 |
+
|
214 |
+
{com}. eststo model1: quietly regress price weight
|
215 |
+
{txt}
|
216 |
+
{com}. eststo model2: quietly regress turn weight foreign
|
217 |
+
{txt}
|
218 |
+
{com}. estout
|
219 |
+
{res}
|
220 |
+
{txt}{hline 38}
|
221 |
+
{txt} model1 model2
|
222 |
+
{txt} b b
|
223 |
+
{txt}{hline 38}
|
224 |
+
{txt}weight {res} 2.044063 .0042183{txt}
|
225 |
+
{txt}foreign {res} -1.809802{txt}
|
226 |
+
{txt}_cons {res} -6.707353 27.44963{txt}
|
227 |
+
{txt}{hline 38}
|
228 |
+
|
229 |
+
|
230 |
+
{p 4 4 2}
|
231 |
+
Using {cmd:eststo} with automatic names:
|
232 |
+
|
233 |
+
{com}. eststo clear
|
234 |
+
{txt}
|
235 |
+
{com}. eststo: quietly regress price weight
|
236 |
+
{txt}({res}est1{txt} stored)
|
237 |
+
|
238 |
+
{com}. eststo: quietly regress turn weight foreign
|
239 |
+
{txt}({res}est2{txt} stored)
|
240 |
+
|
241 |
+
{com}. estout
|
242 |
+
{res}
|
243 |
+
{txt}{hline 38}
|
244 |
+
{txt} est1 est2
|
245 |
+
{txt} b b
|
246 |
+
{txt}{hline 38}
|
247 |
+
{txt}weight {res} 2.044063 .0042183{txt}
|
248 |
+
{txt}foreign {res} -1.809802{txt}
|
249 |
+
{txt}_cons {res} -6.707353 27.44963{txt}
|
250 |
+
{txt}{hline 38}
|
251 |
+
|
252 |
+
|
253 |
+
{p 4 4 2}
|
254 |
+
Adding ancillary statistics:
|
255 |
+
|
256 |
+
{com}. eststo clear
|
257 |
+
{txt}
|
258 |
+
{com}. quietly regress price weight mpg
|
259 |
+
{txt}
|
260 |
+
{com}. test weight = mpg
|
261 |
+
|
262 |
+
{txt} ( 1) {res}weight - mpg = 0
|
263 |
+
|
264 |
+
{txt} F( 1, 71) ={res} 0.36
|
265 |
+
{txt}{col 13}Prob > F ={res} 0.5514
|
266 |
+
{txt}
|
267 |
+
{com}. eststo, add(p_diff r(p))
|
268 |
+
{txt}(e({res}p_diff{txt}) = {res}.55138216{txt} added)
|
269 |
+
({res}est1{txt} stored)
|
270 |
+
|
271 |
+
{com}. estout, stat(p_diff)
|
272 |
+
{res}
|
273 |
+
{txt}{hline 25}
|
274 |
+
{txt} est1
|
275 |
+
{txt} b
|
276 |
+
{txt}{hline 25}
|
277 |
+
{txt}weight {res} 1.746559{txt}
|
278 |
+
{txt}mpg {res} -49.51222{txt}
|
279 |
+
{txt}_cons {res} 1946.069{txt}
|
280 |
+
{txt}{hline 25}
|
281 |
+
{txt}p_diff {res} .5513822{txt}
|
282 |
+
{txt}{hline 25}
|
283 |
+
|
284 |
+
|
285 |
+
{p 4 4 2}
|
286 |
+
Using the {cmd:by} prefix to store subbroup models:
|
287 |
+
|
288 |
+
{com}. eststo clear
|
289 |
+
{txt}
|
290 |
+
{com}. quietly by foreign: eststo: quietly reg price weight mpg
|
291 |
+
{txt}
|
292 |
+
{com}. esttab, label nodepvar nonumber
|
293 |
+
{res}
|
294 |
+
{txt}{hline 52}
|
295 |
+
{txt} Domestic Foreign
|
296 |
+
{txt}{hline 52}
|
297 |
+
{txt}Weight (lbs.) {res} 4.415*** 5.156***{txt}
|
298 |
+
{res} {ralign 12:{txt:(}4.66{txt:)}} {ralign 12:{txt:(}5.85{txt:)}} {txt}
|
299 |
+
|
300 |
+
{txt}Mileage (mpg) {res} 237.7 -19.78 {txt}
|
301 |
+
{res} {ralign 12:{txt:(}1.71{txt:)}} {ralign 12:{txt:(}-0.34{txt:)}} {txt}
|
302 |
+
|
303 |
+
{txt}Constant {res} -13285.4* -5065.8 {txt}
|
304 |
+
{res} {ralign 12:{txt:(}-2.32{txt:)}} {ralign 12:{txt:(}-1.58{txt:)}} {txt}
|
305 |
+
{txt}{hline 52}
|
306 |
+
{txt}Observations {res} 52 22 {txt}
|
307 |
+
{txt}{hline 52}
|
308 |
+
{txt}t statistics in parentheses
|
309 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
310 |
+
|
311 |
+
|
312 |
+
{title:Returned results}
|
313 |
+
|
314 |
+
{p 4 4 2}
|
315 |
+
The name under which an estimation set is stored, is added to the set in
|
316 |
+
{cmd:e(_estimates_name)}.
|
317 |
+
|
318 |
+
{p 4 4 2}
|
319 |
+
In addition, {cmd:eststo} maintains two global macros. {cmd:$eststo} contains a list
|
320 |
+
of the names of the stored estimation sets. {cmd:$eststo_counter}
|
321 |
+
contains the count of stored estimation sets.
|
322 |
+
|
323 |
+
|
324 |
+
{title:Acknowledgements}
|
325 |
+
|
326 |
+
{p 4 4 2}
|
327 |
+
Bill Gould suggested to make {cmd:eststo} "byable".
|
328 |
+
|
329 |
+
|
330 |
+
{title:Author}
|
331 |
+
|
332 |
+
{p 4 4 2}
|
333 |
+
Ben Jann, Institute of Sociology, University of Bern, [email protected]
|
334 |
+
|
335 |
+
|
336 |
+
{title:Also see}
|
337 |
+
|
338 |
+
Manual: {hi:[R] estimates}
|
339 |
+
|
340 |
+
{p 4 13 2}Online: help for
|
341 |
+
{helpb estimates},
|
342 |
+
{helpb esttab},
|
343 |
+
{helpb estout},
|
344 |
+
{helpb estadd},
|
345 |
+
{helpb estpost}
|
346 |
+
{p_end}
|
347 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/esttab.ado
ADDED
@@ -0,0 +1,1209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.0.6 02jun2014 Ben Jann
|
2 |
+
*! wrapper for estout
|
3 |
+
|
4 |
+
program define esttab
|
5 |
+
version 8.2
|
6 |
+
local caller : di _caller()
|
7 |
+
|
8 |
+
// mode specific defaults
|
9 |
+
local cdate "`c(current_date)'"
|
10 |
+
local ctime "`c(current_time)'"
|
11 |
+
// - fixed
|
12 |
+
local fixed_open0 `""% `cdate' `ctime'""'
|
13 |
+
local fixed_close0 `""""'
|
14 |
+
local fixed_open `""'
|
15 |
+
local fixed_close `""'
|
16 |
+
local fixed_caption `""@title""'
|
17 |
+
local fixed_open2 `""'
|
18 |
+
local fixed_close2 `""'
|
19 |
+
local fixed_toprule `""@hline""'
|
20 |
+
local fixed_midrule `""@hline""'
|
21 |
+
local fixed_bottomrule `""@hline""'
|
22 |
+
local fixed_topgap `""""'
|
23 |
+
local fixed_midgap `""""'
|
24 |
+
local fixed_bottomgap `""""'
|
25 |
+
local fixed_eqrule `"begin(@hline "")"'
|
26 |
+
local fixed_ssl `"N R-sq "adj. R-sq" "pseudo R-sq" AIC BIC"'
|
27 |
+
local fixed_lsl `"Observations R-squared "Adjusted R-squared" "Pseudo R-squared" AIC BIC"'
|
28 |
+
local fixed_starlevels `"* 0.05 ** 0.01 *** 0.001"'
|
29 |
+
local fixed_starlevlab `""'
|
30 |
+
local fixed_begin `""'
|
31 |
+
local fixed_delimiter `"" ""'
|
32 |
+
local fixed_end `""'
|
33 |
+
local fixed_incelldel `"" ""'
|
34 |
+
local fixed_varwidth `"\`= cond("\`label'"=="", 12, 20)'"'
|
35 |
+
local fixed_modelwidth `"12"'
|
36 |
+
local fixed_abbrev `"abbrev"'
|
37 |
+
local fixed_substitute `""'
|
38 |
+
local fixed_interaction `"" # ""'
|
39 |
+
local fixed_tstatlab `"t statistics"'
|
40 |
+
local fixed_zstatlab `"z statistics"'
|
41 |
+
local fixed_pvallab `"p-values"'
|
42 |
+
local fixed_cilab `"\`level'% confidence intervals"'
|
43 |
+
// - smcl
|
44 |
+
local smcl_open0 `"{smcl} "{* % `cdate' `ctime'}{...}""'
|
45 |
+
local smcl_close0 `""""'
|
46 |
+
local smcl_open `""'
|
47 |
+
local smcl_close `""'
|
48 |
+
local smcl_caption `""@title""'
|
49 |
+
local smcl_open2 `""'
|
50 |
+
local smcl_close2 `""'
|
51 |
+
local smcl_toprule `""{hline @width}""'
|
52 |
+
local smcl_midrule `""{hline @width}""'
|
53 |
+
local smcl_bottomrule `""{hline @width}""'
|
54 |
+
local smcl_topgap `""""'
|
55 |
+
local smcl_midgap `""""'
|
56 |
+
local smcl_bottomgap `""""'
|
57 |
+
local smcl_eqrule `"begin("{hline @width}" "")"'
|
58 |
+
local smcl_ssl `"`macval(fixed_ssl)'"'
|
59 |
+
local smcl_lsl `"`macval(fixed_lsl)'"'
|
60 |
+
local smcl_starlevels `"`macval(fixed_starlevels)'"'
|
61 |
+
local smcl_starlevlab `""'
|
62 |
+
local smcl_begin `""'
|
63 |
+
local smcl_delimiter `"" ""'
|
64 |
+
local smcl_end `""'
|
65 |
+
local smcl_incelldel `"" ""'
|
66 |
+
local smcl_varwidth `"`macval(fixed_varwidth)'"'
|
67 |
+
local smcl_modelwidth `"`macval(fixed_modelwidth)'"'
|
68 |
+
local smcl_abbrev `"`macval(fixed_abbrev)'"'
|
69 |
+
local smcl_substitute `""'
|
70 |
+
local smcl_interaction `"" # ""'
|
71 |
+
local smcl_tstatlab `"`macval(fixed_tstatlab)'"'
|
72 |
+
local smcl_zstatlab `"`macval(fixed_zstatlab)'"'
|
73 |
+
local smcl_pvallab `"`macval(fixed_pvallab)'"'
|
74 |
+
local smcl_cilab `"`macval(fixed_cilab)'"'
|
75 |
+
// - tab
|
76 |
+
local tab_open0 `"`macval(fixed_open0)'"'
|
77 |
+
local tab_close0 `""""'
|
78 |
+
local tab_open `""'
|
79 |
+
local tab_close `""'
|
80 |
+
local tab_caption `""@title""'
|
81 |
+
local tab_open2 `""'
|
82 |
+
local tab_close2 `""'
|
83 |
+
local tab_topgap `""""'
|
84 |
+
local tab_midgap `""""'
|
85 |
+
local tab_bottomgap `""""'
|
86 |
+
local tab_ssl `"`macval(fixed_ssl)'"'
|
87 |
+
local tab_lsl `"`macval(fixed_lsl)'"'
|
88 |
+
local tab_starlevels `"`macval(fixed_starlevels)'"'
|
89 |
+
local tab_starlevlab `""'
|
90 |
+
local tab_begin `""'
|
91 |
+
local tab_delimiter `"_tab"'
|
92 |
+
local tab_end `""'
|
93 |
+
local tab_incelldel `"" ""'
|
94 |
+
local tab_varwidth `""'
|
95 |
+
local tab_modelwidth `""'
|
96 |
+
local tab_abbrev `""'
|
97 |
+
local tab_substitute `""'
|
98 |
+
local tab_interaction `"" # ""'
|
99 |
+
local tab_tstatlab `"`macval(fixed_tstatlab)'"'
|
100 |
+
local tab_zstatlab `"`macval(fixed_zstatlab)'"'
|
101 |
+
local tab_pvallab `"`macval(fixed_pvallab)'"'
|
102 |
+
local tab_cilab `"`macval(fixed_cilab)'"'
|
103 |
+
// - csv
|
104 |
+
local csv_open0 `"`"\`csvlhs'% `cdate' `ctime'""'"'
|
105 |
+
local csv_close0 `""""'
|
106 |
+
local csv_open `""'
|
107 |
+
local csv_close `""'
|
108 |
+
local csv_caption `"`"\`csvlhs'@title""'"'
|
109 |
+
local csv_open2 `""'
|
110 |
+
local csv_close2 `""'
|
111 |
+
local csv_topgap `""""'
|
112 |
+
local csv_midgap `""""'
|
113 |
+
local csv_bottomgap `""""'
|
114 |
+
local csv_ssl `"`macval(fixed_ssl)'"'
|
115 |
+
local csv_lsl `"`macval(fixed_lsl)'"'
|
116 |
+
local csv_starlevels `"`macval(fixed_starlevels)'"'
|
117 |
+
local csv_starlevlab `""'
|
118 |
+
local csv_begin `"`"\`csvlhs'"'"'
|
119 |
+
local csv_delimiter `"`"",\`csvlhs'"'"'
|
120 |
+
local scsv_delimiter `"`"";\`csvlhs'"'"'
|
121 |
+
local csv_end `"`"""'"'
|
122 |
+
local csv_incelldel `"" ""'
|
123 |
+
local csv_varwidth `""'
|
124 |
+
local csv_modelwidth `""'
|
125 |
+
local csv_abbrev `""'
|
126 |
+
local csv_substitute `""'
|
127 |
+
local csv_interaction `"" # ""'
|
128 |
+
local csv_tstatlab `"`macval(fixed_tstatlab)'"'
|
129 |
+
local csv_zstatlab `"`macval(fixed_zstatlab)'"'
|
130 |
+
local csv_pvallab `"`macval(fixed_pvallab)'"'
|
131 |
+
local csv_cilab `"`macval(fixed_cilab)'"'
|
132 |
+
// - rtf
|
133 |
+
local rtf_open0 `""'
|
134 |
+
local rtf_close0 `""'
|
135 |
+
local rtf_ct `"\yr`=year(d(`cdate'))'\mo`=month(d(`cdate'))'\dy`=day(d(`cdate'))'\hr`=substr("`ctime'",1,2)'\min`=substr("`ctime'",4,2)'"'
|
136 |
+
local rtf_open_l1 `"`"{\rtf1`=cond("`c(os)'"=="MacOSX", "\mac", "\ansi")'\deff0 {\fonttbl{\f0\fnil Times New Roman;}}"'"'
|
137 |
+
local rtf_open_l2 `" `"{\info {\author .}{\company .}{\title .}{\creatim`rtf_ct'}}"'"'
|
138 |
+
local rtf_open_l3 `" `"\deflang1033\plain\fs24"'"'
|
139 |
+
local rtf_open_l4 `" `"{\footer\pard\qc\plain\f0\fs24\chpgn\par}"'"'
|
140 |
+
local rtf_open `"`rtf_open_l1'`rtf_open_l2'`rtf_open_l3'`rtf_open_l4'"'
|
141 |
+
local rtf_close `""{\pard \par}" "}""'
|
142 |
+
local rtf_caption `"`"{\pard\keepn\ql @title\par}"'"'
|
143 |
+
local rtf_open2 `""{""'
|
144 |
+
local rtf_close2 `""}""'
|
145 |
+
local rtf_toprule `""'
|
146 |
+
local rtf_midrule `""'
|
147 |
+
local rtf_bottomrule `""'
|
148 |
+
local rtf_topgap `""'
|
149 |
+
local rtf_midgap `"{\trowd\trgaph108\trleft-108@rtfemptyrow\row}"'
|
150 |
+
local rtf_bottomgap `""'
|
151 |
+
local rtf_eqrule `"begin("{\trowd\trgaph108\trleft-108@rtfrowdefbrdrt\pard\intbl\ql {") replace"'
|
152 |
+
local rtf_ssl `""{\i N}" "{\i R}{\super 2}" "adj. {\i R}{\super 2}" "pseudo {\i R}{\super 2}" "{\i AIC}" "{\i BIC}""'
|
153 |
+
local rtf_lsl `"Observations "{\i R}{\super 2}" "Adjusted {\i R}{\super 2}" "Pseudo {\i R}{\super 2}" "{\i AIC}" "{\i BIC}""'
|
154 |
+
local rtf_starlevels `""{\super *}" 0.05 "{\super **}" 0.01 "{\super ***}" 0.001"'
|
155 |
+
local rtf_starlevlab `", label(" {\i p} < ")"'
|
156 |
+
local rtf_rowdef `"\`=cond("\`lines'"=="", "@rtfrowdef", "@rtfrowdefbrdr")'"'
|
157 |
+
local rtf_begin `"{\trowd\trgaph108\trleft-108\`rtf_rowdef'\pard\intbl\ql {"'
|
158 |
+
local rtf_delimiter `"}\cell \pard\intbl\q\`=cond(`"\`alignment'"'!="", `"\`alignment'"', "c")' {"'
|
159 |
+
local rtf_end `"}\cell\row}"'
|
160 |
+
local rtf_incelldel `""\line ""'
|
161 |
+
local rtf_varwidth `"\`= cond("\`label'"=="", 12, 20)'"'
|
162 |
+
local rtf_modelwidth `"12"'
|
163 |
+
local rtf_abbrev `""'
|
164 |
+
local rtf_substitute `""'
|
165 |
+
local rtf_interaction `"" # ""'
|
166 |
+
local rtf_tstatlab `"{\i t} statistics"'
|
167 |
+
local rtf_zstatlab `"{\i z} statistics"'
|
168 |
+
local rtf_pvallab `"{\i p}-values"'
|
169 |
+
local rtf_cilab `"\`level'% confidence intervals"'
|
170 |
+
// - html
|
171 |
+
local html_open0 `"<html> <head> "<title>`=cond(`"\`macval(title)'"'=="","estimates table, created `cdate' `ctime'","@title")'</title>" </head> <body> """'
|
172 |
+
local html_close0 `""" </body> </html> """'
|
173 |
+
local html_open `"`"<table border="0" width="\`=cond("\`width'"=="","*","\`width'")'">"'"'
|
174 |
+
local html_close `""</table>""'
|
175 |
+
local html_caption `""<caption>@title</caption>""'
|
176 |
+
local html_open2 `""'
|
177 |
+
local html_close2 `""'
|
178 |
+
local html_toprule `""<tr><td colspan=@span><hr></td></tr>""'
|
179 |
+
local html_midrule `""<tr><td colspan=@span><hr></td></tr>""'
|
180 |
+
local html_bottomrule `""<tr><td colspan=@span><hr></td></tr>""'
|
181 |
+
local html_topgap `""'
|
182 |
+
local html_midgap `""<tr><td colspan=@span> </td></tr>""'
|
183 |
+
local html_bottomgap `""'
|
184 |
+
local html_eqrule `"begin("<tr><td colspan=@span><hr></td></tr>" "")"'
|
185 |
+
local html_ssl `"<i>N</i> <i>R</i><sup>2</sup> "adj. <i>R</i><sup>2</sup>" "pseudo <i>R</i><sup>2</sup>" <i>AIC</i> <i>BIC</i>"'
|
186 |
+
local html_lsl `"Observations <i>R</i><sup>2</sup> "Adjusted <i>R</i><sup>2</sup>" "Pseudo <i>R</i><sup>2</sup>" <i>AIC</i> <i>BIC</i>"'
|
187 |
+
local html_starlevels `"<sup>*</sup> 0.05 <sup>**</sup> 0.01 <sup>***</sup> 0.001"'
|
188 |
+
local html_starlevlab `", label(" <i>p</i> < ")"'
|
189 |
+
local html_begin `"<tr><td>"'
|
190 |
+
local html_delimiter `"</td><td\`=cond(`"\`alignment'"'!="", `" align="\`alignment'""', "")'>"'
|
191 |
+
local html_end `"</td></tr>"'
|
192 |
+
local html_incelldel `"<br />"'
|
193 |
+
local html_varwidth `"\`= cond("\`label'"=="", 12, 20)'"'
|
194 |
+
local html_modelwidth `"12"'
|
195 |
+
local html_abbrev `""'
|
196 |
+
local html_substitute `""'
|
197 |
+
local html_interaction `"" # ""'
|
198 |
+
local html_tstatlab `"<i>t</i> statistics"'
|
199 |
+
local html_zstatlab `"<i>z</i> statistics"'
|
200 |
+
local html_pvallab `"<i>p</i>-values"'
|
201 |
+
local html_cilab `"\`level'% confidence intervals"'
|
202 |
+
// - tex
|
203 |
+
local tex_open0 `""% `cdate' `ctime'" \documentclass{article} \`texpkgs' \`=cond("\`longtable'"!="","\usepackage{longtable}","")' \begin{document} """'
|
204 |
+
local tex_close0 `""" \end{document} """'
|
205 |
+
local tex_open `"\`=cond("\`longtable'"=="", "\begin{table}[htbp]\centering", `"{"')'"'
|
206 |
+
local tex_close `"\`=cond("\`longtable'"=="", "\end{table}", "}")'"'
|
207 |
+
local tex_caption `"\caption{@title}"'
|
208 |
+
local tex_open2 `"\`=cond("\`longtable'"!="", "\begin{longtable}", "\begin{tabular" + cond("\`width'"=="", "}", "*}{\`width'}"))'"'
|
209 |
+
local tex_close2 `"\`=cond("\`longtable'"!="", "\end{longtable}", "\end{tabular" + cond("\`width'"=="", "}", "*}"))'"'
|
210 |
+
local tex_toprule `"\`="\hline\hline" + cond("\`longtable'"!="", "\endfirsthead\hline\endhead\hline\endfoot\endlastfoot", "")'"'
|
211 |
+
local tex_midrule `""\hline""'
|
212 |
+
local tex_bottomrule `""\hline\hline""'
|
213 |
+
local tex_topgap `""'
|
214 |
+
local tex_midgap `"[1em]"' // `"\\\"'
|
215 |
+
local tex_bottomgap `""'
|
216 |
+
local tex_eqrule `"begin("\hline" "")"'
|
217 |
+
local tex_ssl `"\(N\) \(R^{2}\) "adj. \(R^{2}\)" "pseudo \(R^{2}\)" \textit{AIC} \textit{BIC}"'
|
218 |
+
local tex_lsl `"Observations \(R^{2}\) "Adjusted \(R^{2}\)" "Pseudo \(R^{2}\)" \textit{AIC} \textit{BIC}"'
|
219 |
+
local tex_starlevels `"\sym{*} 0.05 \sym{**} 0.01 \sym{***} 0.001"'
|
220 |
+
local tex_starlevlab `", label(" \(p<@\)")"'
|
221 |
+
local tex_begin `""'
|
222 |
+
local tex_delimiter `"&"'
|
223 |
+
local tex_end `"\\\"'
|
224 |
+
local tex_incelldel `"" ""'
|
225 |
+
local tex_varwidth `"\`= cond("\`label'"=="", 12, 20)'"'
|
226 |
+
local tex_modelwidth `"12"'
|
227 |
+
local tex_abbrev `""'
|
228 |
+
local tex_tstatlab `"\textit{t} statistics"'
|
229 |
+
local tex_zstatlab `"\textit{z} statistics"'
|
230 |
+
local tex_pvallab `"\textit{p}-values"'
|
231 |
+
local tex_cilab `"\`level'\% confidence intervals"'
|
232 |
+
local tex_substitute `"_ \_ "\_cons " \_cons"'
|
233 |
+
local tex_interaction `"" $\times$ ""'
|
234 |
+
// - booktabs
|
235 |
+
local booktabs_open0 `""% `cdate' `ctime'" \documentclass{article} \`texpkgs' \usepackage{booktabs} \`=cond("\`longtable'"!="","\usepackage{longtable}","")' \begin{document} """'
|
236 |
+
local booktabs_close0 `"`macval(tex_close0)'"'
|
237 |
+
local booktabs_open `"`macval(tex_open)'"'
|
238 |
+
local booktabs_close `"`macval(tex_close)'"'
|
239 |
+
local booktabs_caption `"`macval(tex_caption)'"'
|
240 |
+
local booktabs_open2 `"`macval(tex_open2)'"'
|
241 |
+
local booktabs_close2 `"`macval(tex_close2)'"'
|
242 |
+
local booktabs_toprule `"\`="\toprule" + cond("\`longtable'"!="", "\endfirsthead\midrule\endhead\midrule\endfoot\endlastfoot", "")'"'
|
243 |
+
local booktabs_midrule `""\midrule""'
|
244 |
+
local booktabs_bottomrule `""\bottomrule""'
|
245 |
+
local booktabs_topgap `"`macval(tex_topgap)'"'
|
246 |
+
local booktabs_midgap `"\addlinespace"'
|
247 |
+
local booktabs_bottomgap `"`macval(tex_bottomgap)'"'
|
248 |
+
local booktabs_eqrule `"begin("\midrule" "")"'
|
249 |
+
local booktabs_ssl `"`macval(tex_ssl)'"'
|
250 |
+
local booktabs_lsl `"`macval(tex_lsl)'"'
|
251 |
+
local booktabs_starlevels `"`macval(tex_starlevels)'"'
|
252 |
+
local booktabs_starlevlab `"`macval(tex_starlevlab)'"'
|
253 |
+
local booktabs_begin `"`macval(tex_begin)'"'
|
254 |
+
local booktabs_delimiter `"`macval(tex_delimiter)'"'
|
255 |
+
local booktabs_end `"`macval(tex_end)'"'
|
256 |
+
local booktabs_incelldel `"`macval(tex_incelldel)'"'
|
257 |
+
local booktabs_varwidth `"`macval(tex_varwidth)'"'
|
258 |
+
local booktabs_modelwidth `"`macval(tex_modelwidth)'"'
|
259 |
+
local booktabs_abbrev `"`macval(tex_abbrev)'"'
|
260 |
+
local booktabs_tstatlab `"`macval(tex_tstatlab)'"'
|
261 |
+
local booktabs_zstatlab `"`macval(tex_zstatlab)'"'
|
262 |
+
local booktabs_pvallab `"`macval(tex_pvallab)'"'
|
263 |
+
local booktabs_cilab `"`macval(tex_cilab)'"'
|
264 |
+
local booktabs_substitute `"`macval(tex_substitute)'"'
|
265 |
+
local booktabs_interaction `"`macval(tex_interaction)'"'
|
266 |
+
|
267 |
+
// syntax
|
268 |
+
syntax [anything] [using] [ , ///
|
269 |
+
/// coefficients and t-stats, se, etc.
|
270 |
+
b Bfmt(string) ///
|
271 |
+
noT Tfmt(string) ///
|
272 |
+
z Zfmt(string) ///
|
273 |
+
se SEfmt(string) ///
|
274 |
+
p Pfmt(string) ///
|
275 |
+
ci CIfmt(string) ///
|
276 |
+
BEta BEtafmt(string) ///
|
277 |
+
main(string) /// syntax: name format
|
278 |
+
aux(string) /// syntax: name format
|
279 |
+
abs /// absolute t-values
|
280 |
+
wide ///
|
281 |
+
NOSTAr STAR STAR2(string asis) ///
|
282 |
+
staraux ///
|
283 |
+
NOCONstant CONstant ///
|
284 |
+
COEFlabels(string asis) ///
|
285 |
+
/// summary statistics
|
286 |
+
noOBS obslast ///
|
287 |
+
r2 R2fmt(string) ar2 AR2fmt(string) pr2 PR2fmt(string) ///
|
288 |
+
aic AICfmt(string) bic BICfmt(string) ///
|
289 |
+
SCAlars(string asis) /// syntax: "name1 [label1]" "name2 [label2]" etc.
|
290 |
+
sfmt(string) ///
|
291 |
+
/// layout
|
292 |
+
NOMTItles MTItles MTItles2(string asis) ///
|
293 |
+
NOGAPs GAPs ///
|
294 |
+
NOLInes LInes ///
|
295 |
+
ADDNotes(string asis) ///
|
296 |
+
COMpress ///
|
297 |
+
plain ///
|
298 |
+
smcl FIXed tab csv SCsv rtf HTMl tex BOOKTabs ///
|
299 |
+
Fragment ///
|
300 |
+
page PAGE2(str) ///
|
301 |
+
ALIGNment(str asis) ///
|
302 |
+
width(str asis) ///
|
303 |
+
/// other
|
304 |
+
Noisily ///
|
305 |
+
* ]
|
306 |
+
_more_syntax , `macval(options)'
|
307 |
+
_estout_options , `macval(options)'
|
308 |
+
|
309 |
+
// matrix mode
|
310 |
+
MatrixMode, `anything'
|
311 |
+
|
312 |
+
// syntax consistency etc
|
313 |
+
gettoken chunk using0: using
|
314 |
+
if `"`macval(star2)'"'!="" local star star
|
315 |
+
foreach opt in constant gaps lines star abbrev depvars numbers parentheses ///
|
316 |
+
notes mtitles type outfilenoteoff {
|
317 |
+
NotBothAllowed "``opt''" `no`opt''
|
318 |
+
}
|
319 |
+
NotBothAllowed "`staraux'" `nostar'
|
320 |
+
if `"`macval(mtitles2)'"'!="" NotBothAllowed "mtitles" `nomtitles'
|
321 |
+
if `"`page2'"'!="" local page page
|
322 |
+
NotBothAllowed "`fragment'" `page'
|
323 |
+
if `"`pfmt'"'!="" local p p
|
324 |
+
if `"`zfmt'"'!="" local z z
|
325 |
+
if `"`sefmt'"'!="" local se se
|
326 |
+
if `"`cifmt'"'!="" local ci ci
|
327 |
+
if `"`betafmt'"'!="" local beta beta
|
328 |
+
if "`level'"=="" local level $S_level
|
329 |
+
if ((("`margin'"!="" | `"`margin2'"'!="") & "`nomargin'"=="") | ///
|
330 |
+
("`beta'"!="") | ("`eform'"!="" & "`noeform'"=="")) ///
|
331 |
+
& "`constant'"=="" local noconstant noconstant
|
332 |
+
if `"`r2fmt'"'!="" local r2 r2
|
333 |
+
if `"`ar2fmt'"'!="" local ar2 ar2
|
334 |
+
if `"`pr2fmt'"'!="" local pr2 pr2
|
335 |
+
if `"`aicfmt'"'!="" local aic aic
|
336 |
+
if `"`bicfmt'"'!="" local bic bic
|
337 |
+
if "`type'"=="" & `"`using'"'!="" local notype notype
|
338 |
+
local nocellsopt = `"`macval(cells)'"'==""
|
339 |
+
if `"`width'"'!="" & `"`longtable'"'!="" {
|
340 |
+
di as err "width() and longtable not both allowed"
|
341 |
+
exit 198
|
342 |
+
}
|
343 |
+
|
344 |
+
// format modes
|
345 |
+
local mode `smcl' `fixed' `tab' `csv' `scsv' `rtf' `html' `tex' `booktabs'
|
346 |
+
if `:list sizeof mode'>1 {
|
347 |
+
di as err "only one allowed of smcl, fixed, tab, csv, scsv, rtf, html, tex, or booktabs"
|
348 |
+
exit 198
|
349 |
+
}
|
350 |
+
if `"`using'"'!="" {
|
351 |
+
_getfilename `"`using0'"'
|
352 |
+
local fn `"`r(filename)'"'
|
353 |
+
_getfilesuffix `"`fn'"'
|
354 |
+
local suffix `"`r(suffix)'"'
|
355 |
+
}
|
356 |
+
if "`mode'"=="" {
|
357 |
+
if `"`using'"'!="" {
|
358 |
+
if inlist(`"`suffix'"', ".html", ".htm") local mode html
|
359 |
+
else if `"`suffix'"'==".tex" local mode tex
|
360 |
+
else if `"`suffix'"'==".csv" local mode csv
|
361 |
+
else if `"`suffix'"'==".rtf" local mode rtf
|
362 |
+
else if `"`suffix'"'==".smcl" local mode smcl
|
363 |
+
else local mode fixed
|
364 |
+
}
|
365 |
+
else local mode smcl
|
366 |
+
}
|
367 |
+
else {
|
368 |
+
if "`mode'"=="scsv" {
|
369 |
+
local csv_delimiter `"`macval(`mode'_delimiter)'"'
|
370 |
+
local mode "csv"
|
371 |
+
}
|
372 |
+
}
|
373 |
+
if `"`using'"'!="" & `"`suffix'"'=="" {
|
374 |
+
if inlist("`mode'","fixed","tab") local suffix ".txt"
|
375 |
+
else if inlist("`mode'","csv","scsv") local suffix ".csv"
|
376 |
+
else if "`mode'"=="rtf" local suffix ".rtf"
|
377 |
+
else if "`mode'"=="html" local suffix ".html"
|
378 |
+
else if inlist("`mode'","tex","booktabs") local suffix ".tex"
|
379 |
+
else if "`mode'"=="smcl" local suffix ".smcl"
|
380 |
+
local using `"using `"`fn'`suffix'"'"'
|
381 |
+
local using0 `" `"`fn'`suffix'"'"'
|
382 |
+
}
|
383 |
+
if "`mode'"=="smcl" local smcltags smcltags
|
384 |
+
local mode0 `mode'
|
385 |
+
if "`mode0'"=="booktabs" local mode0 tex
|
386 |
+
else if "`mode0'"=="csv" {
|
387 |
+
if "`plain'"=="" local csvlhs `"=""'
|
388 |
+
else local csvlhs `"""'
|
389 |
+
}
|
390 |
+
if "`compress'"!="" {
|
391 |
+
if "``mode'_modelwidth'"!="" {
|
392 |
+
local `mode'_modelwidth = ``mode'_modelwidth' - 3
|
393 |
+
}
|
394 |
+
if "``mode'_varwidth'"!="" {
|
395 |
+
local `mode'_varwidth = ``mode'_varwidth' - cond("`label'"!="", 4, 2)
|
396 |
+
}
|
397 |
+
}
|
398 |
+
if `"`modelwidth'"'=="" {
|
399 |
+
if `nocellsopt' & `"``mode'_modelwidth'"'!="" & "`ci'"!="" {
|
400 |
+
local modelwidth = 2*``mode'_modelwidth' - 2
|
401 |
+
if "`wide'"!="" local modelwidth "``mode'_modelwidth' `modelwidth'"
|
402 |
+
}
|
403 |
+
else {
|
404 |
+
local modelwidth "``mode'_modelwidth'"
|
405 |
+
}
|
406 |
+
}
|
407 |
+
if `"`varwidth'"'=="" {
|
408 |
+
local varwidth "``mode'_varwidth'"
|
409 |
+
}
|
410 |
+
if "`plain'"=="" & `matrixmode'==0 {
|
411 |
+
foreach opt in star depvars numbers parentheses notes {
|
412 |
+
SwitchOnIfEmpty `opt' `no`opt''
|
413 |
+
}
|
414 |
+
if "`wide'"=="" & ("`t'"=="" | "`z'`se'`p'`ci'`aux'"!="") & `nocellsopt'==1 ///
|
415 |
+
SwitchOnIfEmpty gaps `nogaps'
|
416 |
+
}
|
417 |
+
if "`plain'"=="" {
|
418 |
+
SwitchOnIfEmpty lines `nolines'
|
419 |
+
}
|
420 |
+
if `"`lines'"'!="" {
|
421 |
+
SwitchOnIfEmpty eqlines `noeqlines'
|
422 |
+
}
|
423 |
+
if inlist("`mode0'", "tab", "csv") {
|
424 |
+
local lines
|
425 |
+
local eqlines
|
426 |
+
}
|
427 |
+
if "`notes'"!="" & "`nolegend'"=="" & `nocellsopt'==1 & `matrixmode'==0 local legend legend
|
428 |
+
if "`plain'"!="" {
|
429 |
+
if "`bfmt'"=="" local bfmt %9.0g
|
430 |
+
if "`tfmt'"=="" local tfmt `bfmt'
|
431 |
+
if "`zfmt'"=="" local zfmt `bfmt'
|
432 |
+
if "`sefmt'"=="" local sefmt `bfmt'
|
433 |
+
if "`pfmt'"=="" local pfmt `bfmt'
|
434 |
+
if "`cifmt'"=="" local cifmt `bfmt'
|
435 |
+
if "`betafmt'"=="" local betafmt `bfmt'
|
436 |
+
}
|
437 |
+
//if "`nomtitles'"!="" local depvars
|
438 |
+
//else if "`depvars'"=="" local mtitles mtitles
|
439 |
+
|
440 |
+
// prepare append for rtf, tex, and html
|
441 |
+
local outfilenoteoff2 "`outfilenoteoff'"
|
442 |
+
if "`outfilenoteoff2'"=="" local outfilenoteoff2 "`nooutfilenoteoff'"
|
443 |
+
if `"`using'"'!="" & "`append'"!="" & ///
|
444 |
+
(("`mode0'"=="rtf" & "`fragment'"=="") | ///
|
445 |
+
("`page'"!="" & inlist("`mode0'", "tex", "html"))) {
|
446 |
+
capture confirm file `using0'
|
447 |
+
if _rc==0 {
|
448 |
+
tempfile appendfile
|
449 |
+
if "`mode'"=="rtf" local `mode'_open
|
450 |
+
else local `mode'_open0
|
451 |
+
local append
|
452 |
+
if "`outfilenoteoff2'"=="" local outfilenoteoff2 outfilenoteoff
|
453 |
+
}
|
454 |
+
}
|
455 |
+
|
456 |
+
// cells() option
|
457 |
+
if "`notes'"!="" {
|
458 |
+
if ("`margin'"!="" | `"`margin2'"'!="") & "`nomargin'"=="" ///
|
459 |
+
local thenote "`thenote'Marginal effects"
|
460 |
+
if "`eform'"!="" & "`noeform'"=="" ///
|
461 |
+
local thenote "`thenote'Exponentiated coefficients"
|
462 |
+
}
|
463 |
+
if "`bfmt'"=="" local bfmt a3
|
464 |
+
if `nocellsopt' & `matrixmode'==0 {
|
465 |
+
if "`star'"!="" & "`staraux'"=="" local bstar star
|
466 |
+
if "`beta'"!="" {
|
467 |
+
if "`main'"!="" {
|
468 |
+
di as err "beta() and main() not allowed both"
|
469 |
+
exit 198
|
470 |
+
}
|
471 |
+
if "`betafmt'"=="" local betafmt 3
|
472 |
+
local cells fmt(`betafmt') `bstar'
|
473 |
+
local cells beta(`cells')
|
474 |
+
if "`notes'"!="" {
|
475 |
+
if `"`thenote'"'!="" local thenote "`thenote'; "
|
476 |
+
local thenote "`thenote'Standardized beta coefficients"
|
477 |
+
}
|
478 |
+
}
|
479 |
+
else if "`main'"!="" {
|
480 |
+
tokenize "`main'"
|
481 |
+
if "`2'"=="" local 2 "`bfmt'"
|
482 |
+
local cells fmt(`2') `bstar'
|
483 |
+
local cells `1'(`cells')
|
484 |
+
if "`notes'"!="" {
|
485 |
+
if `"`thenote'"'!="" local thenote "`thenote'; "
|
486 |
+
local thenote "`thenote'`1' coefficients"
|
487 |
+
}
|
488 |
+
}
|
489 |
+
else {
|
490 |
+
local cells fmt(`bfmt') `bstar'
|
491 |
+
local cells b(`cells')
|
492 |
+
}
|
493 |
+
if "`t'"=="" | "`z'`se'`p'`ci'`aux'"!="" {
|
494 |
+
if "`onecell'"!="" {
|
495 |
+
local cells `cells' &
|
496 |
+
}
|
497 |
+
// parse aux option
|
498 |
+
tokenize "`aux'"
|
499 |
+
local auxname `1'
|
500 |
+
local auxfmt `2'
|
501 |
+
// type of auxiliary statistic
|
502 |
+
local aux `z' `se' `p' `ci' `auxname'
|
503 |
+
if `"`aux'"'=="" local aux t
|
504 |
+
else {
|
505 |
+
if `:list sizeof aux'>1 {
|
506 |
+
di as err "only one allowed of z, se, p, ci, and aux()"
|
507 |
+
exit 198
|
508 |
+
}
|
509 |
+
}
|
510 |
+
if !inlist(`"`aux'"', "t", "z") local abs
|
511 |
+
// parentheses/brackets
|
512 |
+
if "`parentheses'"!="" | "`brackets'"!="" {
|
513 |
+
if `"`aux'"'=="ci" {
|
514 |
+
local brackets brackets
|
515 |
+
if "`mode'"!="smcl" | "`onecell'"!="" local paren par
|
516 |
+
else local paren `"par("{ralign @modelwidth:{txt:[}" "{txt:,}" "{txt:]}}")"'
|
517 |
+
}
|
518 |
+
else if "`brackets'"!="" {
|
519 |
+
if "`mode'"!="smcl" | "`onecell'"!="" local paren "par([ ])"
|
520 |
+
else local paren `"par("{ralign @modelwidth:{txt:[}" "{txt:]}}")"'
|
521 |
+
}
|
522 |
+
else {
|
523 |
+
if "`mode'"!="smcl" | "`onecell'"!="" local paren par
|
524 |
+
else local paren `"par("{ralign @modelwidth:{txt:(}" "{txt:)}}")"'
|
525 |
+
}
|
526 |
+
}
|
527 |
+
// compose note
|
528 |
+
if "`notes'"!="" {
|
529 |
+
if `"`thenote'"'!="" local thenote "`thenote'; "
|
530 |
+
if `"`auxname'"'!="" {
|
531 |
+
local thenote `"`macval(thenote)'`auxname'"'
|
532 |
+
}
|
533 |
+
else if inlist(`"`aux'"', "t", "z") {
|
534 |
+
if "`abs'"!="" local thenote `"`macval(thenote)'Absolute "'
|
535 |
+
local thenote `"`macval(thenote)'``mode'_`aux'statlab'"'
|
536 |
+
}
|
537 |
+
else if `"`aux'"'=="se" {
|
538 |
+
local thenote `"`macval(thenote)'Standard errors"'
|
539 |
+
}
|
540 |
+
else if `"`aux'"'=="p" {
|
541 |
+
local thenote `"`macval(thenote)'``mode'_pvallab'"'
|
542 |
+
}
|
543 |
+
else if `"`aux'"'=="ci" {
|
544 |
+
local thenote `"`macval(thenote)'``mode'_cilab'"'
|
545 |
+
}
|
546 |
+
if "`parentheses'"=="" {
|
547 |
+
if "`wide'"=="" local thenote `"`macval(thenote)' in second row"'
|
548 |
+
else local thenote `"`macval(thenote)' in second column"'
|
549 |
+
}
|
550 |
+
else if "`brackets'"!="" {
|
551 |
+
local thenote `"`macval(thenote)' in brackets"'
|
552 |
+
}
|
553 |
+
else local thenote `"`macval(thenote)' in parentheses"'
|
554 |
+
}
|
555 |
+
// formats
|
556 |
+
if "`tfmt'"=="" local tfmt 2
|
557 |
+
if "`zfmt'"=="" local zfmt 2
|
558 |
+
if "`sefmt'"=="" local sefmt `bfmt'
|
559 |
+
if "`pfmt'"=="" local pfmt 3
|
560 |
+
if "`cifmt'"=="" local cifmt `bfmt'
|
561 |
+
if `"`auxfmt'"'=="" local auxfmt `bfmt'
|
562 |
+
if `"`auxname'"'=="" {
|
563 |
+
local auxfmt ``aux'fmt'
|
564 |
+
}
|
565 |
+
// stars
|
566 |
+
if "`staraux'"!="" local staraux star
|
567 |
+
// put together
|
568 |
+
local temp fmt(`auxfmt') `paren' `abs' `staraux'
|
569 |
+
local cells `cells' `aux'(`temp')
|
570 |
+
}
|
571 |
+
if "`wide'"!="" local cells cells(`"`cells'"')
|
572 |
+
else local cells cells(`cells')
|
573 |
+
}
|
574 |
+
|
575 |
+
// stats() option
|
576 |
+
if `"`macval(stats)'"'=="" & `matrixmode'==0 {
|
577 |
+
if `"`sfmt'"'=="" local sfmt `bfmt'
|
578 |
+
if `"`r2fmt'"'=="" local r2fmt = cond("`plain'"!="", "`bfmt'", "3")
|
579 |
+
if `"`ar2fmt'"'=="" local ar2fmt = cond("`plain'"!="", "`bfmt'", "3")
|
580 |
+
if `"`pr2fmt'"'=="" local pr2fmt = cond("`plain'"!="", "`bfmt'", "3")
|
581 |
+
if `"`aicfmt'"'=="" local aicfmt `bfmt'
|
582 |
+
if `"`bicfmt'"'=="" local bicfmt `bfmt'
|
583 |
+
if "`label'"=="" {
|
584 |
+
local stalabs `"``mode'_ssl'"'
|
585 |
+
}
|
586 |
+
else {
|
587 |
+
local stalabs `"``mode'_lsl'"'
|
588 |
+
}
|
589 |
+
gettoken obslab stalabs: stalabs
|
590 |
+
if "`obs'"=="" & "`obslast'"=="" {
|
591 |
+
local sta N
|
592 |
+
local stalab `"`"`macval(obslab)'"'"'
|
593 |
+
local stafmt %18.0g
|
594 |
+
}
|
595 |
+
local i 0
|
596 |
+
foreach s in r2 ar2 pr2 aic bic {
|
597 |
+
local ++i
|
598 |
+
if "``s''"!="" {
|
599 |
+
local sta `sta' `:word `i' of r2 r2_a r2_p aic bic'
|
600 |
+
local chunk: word `i' of `macval(stalabs)'
|
601 |
+
local stalab `"`macval(stalab)' `"`macval(chunk)'"'"'
|
602 |
+
local stafmt `stafmt' ``s'fmt'
|
603 |
+
}
|
604 |
+
}
|
605 |
+
local i 0
|
606 |
+
CheckScalarOpt `macval(scalars)'
|
607 |
+
foreach addstat of local scalars {
|
608 |
+
local ++i
|
609 |
+
gettoken addstatname addstatlabel: addstat
|
610 |
+
local addstatlabel = substr(`"`macval(addstatlabel)'"',2,.)
|
611 |
+
if `: list posof `"`addstatname'"' in sta' continue
|
612 |
+
if `"`addstatname'"'=="N" & "`obs'"=="" & "`obslast'"!="" continue
|
613 |
+
if trim(`"`macval(addstatlabel)'"')=="" local addstatlabel `addstatname'
|
614 |
+
local addstatfmt: word `i' of `sfmt'
|
615 |
+
if `"`addstatfmt'"'=="" {
|
616 |
+
local addstatfmt: word `: list sizeof sfmt' of `sfmt'
|
617 |
+
}
|
618 |
+
local sta `sta' `addstatname'
|
619 |
+
local stalab `"`macval(stalab)' `"`macval(addstatlabel)'"'"'
|
620 |
+
local stafmt `stafmt' `addstatfmt'
|
621 |
+
}
|
622 |
+
if "`obs'"=="" & "`obslast'"!="" {
|
623 |
+
local sta `sta' N
|
624 |
+
local stalab `"`macval(stalab)' `"`macval(obslab)'"'"'
|
625 |
+
local stafmt `stafmt' %18.0g
|
626 |
+
}
|
627 |
+
if "`sta'"!="" {
|
628 |
+
local stats stats(`sta', fmt(`stafmt') labels(`macval(stalab)'))
|
629 |
+
}
|
630 |
+
}
|
631 |
+
|
632 |
+
// table header
|
633 |
+
if `"`macval(mlabels)'"'=="" {
|
634 |
+
if "`mode0'"=="tex" local mspan " span prefix(\multicolumn{@span}{c}{) suffix(})"
|
635 |
+
if `"`depvars'"'!="" {
|
636 |
+
local mlabels `"mlabels(, depvar`mspan')"'
|
637 |
+
}
|
638 |
+
if `"`nomtitles'"'!="" local mlabels `"mlabels(none)"'
|
639 |
+
if "`mtitles'"!="" {
|
640 |
+
local mlabels `"mlabels(, titles`mspan')"'
|
641 |
+
}
|
642 |
+
if `"`macval(mtitles2)'"'!="" {
|
643 |
+
local mlabels `"mlabels(`macval(mtitles2)', titles`mspan')"'
|
644 |
+
}
|
645 |
+
}
|
646 |
+
if `"`macval(collabels)'"'=="" & `nocellsopt' & `matrixmode'==0 & "`plain'"=="" {
|
647 |
+
local collabels `"collabels(none)"'
|
648 |
+
}
|
649 |
+
if "`mode0'"=="tex" & "`numbers'"!="" {
|
650 |
+
local numbers "numbers(\multicolumn{@span}{c}{( )})"
|
651 |
+
}
|
652 |
+
|
653 |
+
// pre-/posthead, pre-/postfoot, gaps and lines
|
654 |
+
// - complete note
|
655 |
+
if `"`macval(thenote)'"'!="" {
|
656 |
+
local thenote `"`"`macval(thenote)'"'"'
|
657 |
+
}
|
658 |
+
if `"`macval(note)'"'!="" {
|
659 |
+
local thenote `""@note""'
|
660 |
+
}
|
661 |
+
if `"`macval(addnotes)'"'!="" {
|
662 |
+
if index(`"`macval(addnotes)'"', `"""')==0 {
|
663 |
+
local addnotes `"`"`macval(addnotes)'"'"'
|
664 |
+
}
|
665 |
+
local thenote `"`macval(thenote)' `macval(addnotes)'"'
|
666 |
+
}
|
667 |
+
if "`legend'"!="" {
|
668 |
+
if ("`margin'"!="" | `"`margin2'"'!="") & ///
|
669 |
+
"`nomargin'"=="" & "`nodiscrete'"=="" {
|
670 |
+
local thenote `"`macval(thenote)' "@discrete""'
|
671 |
+
}
|
672 |
+
if "`star'"!="" | `nocellsopt'==0 {
|
673 |
+
local thenote `"`macval(thenote)' "@starlegend""'
|
674 |
+
}
|
675 |
+
}
|
676 |
+
// - mode specific settings
|
677 |
+
if "`star'"!="" {
|
678 |
+
if `"`macval(star2)'"'!="" {
|
679 |
+
FormatStarSym "`mode0'" `"`macval(star2)'"'
|
680 |
+
local `mode'_starlevels `"`macval(star2)'"'
|
681 |
+
}
|
682 |
+
if `"`macval(starlevels)'"'=="" {
|
683 |
+
local starlevels `"starlevels(`macval(`mode'_starlevels)'`macval(`mode'_starlevlab)')"'
|
684 |
+
}
|
685 |
+
}
|
686 |
+
foreach opt in begin delimiter end substitute interaction {
|
687 |
+
if `"`macval(`opt')'"'=="" & `"``mode'_`opt''"'!="" {
|
688 |
+
local `opt' `"`opt'(``mode'_`opt'')"'
|
689 |
+
}
|
690 |
+
}
|
691 |
+
if "`onecell'"!="" {
|
692 |
+
if `"`macval(incelldelimiter)'"'=="" {
|
693 |
+
local incelldelimiter `"incelldelimiter(``mode'_incelldel')"'
|
694 |
+
}
|
695 |
+
}
|
696 |
+
if "`noabbrev'`abbrev'"=="" {
|
697 |
+
local abbrev ``mode'_abbrev'
|
698 |
+
}
|
699 |
+
if `"`fragment'"'=="" {
|
700 |
+
if "`page'"!="" {
|
701 |
+
if `"`page2'"'!="" {
|
702 |
+
local texpkgs `""\usepackage{`page2'}""'
|
703 |
+
}
|
704 |
+
local opening `"``mode'_open0'"'
|
705 |
+
}
|
706 |
+
if `"`macval(title)'"'!="" {
|
707 |
+
local opening `"`macval(opening)' ``mode'_open'"'
|
708 |
+
if "`mode0'"=="tex" & "`star'"!="" {
|
709 |
+
local opening `"`macval(opening)' "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}""'
|
710 |
+
}
|
711 |
+
if !("`longtable'"!="" & "`mode0'"=="tex") {
|
712 |
+
local opening `"`macval(opening)' ``mode'_caption'"'
|
713 |
+
}
|
714 |
+
}
|
715 |
+
else if "`mode0'"=="tex" & "`star'"!="" {
|
716 |
+
local opening `"`macval(opening)' "{" "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}""'
|
717 |
+
}
|
718 |
+
else if "`mode0'"!="tex" {
|
719 |
+
local opening `"`macval(opening)' ``mode'_open'"'
|
720 |
+
}
|
721 |
+
local opening `"`macval(opening)' ``mode'_open2'"'
|
722 |
+
if "`mode0'"=="tex" {
|
723 |
+
if `"`labcol2'"'!="" local lstubtex "lc"
|
724 |
+
else local lstubtex "l"
|
725 |
+
if `"`width'"'!="" local extracolsep "@{\hskip\tabcolsep\extracolsep\fill}"
|
726 |
+
if `"`macval(alignment)'"'!="" {
|
727 |
+
local opening `"`macval(opening)'{`extracolsep'`lstubtex'*{@E}{`macval(alignment)'}}"'
|
728 |
+
}
|
729 |
+
else {
|
730 |
+
if `nocellsopt' {
|
731 |
+
MakeTeXColspec "`wide'" "`not'" "`star'" "`stardetach'" "`staraux'"
|
732 |
+
}
|
733 |
+
else {
|
734 |
+
MakeTeXColspecAlt, `cells'
|
735 |
+
}
|
736 |
+
local opening `"`macval(opening)'{`extracolsep'`lstubtex'*{@E}{`value'}}"'
|
737 |
+
}
|
738 |
+
if "`longtable'"!="" {
|
739 |
+
if `"`macval(title)'"'!="" {
|
740 |
+
local opening `"`macval(opening)' ``mode'_caption'\\\"'
|
741 |
+
}
|
742 |
+
}
|
743 |
+
}
|
744 |
+
if "`mode0'"=="html" {
|
745 |
+
local brr
|
746 |
+
foreach chunk of local thenote {
|
747 |
+
local closing `"`macval(closing)' `"`brr'`macval(chunk)'"'"'
|
748 |
+
local brr "<br />"
|
749 |
+
}
|
750 |
+
if `"`macval(closing)'"'!="" {
|
751 |
+
local closing `""<tr><td colspan=@span>" `macval(closing)' "</td></tr>""'
|
752 |
+
}
|
753 |
+
}
|
754 |
+
else if "`mode0'"=="tex" {
|
755 |
+
foreach chunk of local thenote {
|
756 |
+
local closing `"`macval(closing)' `"\multicolumn{@span}{l}{\footnotesize `macval(chunk)'}\\\"'"'
|
757 |
+
}
|
758 |
+
}
|
759 |
+
else if "`mode0'"=="csv" {
|
760 |
+
foreach chunk of local thenote {
|
761 |
+
local closing `"`macval(closing)' `"`csvlhs'`macval(chunk)'""'"'
|
762 |
+
}
|
763 |
+
}
|
764 |
+
else if "`mode0'"=="rtf" {
|
765 |
+
foreach chunk of local thenote {
|
766 |
+
local closing `"`macval(closing)' `"{\pard\ql\fs20 `macval(chunk)'\par}"'"'
|
767 |
+
}
|
768 |
+
}
|
769 |
+
else {
|
770 |
+
local closing `"`macval(thenote)'"'
|
771 |
+
}
|
772 |
+
local closing `"`macval(closing)' ``mode'_close2'"'
|
773 |
+
if `"`macval(title)'"'!="" | "`mode0'"!="tex" {
|
774 |
+
local closing `"`macval(closing)' ``mode'_close'"'
|
775 |
+
}
|
776 |
+
else if "`mode0'"=="tex" & "`star'"!="" {
|
777 |
+
local closing `"`macval(closing)' }"'
|
778 |
+
}
|
779 |
+
if "`page'"!="" {
|
780 |
+
local closing `"`macval(closing)' ``mode'_close0'"'
|
781 |
+
}
|
782 |
+
local toprule `"``mode'_toprule'"'
|
783 |
+
local bottomrule `"``mode'_bottomrule'"'
|
784 |
+
local topgap `"``mode'_topgap'"'
|
785 |
+
local bottomgap `"``mode'_bottomgap'"'
|
786 |
+
}
|
787 |
+
local midrule `"``mode'_midrule'"'
|
788 |
+
local midgap `"``mode'_midgap'"'
|
789 |
+
local eqrule `"``mode'_eqrule'"'
|
790 |
+
// - compose prehead()
|
791 |
+
if `"`macval(prehead)'"'=="" {
|
792 |
+
if `"`lines'"'!="" {
|
793 |
+
local opening `"`macval(opening)' `macval(toprule)'"'
|
794 |
+
}
|
795 |
+
else if `"`gaps'"'!="" {
|
796 |
+
local opening `"`macval(opening)' `macval(topgap)'"'
|
797 |
+
}
|
798 |
+
SaveRetok `macval(opening)'
|
799 |
+
local opening `"`macval(value)'"'
|
800 |
+
if `"`macval(opening)'"'!="" {
|
801 |
+
local prehead `"prehead(`macval(opening)')"'
|
802 |
+
}
|
803 |
+
}
|
804 |
+
// - compose posthead()
|
805 |
+
if `"`macval(posthead)'"'=="" {
|
806 |
+
if `"`lines'"'!="" {
|
807 |
+
local posthead `"posthead(`macval(midrule)')"'
|
808 |
+
}
|
809 |
+
else if `"`gaps'"'!="" {
|
810 |
+
local posthead `"posthead(`macval(midgap)')"'
|
811 |
+
}
|
812 |
+
}
|
813 |
+
// - compose prefoot()
|
814 |
+
if `"`macval(prefoot)'"'=="" & `"`macval(stats)'"'!="" {
|
815 |
+
if `"`lines'"'!="" {
|
816 |
+
local prefoot `"prefoot(`macval(midrule)')"'
|
817 |
+
}
|
818 |
+
else if `"`gaps'"'!="" {
|
819 |
+
local prefoot `"prefoot(`macval(midgap)')"'
|
820 |
+
}
|
821 |
+
if `"`cells'"'=="cells(none)" local prefoot
|
822 |
+
}
|
823 |
+
// - compose postfoot()
|
824 |
+
if `"`macval(postfoot)'"'=="" {
|
825 |
+
if `"`lines'"'!="" {
|
826 |
+
local closing `"`macval(bottomrule)' `macval(closing)'"'
|
827 |
+
}
|
828 |
+
else if `"`gaps'"'!="" {
|
829 |
+
local closing `"`macval(bottomgap)' `macval(closing)'"'
|
830 |
+
}
|
831 |
+
SaveRetok `macval(closing)'
|
832 |
+
local closing `"`macval(value)'"'
|
833 |
+
if `"`macval(closing)'"'!="" {
|
834 |
+
local postfoot postfoot(`macval(closing)')
|
835 |
+
}
|
836 |
+
}
|
837 |
+
// - varlabels
|
838 |
+
if `"`macval(varlabels)'"'=="" {
|
839 |
+
if `"`gaps'"'!="" {
|
840 |
+
local varl `", end("" `macval(midgap)') nolast"'
|
841 |
+
}
|
842 |
+
if "`label'"!="" {
|
843 |
+
local varl `"_cons Constant`macval(varl)'"'
|
844 |
+
}
|
845 |
+
if `"`macval(coeflabels)'"'!="" {
|
846 |
+
local varl `"`macval(coeflabels)' `macval(varl)'"'
|
847 |
+
}
|
848 |
+
if trim(`"`macval(varl)'"')!="" {
|
849 |
+
local varlabels varlabels(`macval(varl)')
|
850 |
+
}
|
851 |
+
}
|
852 |
+
// - equation labels
|
853 |
+
if ("`eqlines'"!="" | `"`gaps'"'!="") & "`unstack'"=="" {
|
854 |
+
if trim(`"`eqlabels'"')!="none" {
|
855 |
+
ParseEqLabels `macval(eqlabels)'
|
856 |
+
if `eqlabelsok' {
|
857 |
+
_parse comma eqllhs eqlrhs : eqlabels
|
858 |
+
if `"`eqlrhs'"'=="" local eqlabelscomma ", "
|
859 |
+
else local eqlabelscomma " "
|
860 |
+
if "`eqlines'"!=""{
|
861 |
+
local eqlabels `"`macval(eqlabels)'`eqlabelscomma'`macval(eqrule)' nofirst"'
|
862 |
+
}
|
863 |
+
else if `"`gaps'"'!="" {
|
864 |
+
local eqlabels `"`macval(eqlabels)'`eqlabelscomma'begin(`macval(midgap)' "") nofirst"'
|
865 |
+
}
|
866 |
+
}
|
867 |
+
}
|
868 |
+
}
|
869 |
+
if `"`macval(eqlabels)'"'!="" {
|
870 |
+
local eqlabels `"eqlabels(`macval(eqlabels)')"'
|
871 |
+
}
|
872 |
+
|
873 |
+
// noconstant option
|
874 |
+
if `"`drop'"'=="" {
|
875 |
+
if "`noconstant'"!="" {
|
876 |
+
local drop drop(_cons, relax)
|
877 |
+
}
|
878 |
+
}
|
879 |
+
|
880 |
+
// compute beta coefficients (run estadd to add e(beta))
|
881 |
+
if "`beta'"!="" {
|
882 |
+
local estnames `"`anything'"'
|
883 |
+
if `"`estnames'"'=="" {
|
884 |
+
capt est_expand $eststo
|
885 |
+
if !_rc {
|
886 |
+
local estnames `"$eststo"'
|
887 |
+
}
|
888 |
+
}
|
889 |
+
version `caller': estadd beta, replace: `estnames'
|
890 |
+
}
|
891 |
+
|
892 |
+
// use tempfile for new table
|
893 |
+
if `"`appendfile'"'!="" {
|
894 |
+
local using `"using `"`appendfile'"'"'
|
895 |
+
}
|
896 |
+
|
897 |
+
// execute estout
|
898 |
+
if `"`varwidth'"'!="" local varwidth `"varwidth(`varwidth')"'
|
899 |
+
if `"`modelwidth'"'!="" local modelwidth `"modelwidth(`modelwidth')"'
|
900 |
+
if `"`style'"'=="" local style "style(esttab)"
|
901 |
+
CleanEstoutCmd `anything' `using' , ///
|
902 |
+
`macval(cells)' `drop' `nomargin' `margin' `margin2' `noeform' `eform' ///
|
903 |
+
`nodiscrete' `macval(stats)' `stardetach' `macval(starlevels)' ///
|
904 |
+
`varwidth' `modelwidth' `noabbrev' `abbrev' `unstack' `macval(begin)' ///
|
905 |
+
`macval(delimiter)' `macval(end)' `macval(incelldelimiter)' `smcltags' ///
|
906 |
+
`macval(title)' `macval(prehead)' `macval(posthead)' `macval(prefoot)' ///
|
907 |
+
`macval(postfoot)' `label' `macval(varlabels)' `macval(mlabels)' `nonumbers' ///
|
908 |
+
`numbers' `macval(collabels)' `macval(eqlabels)' `macval(mgroups)' ///
|
909 |
+
`macval(note)' `macval(labcol2)' `macval(substitute)' `macval(interaction)' ///
|
910 |
+
`append' `notype'`type' `outfilenoteoff2' level(`level') `style' ///
|
911 |
+
`macval(options)'
|
912 |
+
if "`noisily'"!="" {
|
913 |
+
gettoken chunk rest: cmd, parse(",")
|
914 |
+
di as txt _asis `"`chunk'"' _c
|
915 |
+
gettoken chunk rest: rest, bind
|
916 |
+
while `"`macval(chunk)'"'!="" {
|
917 |
+
di as txt _asis `" `macval(chunk)'"'
|
918 |
+
gettoken chunk rest: rest, bind
|
919 |
+
}
|
920 |
+
}
|
921 |
+
`macval(cmd)'
|
922 |
+
|
923 |
+
// insert new table into existing document (tex, html, rtf)
|
924 |
+
if `"`appendfile'"'!="" {
|
925 |
+
local enddoctex "\end{document}"
|
926 |
+
local enddochtml "</body>"
|
927 |
+
local enddocrtf "}"
|
928 |
+
local enddoc "`enddoc`mode0''"
|
929 |
+
tempname fh
|
930 |
+
file open `fh' using `using0', read write
|
931 |
+
file seek `fh' query
|
932 |
+
local loc = r(loc)
|
933 |
+
file read `fh' line
|
934 |
+
while r(eof)==0 {
|
935 |
+
if `"`line'"'=="`enddoc'" {
|
936 |
+
if "`mode'"=="rtf" {
|
937 |
+
file seek `fh' query
|
938 |
+
local loc0 = r(loc)
|
939 |
+
file read `fh' line
|
940 |
+
if r(eof)==0 {
|
941 |
+
local loc = `loc0'
|
942 |
+
continue
|
943 |
+
}
|
944 |
+
}
|
945 |
+
continue, break
|
946 |
+
}
|
947 |
+
file seek `fh' query
|
948 |
+
local loc = r(loc)
|
949 |
+
file read `fh' line
|
950 |
+
}
|
951 |
+
file seek `fh' `loc'
|
952 |
+
tempname new
|
953 |
+
file open `new' `using', read
|
954 |
+
file read `new' line
|
955 |
+
while r(eof)==0 {
|
956 |
+
file write `fh' `"`macval(line)'"' _n
|
957 |
+
file read `new' line
|
958 |
+
}
|
959 |
+
file close `fh'
|
960 |
+
file close `new'
|
961 |
+
if "`outfilenoteoff'"=="" {
|
962 |
+
di as txt `"(output written to {browse `using0'})"'
|
963 |
+
}
|
964 |
+
}
|
965 |
+
end
|
966 |
+
|
967 |
+
program _more_syntax
|
968 |
+
// using subroutine (rather than second syntax call) to preserve 'using'
|
969 |
+
local theoptions ///
|
970 |
+
NODEPvars DEPvars ///
|
971 |
+
NOPArentheses PArentheses ///
|
972 |
+
BRackets ///
|
973 |
+
NONOTEs NOTEs /// without s in helpfile
|
974 |
+
LONGtable ///
|
975 |
+
ONEcell ///
|
976 |
+
NOEQLInes ///
|
977 |
+
NOOUTFILENOTEOFF outfilenoteoff
|
978 |
+
syntax [, `theoptions' * ]
|
979 |
+
foreach opt of local theoptions {
|
980 |
+
local opt = lower("`opt'")
|
981 |
+
c_local `opt' "``opt''"
|
982 |
+
}
|
983 |
+
c_local options `"`macval(options)'"'
|
984 |
+
end
|
985 |
+
|
986 |
+
program _estout_options
|
987 |
+
syntax [, ///
|
988 |
+
Cells(passthru) ///
|
989 |
+
Drop(passthru) ///
|
990 |
+
/// Keep(string asis) ///
|
991 |
+
/// Order(string asis) ///
|
992 |
+
/// REName(passthru) ///
|
993 |
+
/// Indicate(string asis) ///
|
994 |
+
/// TRansform(string asis) ///
|
995 |
+
/// EQuations(passthru) ///
|
996 |
+
NOEFORM eform ///EFORM2(string) ///
|
997 |
+
NOMargin Margin Margin2(passthru) ///
|
998 |
+
NODIscrete /// DIscrete(string asis) ///
|
999 |
+
/// MEQs(string) ///
|
1000 |
+
/// NODROPPED dropped DROPPED2(string) ///
|
1001 |
+
level(numlist max=1 int >=10 <=99) ///
|
1002 |
+
Stats(passthru) ///
|
1003 |
+
STARLevels(passthru) ///
|
1004 |
+
/// NOSTARDetach ///
|
1005 |
+
STARDetach ///
|
1006 |
+
/// STARKeep(string asis) ///
|
1007 |
+
/// STARDrop(string asis) ///
|
1008 |
+
VARwidth(str) ///
|
1009 |
+
MODELwidth(str) ///
|
1010 |
+
NOABbrev ABbrev ///
|
1011 |
+
/// NOUNStack
|
1012 |
+
UNStack ///
|
1013 |
+
BEGin(passthru) ///
|
1014 |
+
DELimiter(passthru) ///
|
1015 |
+
INCELLdelimiter(passthru) ///
|
1016 |
+
end(passthru) ///
|
1017 |
+
/// DMarker(string) ///
|
1018 |
+
/// MSign(string) ///
|
1019 |
+
/// NOLZ lz ///
|
1020 |
+
SUBstitute(passthru) ///
|
1021 |
+
INTERACTion(passthru) ///
|
1022 |
+
TItle(passthru) ///
|
1023 |
+
NOLEgend LEgend ///
|
1024 |
+
PREHead(passthru) ///
|
1025 |
+
POSTHead(passthru) ///
|
1026 |
+
PREFoot(passthru) ///
|
1027 |
+
POSTFoot(passthru) ///
|
1028 |
+
/// HLinechar(string) ///
|
1029 |
+
/// NOLabel
|
1030 |
+
Label ///
|
1031 |
+
VARLabels(passthru) ///
|
1032 |
+
/// REFcat(string asis) ///
|
1033 |
+
MLabels(passthru) ///
|
1034 |
+
NONUMbers NUMbers ///NUMbers2(string asis) ///
|
1035 |
+
COLLabels(passthru) ///
|
1036 |
+
EQLabels(string asis) ///
|
1037 |
+
MGRoups(passthru) ///
|
1038 |
+
LABCOL2(passthru) ///
|
1039 |
+
/// NOReplace Replace ///
|
1040 |
+
/// NOAppend
|
1041 |
+
Append ///
|
1042 |
+
NOTYpe TYpe ///
|
1043 |
+
/// NOSHOWTABS showtabs ///
|
1044 |
+
/// TOPfile(string) ///
|
1045 |
+
/// BOTtomfile(string) ///
|
1046 |
+
STYle(passthru) ///
|
1047 |
+
/// DEFaults(string) ///
|
1048 |
+
/// NOASIS asis ///
|
1049 |
+
/// NOWRAP wrap ///
|
1050 |
+
/// NOSMCLTAGS smcltags ///
|
1051 |
+
/// NOSMCLRules SMCLRules ///
|
1052 |
+
/// NOSMCLMIDRules SMCLMIDRules ///
|
1053 |
+
/// NOSMCLEQRules SMCLEQRules ///
|
1054 |
+
note(passthru) ///
|
1055 |
+
* ]
|
1056 |
+
foreach opt in ///
|
1057 |
+
cells drop noeform eform nomargin margin margin2 nodiscrete ///
|
1058 |
+
level stats starlevels stardetach varwidth modelwidth unstack ///
|
1059 |
+
noabbrev abbrev begin delimiter incelldelimiter end substitute ///
|
1060 |
+
interaction title nolegend legend prehead posthead prefoot postfoot ///
|
1061 |
+
label varlabels mlabels labcol2 nonumbers numbers collabels eqlabels ///
|
1062 |
+
mgroups append notype type style note options {
|
1063 |
+
c_local `opt' `"`macval(`opt')'"'
|
1064 |
+
}
|
1065 |
+
end
|
1066 |
+
|
1067 |
+
program MatrixMode
|
1068 |
+
capt syntax [, Matrix(str asis) e(str asis) r(str asis) rename(str asis) ]
|
1069 |
+
if _rc | `"`matrix'`e'`r'"'=="" {
|
1070 |
+
c_local matrixmode 0
|
1071 |
+
exit
|
1072 |
+
}
|
1073 |
+
c_local matrixmode 1
|
1074 |
+
end
|
1075 |
+
|
1076 |
+
prog NotBothAllowed
|
1077 |
+
args opt1 opt2
|
1078 |
+
if `"`opt1'"'!="" {
|
1079 |
+
if `"`opt2'"'!="" {
|
1080 |
+
di as err `"options `opt1' and `opt2' not both allowed"'
|
1081 |
+
exit 198
|
1082 |
+
}
|
1083 |
+
}
|
1084 |
+
end
|
1085 |
+
|
1086 |
+
prog SwitchOnIfEmpty
|
1087 |
+
args opt1 opt2
|
1088 |
+
if `"`opt2'"'=="" {
|
1089 |
+
c_local `opt1' `opt1'
|
1090 |
+
}
|
1091 |
+
end
|
1092 |
+
|
1093 |
+
prog _getfilesuffix, rclass // based on official _getfilename.ado
|
1094 |
+
version 8
|
1095 |
+
gettoken filename rest : 0
|
1096 |
+
if `"`rest'"' != "" {
|
1097 |
+
exit 198
|
1098 |
+
}
|
1099 |
+
local hassuffix 0
|
1100 |
+
gettoken word rest : filename, parse(".")
|
1101 |
+
while `"`rest'"' != "" {
|
1102 |
+
local hassuffix 1
|
1103 |
+
gettoken word rest : rest, parse(".")
|
1104 |
+
}
|
1105 |
+
if `"`word'"'=="." {
|
1106 |
+
di as err `"incomplete filename; ends in ."'
|
1107 |
+
exit 198
|
1108 |
+
}
|
1109 |
+
if index(`"`word'"',"/") | index(`"`word'"',"\") local hassuffix 0
|
1110 |
+
if `hassuffix' return local suffix `".`word'"'
|
1111 |
+
else return local suffix ""
|
1112 |
+
end
|
1113 |
+
|
1114 |
+
prog FormatStarSym
|
1115 |
+
args mode list
|
1116 |
+
if inlist("`mode'","rtf","html","tex") {
|
1117 |
+
if "`mode'"=="rtf" {
|
1118 |
+
local prefix "{\super "
|
1119 |
+
local suffix "}"
|
1120 |
+
}
|
1121 |
+
else if "`mode'"=="html" {
|
1122 |
+
local prefix "<sup>"
|
1123 |
+
local suffix "</sup>"
|
1124 |
+
}
|
1125 |
+
else if "`mode'"=="tex" {
|
1126 |
+
local prefix "\sym{"
|
1127 |
+
local suffix "}"
|
1128 |
+
}
|
1129 |
+
local odd 1
|
1130 |
+
foreach l of local list {
|
1131 |
+
if `odd' {
|
1132 |
+
local l `"`"`prefix'`macval(l)'`suffix'"'"'
|
1133 |
+
local odd 0
|
1134 |
+
}
|
1135 |
+
else local odd 1
|
1136 |
+
local newlist `"`macval(newlist)'`space'`macval(l)'"'
|
1137 |
+
local space " "
|
1138 |
+
}
|
1139 |
+
c_local star2 `"`macval(newlist)'"'
|
1140 |
+
}
|
1141 |
+
//else do noting
|
1142 |
+
end
|
1143 |
+
|
1144 |
+
prog CheckScalarOpt
|
1145 |
+
capt syntax [anything]
|
1146 |
+
if _rc error 198
|
1147 |
+
end
|
1148 |
+
|
1149 |
+
prog MakeTeXColspec
|
1150 |
+
args wide not star detach aux
|
1151 |
+
if "`star'"!="" & "`detach'"!="" & "`aux'"=="" local value "r@{}l"
|
1152 |
+
else local value "c"
|
1153 |
+
if "`wide'"!="" & "`not'"=="" {
|
1154 |
+
if "`star'"!="" & "`detach'"!="" & "`aux'"!="" local value "`value'r@{}l"
|
1155 |
+
else local value "`value'c"
|
1156 |
+
}
|
1157 |
+
c_local value "`value'"
|
1158 |
+
end
|
1159 |
+
|
1160 |
+
prog MakeTeXColspecAlt
|
1161 |
+
syntax, cells(string asis)
|
1162 |
+
local count 1
|
1163 |
+
while `count' {
|
1164 |
+
local cells: subinstr local cells " (" "(", all count(local count)
|
1165 |
+
}
|
1166 |
+
local count 1
|
1167 |
+
while `"`macval(cells)'"'!="" {
|
1168 |
+
gettoken row cells : cells, bind
|
1169 |
+
local size 0
|
1170 |
+
gettoken chunk row : row, bind
|
1171 |
+
while `"`macval(chunk)'"'!="" {
|
1172 |
+
local ++size
|
1173 |
+
gettoken chunk row : row, bind
|
1174 |
+
}
|
1175 |
+
local count = max(`count',`size')
|
1176 |
+
}
|
1177 |
+
c_local value: di _dup(`count') "c"
|
1178 |
+
end
|
1179 |
+
|
1180 |
+
prog SaveRetok
|
1181 |
+
gettoken chunk 0: 0, q
|
1182 |
+
local value `"`macval(chunk)'"'
|
1183 |
+
gettoken chunk 0: 0, q
|
1184 |
+
while `"`macval(chunk)'"'!="" {
|
1185 |
+
local value `"`macval(value)' `macval(chunk)'"'
|
1186 |
+
gettoken chunk 0: 0, q
|
1187 |
+
}
|
1188 |
+
c_local value `"`macval(value)'"'
|
1189 |
+
end
|
1190 |
+
|
1191 |
+
prog CleanEstoutCmd
|
1192 |
+
syntax [anything] [using] [ , * ]
|
1193 |
+
local cmd estout
|
1194 |
+
if `"`macval(anything)'"'!="" {
|
1195 |
+
local cmd `"`macval(cmd)' `macval(anything)'"'
|
1196 |
+
}
|
1197 |
+
if `"`macval(using)'"'!="" {
|
1198 |
+
local cmd `"`macval(cmd)' `macval(using)'"'
|
1199 |
+
}
|
1200 |
+
if `"`macval(options)'"'!="" {
|
1201 |
+
local cmd `"`macval(cmd)', `macval(options)'"'
|
1202 |
+
}
|
1203 |
+
c_local cmd `"`macval(cmd)'"'
|
1204 |
+
end
|
1205 |
+
|
1206 |
+
prog ParseEqLabels
|
1207 |
+
syntax [anything] [, Begin(passthru) NOReplace Replace NOFirst First * ]
|
1208 |
+
c_local eqlabelsok = `"`begin'`noreplace'`replace'`nofirst'`first'"'==""
|
1209 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/e/esttab.hlp
ADDED
@@ -0,0 +1,918 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 02jun2014}{...}
|
3 |
+
{hi:help esttab}{right:also see: {helpb estout}, {helpb eststo}, {helpb estadd}, {helpb estpost}}
|
4 |
+
{right: {browse "http://repec.org/bocode/e/estout"}}
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{p 4 4 2}{hi:esttab} {hline 2} Display formatted regression table
|
10 |
+
|
11 |
+
|
12 |
+
{title:Table of contents}
|
13 |
+
|
14 |
+
{help esttab##syn:Syntax}
|
15 |
+
{help esttab##des:Description}
|
16 |
+
{help esttab##opt:Options}
|
17 |
+
{help esttab##exa:Examples}
|
18 |
+
{help esttab##aut:Backmatter}
|
19 |
+
|
20 |
+
{marker syn}
|
21 |
+
{title:Syntax}
|
22 |
+
|
23 |
+
{p 8 15 2}
|
24 |
+
{cmd:esttab} [ {it:namelist} ] [ {cmd:using} {it:filename} ] [ {cmd:,}
|
25 |
+
{it:options} ]
|
26 |
+
|
27 |
+
|
28 |
+
{p 4 4 2}where {it:namelist} is a name, a list of names, or {cmd:_all}. The
|
29 |
+
{cmd:*} and {cmd:?} wildcards are allowed in {it:namelist}. A name may also be {cmd:.},
|
30 |
+
meaning the current (active) estimates.
|
31 |
+
|
32 |
+
|
33 |
+
{it:options}{col 26}description
|
34 |
+
{hline 70}
|
35 |
+
{help esttab##main:Main}
|
36 |
+
{cmd:b(}{it:{help esttab##fmt:fmt}}{cmd:)}{col 26}{...}
|
37 |
+
specify format for point estimates
|
38 |
+
{cmd:beta}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
39 |
+
display beta coefficients instead of point est's
|
40 |
+
{cmd:main(}{it:name} [{it:{help esttab##fmt:fmt}}]{cmd:)}{col 26}{...}
|
41 |
+
display contents of {cmd:e(}{it:name}{cmd:)} instead of point e's
|
42 |
+
{cmd:t(}{it:{help esttab##fmt:fmt}}{cmd:)}{col 26}{...}
|
43 |
+
specify format for t-statistics
|
44 |
+
{cmd:abs}{col 26}{...}
|
45 |
+
use absolute value of t-statistics
|
46 |
+
{cmd:not}{col 26}{...}
|
47 |
+
suppress t-statistics
|
48 |
+
{cmd:z}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
49 |
+
display z-statistics (affects label only)
|
50 |
+
{cmd:se}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
51 |
+
display standard errors instead of t-statistics
|
52 |
+
{cmd:p}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
53 |
+
display p-values instead of t-statistics
|
54 |
+
{cmd:ci}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
55 |
+
display confidence intervals instead of t-stat's
|
56 |
+
{cmd:aux(}{it:name} [{it:{help esttab##fmt:fmt}}]{cmd:)}{col 26}{...}
|
57 |
+
display contents of {cmd:e(}{it:name}{cmd:)} instead of t-stat's
|
58 |
+
[{ul:{cmd:no}}]{cmdab:con:stant}{col 26}{...}
|
59 |
+
do not/do report the intercept
|
60 |
+
|
61 |
+
{help esttab##stars:Significance stars}
|
62 |
+
[{cmd:no}]{cmd:star}[{cmd:(}{it:list}{cmd:)}]{col 26}{...}
|
63 |
+
do not/do report significance stars
|
64 |
+
{cmd:staraux}{col 26}{...}
|
65 |
+
attach stars to t-stat's instead of point est's
|
66 |
+
|
67 |
+
{help esttab##stat:Summary statistics}
|
68 |
+
{cmd:r2}|{cmd:ar2}|{cmd:pr2}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
69 |
+
display (adjusted, pseudo) R-squared
|
70 |
+
{cmd:aic}|{cmd:bic}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]{col 26}{...}
|
71 |
+
display Akaike's or Schwarz's information crit.
|
72 |
+
{cmdab:sca:lars:(}{it:list}{cmd:)}{col 26}{...}
|
73 |
+
display any other scalars contained in {cmd:e()}
|
74 |
+
{cmd:sfmt(}{it:{help esttab##fmt:fmt}} [{it:...}]{cmd:)}{col 26}{...}
|
75 |
+
set format(s) for {cmd:scalars()}
|
76 |
+
{cmd:noobs}{col 26}{...}
|
77 |
+
do not display the number of observations
|
78 |
+
{cmd:obslast}{col 26}{...}
|
79 |
+
place the number of observations last
|
80 |
+
|
81 |
+
{help esttab##layout:Layout}
|
82 |
+
{cmd:wide}{col 26}{...}
|
83 |
+
place point est's and t-stat's beside one another
|
84 |
+
{cmdab:one:cell}{col 26}{...}
|
85 |
+
combine point est's and t-stat's in a single cell
|
86 |
+
[{ul:{cmd:no}}]{cmdab:pa:rentheses}{col 26}{...}
|
87 |
+
do not/do print parentheses around t-statistics
|
88 |
+
{cmdab:br:ackets}{col 26}{...}
|
89 |
+
use brackets instead of parentheses
|
90 |
+
[{ul:{cmd:no}}]{cmdab:gap:s}{col 26}{...}
|
91 |
+
suppress/add vertical spacing
|
92 |
+
[{ul:{cmd:no}}]{cmdab:li:nes}{col 26}{...}
|
93 |
+
suppress/add horizontal lines
|
94 |
+
{cmdab:noeqli:nes}{col 26}{...}
|
95 |
+
suppress lines between equations
|
96 |
+
{cmd:compress}{col 26}{...}
|
97 |
+
reduce horizontal spacing
|
98 |
+
{cmd:plain}{col 26}{...}
|
99 |
+
produce a minimally formatted table
|
100 |
+
|
101 |
+
{help esttab##label:Labeling}
|
102 |
+
{cmdab:l:abel}{col 26}{...}
|
103 |
+
make use of variable labels
|
104 |
+
{cmdab:interact:ion:(}{it:str}{cmd:)}{col 26}{...}
|
105 |
+
specify interaction operator
|
106 |
+
{cmdab:ti:tle:(}{it:string}{cmd:)}{col 26}{...}
|
107 |
+
specify a title for the table
|
108 |
+
{cmdab:mti:tles}[{cmd:(}{it:list}{cmd:)}]{col 26}{...}
|
109 |
+
specify model titles to appear in table header
|
110 |
+
{cmdab:nomti:tles}{col 26}{...}
|
111 |
+
disable model titles
|
112 |
+
[{ul:{cmd:no}}]{cmdab:dep:vars}{col 26}{...}
|
113 |
+
do not/do use dependent variables as model titles
|
114 |
+
[{ul:{cmd:no}}]{cmdab:num:bers}{col 26}{...}
|
115 |
+
do not/do print model numbers in table header
|
116 |
+
{cmdab:coef:labels:(}{it:list}{cmd:)}{col 26}{...}
|
117 |
+
specify labels for coefficients
|
118 |
+
[{ul:{cmd:no}}]{cmdab:note:s}{col 26}{...}
|
119 |
+
suppress/add notes in the table footer
|
120 |
+
{cmdab:addn:otes:(}{it:list}{cmd:)}{col 26}{...}
|
121 |
+
add lines at the end of the table
|
122 |
+
|
123 |
+
{help esttab##format:Document format}
|
124 |
+
{cmd:smcl} | {cmdab:fix:ed} | {cmd:tab} | {cmd:csv} | {cmdab:sc:sv} | {cmd:rtf} | {cmdab:htm:l} | {cmd:tex} | {cmdab:bookt:abs}
|
125 |
+
{col 26}{...}
|
126 |
+
set the document format ({cmd:smcl} is the default)
|
127 |
+
{cmdab:f:ragment}{col 26}{...}
|
128 |
+
suppress table opening and closing (LaTeX, HTML)
|
129 |
+
{cmd:page}[{cmd:(}{it:packages}{cmd:)}]{col 26}{...}
|
130 |
+
add page opening and closing (LaTeX, HTML)
|
131 |
+
{cmdab:align:ment(}{it:string}{cmd:)}{col 26}{...}
|
132 |
+
set alignment within columns (LaTeX, HTML, RTF)
|
133 |
+
{cmdab:width(}{it:string}{cmd:)}{col 26}{...}
|
134 |
+
set width of table (LaTeX, HTML)
|
135 |
+
{cmdab:long:table}{col 26}{...}
|
136 |
+
multi-page table (LaTeX)
|
137 |
+
|
138 |
+
{help esttab##output:Output}
|
139 |
+
{cmdab:r:eplace}{col 26}{...}
|
140 |
+
overwrite an existing file
|
141 |
+
{cmdab:a:ppend}{col 26}{...}
|
142 |
+
append the output to an existing file
|
143 |
+
{cmdab:ty:pe}{col 26}{...}
|
144 |
+
force prining the table in the results window
|
145 |
+
{cmdab:n:oisily}{col 26}{...}
|
146 |
+
display the executed {helpb estout} command
|
147 |
+
|
148 |
+
{help esttab##advanced:Advanced}
|
149 |
+
{cmdab:d:rop:(}{it:list}{cmd:)}{col 26}{...}
|
150 |
+
drop individual coefficients
|
151 |
+
{cmdab:noomit:ted}{col 26}{...}
|
152 |
+
drop omitted coefficients
|
153 |
+
{cmdab:nobase:levels}{col 26}{...}
|
154 |
+
drop base levels of factor variables
|
155 |
+
{cmdab:k:eep:(}{it:list}{cmd:)}{col 26}{...}
|
156 |
+
keep individual coefficients
|
157 |
+
{cmdab:o:rder:(}{it:list}{cmd:)}{col 26}{...}
|
158 |
+
change order of coefficients
|
159 |
+
{cmdab:eq:uations:(}{it:list}{cmd:)}{col 26}{...}
|
160 |
+
match the models' equations
|
161 |
+
{cmd:eform}{col 26}{...}
|
162 |
+
report exponentiated coefficients
|
163 |
+
{cmdab:uns:tack}{col 26}{...}
|
164 |
+
place multiple equations in separate columns
|
165 |
+
{it:estout_options}{col 26}{...}
|
166 |
+
any other {helpb estout} options
|
167 |
+
{hline 70}
|
168 |
+
|
169 |
+
{marker des}
|
170 |
+
{title:Description}
|
171 |
+
|
172 |
+
{p 4 4 2}
|
173 |
+
{cmd:esttab} is a wrapper for {helpb estout}. It produces a
|
174 |
+
pretty-looking publication-style regression table from stored
|
175 |
+
estimates without much typing. The compiled table is displayed in the
|
176 |
+
Stata results window or, optionally, written to a text file specified
|
177 |
+
by {cmd:using} {it:filename}. If {it:filename} is specified without
|
178 |
+
suffix, a default suffix is added depending on the specified document
|
179 |
+
format (".smcl" for {cmd:smcl}, ".txt" for {cmd:fixed} and {cmd:tab}, ".csv" for {cmd:csv}
|
180 |
+
and {cmd:scsv}, ".rtf" for {cmd:rft}, ".html" for {cmd:html}, and
|
181 |
+
".tex" for {cmd:tex} and {cmd:booktabs}).
|
182 |
+
|
183 |
+
{p 4 4 2}
|
184 |
+
{it:namelist} provides the names of the stored estimation sets to be
|
185 |
+
tabulated. You may use the {cmd:*} and {cmd:?} wildcards in
|
186 |
+
{it:namelist}. If {it:namelist} is omitted, {cmd:esttab} tabulates the
|
187 |
+
estimation sets stored by {cmd:eststo} (see help {helpb eststo})
|
188 |
+
or, if no such estimates are present, the currently active
|
189 |
+
estimates (i.e. the model fit last).
|
190 |
+
|
191 |
+
{p 4 4 2}
|
192 |
+
See help {helpb estimates} for information about storing estimation
|
193 |
+
results. An alternative to the {cmd:estimates store} command is
|
194 |
+
provided by {helpb eststo}.
|
195 |
+
|
196 |
+
{p 4 4 2}
|
197 |
+
{cmd:esttab} can also be used to tabulate a Stata matrix applying syntax
|
198 |
+
{bind:{cmd:esttab} {cmdab:m:atrix:(}{it:name}{cmd:)}}, where {it:name}
|
199 |
+
is the name of the matrix. Furthermore, an {cmd:e()}-matrix or {cmd:r()}-matrix
|
200 |
+
can be tabulated specifying {cmd:esttab e(}{it:name}{cmd:)} or
|
201 |
+
{cmd:esttab r(}{it:name}{cmd:)}. Most options under the headings
|
202 |
+
'Main', 'Significance stars', and 'Summary statistics' are irrelevant
|
203 |
+
in this case. See help {helpb estout} for further details on tabulating matrices.
|
204 |
+
|
205 |
+
{marker opt}
|
206 |
+
{title:Options}
|
207 |
+
{marker main}
|
208 |
+
{dlgtab:Main}
|
209 |
+
|
210 |
+
{p 4 8 2}
|
211 |
+
{cmd:b(}{it:{help esttab##fmt:fmt}}{cmd:)} sets the numerical display format
|
212 |
+
for the point estimates. The default format is {cmd:a3}. (See
|
213 |
+
{help esttab##fmt:Numerical formats} below for details on available
|
214 |
+
formats.)
|
215 |
+
|
216 |
+
{p 4 8 2}
|
217 |
+
{cmd:beta}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] requests that
|
218 |
+
standardized beta coefficients be displayed in place of the raw point
|
219 |
+
estimates and, optionally, sets the display format (the default is to
|
220 |
+
print three decimal places). Note that {cmd:beta} causes the
|
221 |
+
intercept to be dropped from the table (unless {cmd:constant} is
|
222 |
+
specified).{p_end}
|
223 |
+
{marker main}
|
224 |
+
{p 4 8 2}
|
225 |
+
{cmd:main(}{it:name} [{it:{help esttab##fmt:fmt}}]{cmd:)} requests that
|
226 |
+
the statistics stored in {cmd:e(}{it:name}{cmd:)} be displayed in
|
227 |
+
place of the point estimates and, optionally, sets the display format
|
228 |
+
(the default is to use the display format for point estimates). For
|
229 |
+
example, {cmd:e(}{it:name}{cmd:)} may contain statistics added by
|
230 |
+
{cmd:estadd} (see help {helpb estadd}).
|
231 |
+
|
232 |
+
{p 4 8 2}
|
233 |
+
{cmd:t(}{it:{help esttab##fmt:fmt}}{cmd:)} sets the display format for
|
234 |
+
t-statistics. The default is to display two decimal places.
|
235 |
+
|
236 |
+
{p 4 8 2}
|
237 |
+
{cmd:abs} causes absolute values of t-statistics to be reported.
|
238 |
+
|
239 |
+
{p 4 8 2}
|
240 |
+
{cmd:not} suppresses the printing of t-statistics.
|
241 |
+
|
242 |
+
{p 4 8 2}
|
243 |
+
{cmd:z}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] requests that
|
244 |
+
z-statistics be displayed. z-statistics are the same as t-statistics. Hence,
|
245 |
+
specifying {cmd:z} does not change the table contents, it only changes the
|
246 |
+
label.
|
247 |
+
|
248 |
+
{p 4 8 2}
|
249 |
+
{cmd:se}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] requests that
|
250 |
+
standard errors be displayed in place of t-statistics and,
|
251 |
+
optionally, sets the display format (the default is to use the
|
252 |
+
display format for point estimates).
|
253 |
+
|
254 |
+
{p 4 8 2}
|
255 |
+
{cmd:p}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] requests that
|
256 |
+
p-values be displayed in place of t-statistics and, optionally, sets
|
257 |
+
the display format (the default is to print three decimal places)
|
258 |
+
|
259 |
+
{p 4 8 2}
|
260 |
+
{cmd:ci}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] requests that
|
261 |
+
confidence intervals be displayed in place of t-statistics and,
|
262 |
+
optionally, sets the display format (the default is to use the
|
263 |
+
display format for point estimates). {cmd:level(}{it:#}{cmd:)}
|
264 |
+
assigns the confidence level, in percent. The default is
|
265 |
+
{cmd:level(95)} or as set by {helpb set level}.{p_end}
|
266 |
+
{marker aux}
|
267 |
+
{p 4 8 2}
|
268 |
+
{cmd:aux(}{it:name} [{it:{help esttab##fmt:fmt}}]{cmd:)} requests that
|
269 |
+
the statistics stored in {cmd:e(}{it:name}{cmd:)} be displayed in
|
270 |
+
place of t-statistics and, optionally, sets the display format (the
|
271 |
+
default is to use the display format for point estimates). For
|
272 |
+
example, {cmd:e(}{it:name}{cmd:)} may contain statistics added by
|
273 |
+
{cmd:estadd} (see help {helpb estadd}, if installed).
|
274 |
+
|
275 |
+
{p 4 8 2}
|
276 |
+
{cmd:noconstant} causes the intercept be dropped from the table.
|
277 |
+
Specify {cmd:constant} to include the constant in situations where it
|
278 |
+
is dropped by default.
|
279 |
+
|
280 |
+
{marker stars}
|
281 |
+
{dlgtab:Significance stars}
|
282 |
+
|
283 |
+
{p 4 8 2}
|
284 |
+
{cmd:star}[{cmd:(}{it:symbol} {it:level} [{it:...}]{cmd:)}] causes
|
285 |
+
stars denoting the significance of the coefficients to be printed
|
286 |
+
next to the point estimates. This is the default. Type {cmd:nostar}
|
287 |
+
to suppress the stars. The default symbols and thresholds are:
|
288 |
+
{cmd:*} for p<.05, {cmd:**} for p<.01, and {cmd:***} for p<.001.
|
289 |
+
Alternatively, for example, type {bind:{cmd:star(+ 0.10 * 0.05)}} to
|
290 |
+
set the following thresholds: {cmd:+} for p<.10 and {cmd:*} for
|
291 |
+
p<.05. Note that the thresholds must lie in the (0,1] interval and
|
292 |
+
must be specified in descending order.
|
293 |
+
|
294 |
+
{p 4 8 2}
|
295 |
+
{cmd:staraux} causes the significance stars be printed next to the
|
296 |
+
t-statistics (or standard errors, etc.) instead of the point estimates.
|
297 |
+
|
298 |
+
{marker stat}
|
299 |
+
{dlgtab:Summary statistics}
|
300 |
+
|
301 |
+
{p 4 8 2}
|
302 |
+
{cmd:r2}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}],
|
303 |
+
{cmd:ar2}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}], and
|
304 |
+
{cmd:pr2}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]
|
305 |
+
include the R-squared, the adjusted R-squared, and the
|
306 |
+
pseudo-R-squared in the table footer and, optionally, set the
|
307 |
+
corresponding display formats (the default is to display three
|
308 |
+
decimal places).
|
309 |
+
|
310 |
+
{p 4 8 2}
|
311 |
+
{cmd:aic}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}] and
|
312 |
+
{cmd:bic}[{cmd:(}{it:{help esttab##fmt:fmt}}{cmd:)}]
|
313 |
+
include Akaike's and Schwarz's information criterion in the table
|
314 |
+
footer and, optionally, set the corresponding display formats (the
|
315 |
+
default is to use the display format for point estimates).{p_end}
|
316 |
+
{marker scalars}
|
317 |
+
{p 4 8 2}
|
318 |
+
{cmd:scalars(}{it:list}{cmd:)} may be used to add other
|
319 |
+
{cmd:e()}-scalars to the table footer (type {cmd:ereturn list} to
|
320 |
+
display a list of available {cmd:e()}-scalars after fitting a model;
|
321 |
+
see help {helpb ereturn}). For example, {cmd:scalars(df_m)} would
|
322 |
+
report the model degrees of freedom for each model. {it:list} may be
|
323 |
+
a simple list of names of {cmd:e()}-scalars, e.g.
|
324 |
+
|
325 |
+
{com}. esttab, scalars(ll_0 ll chi2){txt}
|
326 |
+
|
327 |
+
{p 8 8 2}
|
328 |
+
or, alternatively, a list of quoted name-label pairs, e.g.
|
329 |
+
|
330 |
+
{com}. esttab, scalars({bind:"ll Log lik."} {bind:"chi2 Chi-squared"}){txt}
|
331 |
+
|
332 |
+
{p 4 8 2}
|
333 |
+
{cmd:sfmt(}{it:{help esttab##fmt:fmt}} [{it:...}]{cmd:)} sets the
|
334 |
+
display format(s) for the statistics specified in {cmd:scalars()}
|
335 |
+
(the default is to use the display format for point estimates). If
|
336 |
+
{cmd:sfmt()} contains less elements than {cmd:scalars()}, the last
|
337 |
+
specified format is used for the remaining scalars. That is, only one
|
338 |
+
format needs to be specified if the same format be used for all
|
339 |
+
scalars.
|
340 |
+
|
341 |
+
{p 4 8 2}
|
342 |
+
{cmd:noobs} suppresses displaying information on the number of
|
343 |
+
observations. The default is to report the number of observations for
|
344 |
+
each model in the table footer.
|
345 |
+
|
346 |
+
{p 4 8 2}
|
347 |
+
{cmd:obslast} displays the number of observations in the last row of
|
348 |
+
the table footer. The default is to use the first row.
|
349 |
+
|
350 |
+
{marker layout}
|
351 |
+
{dlgtab:Layout}
|
352 |
+
{marker wide}
|
353 |
+
{p 4 8 2}
|
354 |
+
{cmd:wide} causes point estimates and t-statistics (or standard errors,
|
355 |
+
etc.) to be printed beside one another instead of beneath one another.
|
356 |
+
{p_end}
|
357 |
+
{marker onecell}
|
358 |
+
{p 4 8 2}
|
359 |
+
{cmd:onecell} causes point estimates and t-statistics (or standard errors,
|
360 |
+
etc.) to be combined in a single table cell. This option is useful primarily
|
361 |
+
in {cmd:rtf} or {cmd:html} mode. In these modes a line break is
|
362 |
+
inserted between the two statistics. The benefit from using {cmd:onecell}
|
363 |
+
in {cmd:rtf} or {cmd:html} mode is that long coefficients labels do not
|
364 |
+
derange the table layout. The default for other modes is to insert
|
365 |
+
a blank between the statistics. Use {cmd:estout}'s
|
366 |
+
{helpb estout##incelldel:incelldelimiter()} option to change this.
|
367 |
+
|
368 |
+
{p 4 8 2}
|
369 |
+
{cmd:parentheses} encloses t-statistics (or standard errors, etc.) in
|
370 |
+
parentheses. This is the default. Specify {cmd:noparentheses} to
|
371 |
+
suppress the parentheses.
|
372 |
+
|
373 |
+
{p 4 8 2}
|
374 |
+
{cmd:brackets} uses square brackets, [], instead of parentheses. Note
|
375 |
+
that brackets are the default for confidence intervals.
|
376 |
+
|
377 |
+
{p 4 8 2}
|
378 |
+
{cmd:gaps} adds empty rows (or, more generally, additional vertical
|
379 |
+
space) between coefficients to increase readability (empty rows are
|
380 |
+
also inserted between the table's header, body, and footer, unless
|
381 |
+
{cmd:lines} is activated). This is the default unless {cmd:wide} or
|
382 |
+
{cmd:not} is specified. Type {cmd:nogaps} to suppress the extra
|
383 |
+
spacing.
|
384 |
+
|
385 |
+
{p 4 8 2}
|
386 |
+
{cmd:lines} adds horizontal lines to the table separating the table's
|
387 |
+
header, body, and footer and, in the case of multiple
|
388 |
+
equation models, the equations. This is the default. Specify {cmd:nolines}
|
389 |
+
to suppress the lines. Lines are always suppressed in the {cmd:tab}
|
390 |
+
and {cmd:csv} modes.
|
391 |
+
|
392 |
+
{p 4 8 2}
|
393 |
+
{cmd:noeqlines} suppresses the horizontal lines between equations
|
394 |
+
in the case of multiple equation models.{p_end}
|
395 |
+
{marker compress}
|
396 |
+
{p 4 8 2}
|
397 |
+
{cmd:compress} reduces the amount of horizontal spacing (so that more
|
398 |
+
models fit on screen without line breaking). The option has no effect
|
399 |
+
in the {cmd:tab} and {cmd:csv} modes. Furthermore, note that in the
|
400 |
+
TeX and HTML modes the {cmd:compress} option only changes the
|
401 |
+
arrangement the table's code, but not the look of the compiled
|
402 |
+
end-product. In {cmd:rtf}, however, {cmd:compress} changes the look
|
403 |
+
of the formatted table.{p_end}
|
404 |
+
{marker plain}
|
405 |
+
{p 4 8 2}
|
406 |
+
{cmd:plain} produces a minimally formatted table. It is a shorthand
|
407 |
+
to specifying {cmd:nostar}, {cmd:nodepvars}, {cmd:nonumbers},
|
408 |
+
{cmd:noparentheses}, {cmd:nogaps}, {cmd:nolines} and {cmd:nonotes}
|
409 |
+
and setting all formats to {cmd:%9.0g}. Note that the disabled
|
410 |
+
options can be switched on again. For example, type
|
411 |
+
|
412 |
+
{com}. esttab, plain star{txt}
|
413 |
+
|
414 |
+
{p 8 8 2}
|
415 |
+
to produce a plain table including significance stars.
|
416 |
+
|
417 |
+
{marker label}
|
418 |
+
{dlgtab:Labeling}
|
419 |
+
|
420 |
+
{p 4 8 2}
|
421 |
+
{cmd:label} specifies that variable labels be used instead of
|
422 |
+
variable names (and estimation set titles be used instead of
|
423 |
+
estimation set names). Furthermore, {cmd:label} prints "Constant"
|
424 |
+
instead of "_cons".
|
425 |
+
|
426 |
+
{p 4 8 2}
|
427 |
+
{cmd:interaction(}{it:string}{cmd:)} specifies the string to be used
|
428 |
+
as delimiter for interaction terms (only relevant in Stata 11 or newer). The
|
429 |
+
default is {cmd:interaction(" # ")}. For {cmd:tex} and {cmd:booktabs} the
|
430 |
+
default is {cmd:interaction(" $\times$ ")}.
|
431 |
+
{p_end}
|
432 |
+
{marker title}
|
433 |
+
{p 4 8 2}
|
434 |
+
{cmd:title(}{it:string}{cmd:)} may be used to provide a title for the
|
435 |
+
table. If specified, {it:string} is printed at the top of the table.
|
436 |
+
Note that specifying a title causes the table to be set up as a
|
437 |
+
floating object in LaTeX mode. You may want to set a label for
|
438 |
+
referencing in this case. For example, if you type
|
439 |
+
{cmd:title(...\label{tab1})}, then "\ref{tab1}" could be used in the
|
440 |
+
LaTeX document to point to the table.
|
441 |
+
|
442 |
+
{p 4 8 2}
|
443 |
+
{cmd:mtitles}, without argument, specifies that for each model the title
|
444 |
+
(or, if empty, the name) of the stored estimation set be printed as the model's
|
445 |
+
title in the table header. If {cmd:mtitles} is omitted, the default is to
|
446 |
+
use name or label of the dependent variable as the model's title (see the
|
447 |
+
{cmd:depvar} option). Alternatively, use {cmd:mtitles(}{it:list}{cmd:)}
|
448 |
+
specifies a list of model titles. Enclose the titles
|
449 |
+
in double quotes if they contain spaces,
|
450 |
+
e.g. {bind:{cmd:mtitles("Model 1" "Model 2")}}.
|
451 |
+
|
452 |
+
{p 4 8 2}
|
453 |
+
{cmd:nomtitles} suppresses printing of model titles.
|
454 |
+
|
455 |
+
{p 4 8 2}
|
456 |
+
{cmd:depvars} prints the name (or label) of the (first) dependent
|
457 |
+
variable of a model as the model's title in the table header. This is
|
458 |
+
the default. Specify {cmd:nodepvars} to use the names of
|
459 |
+
the stored estimation sets as titles.
|
460 |
+
|
461 |
+
{p 4 8 2}
|
462 |
+
{cmd:numbers} includes a row containing consecutive model numbers in
|
463 |
+
the table header. This is the default. Specify {cmd:nonumbers} to
|
464 |
+
suppress printing the model numbers.
|
465 |
+
|
466 |
+
{p 4 8 2}
|
467 |
+
{cmd:coeflabels(}{it:name} {it:label} [...]{cmd:)} specifies labels
|
468 |
+
for the coefficients. Specify names and labels in pairs and, if
|
469 |
+
necessary, enclose labels in double quotes,
|
470 |
+
e.g. {cmd:coeflabels(mpg Milage rep78 {bind:"Repair Record"})}.
|
471 |
+
|
472 |
+
{p 4 8 2}
|
473 |
+
{cmd:notes} prints notes at the end of the table explaining the
|
474 |
+
significance symbols and the type of displayed statistics. This is
|
475 |
+
the default. Specify {cmd:nonotes} to suppress the notes.
|
476 |
+
|
477 |
+
{p 4 8 2}
|
478 |
+
{cmd:addnotes(}{it:list}{cmd:)} may be used to add further lines of
|
479 |
+
text at the bottom of the table. Lines containing blanks must be
|
480 |
+
enclosed in double quotes,
|
481 |
+
e.g. {cmd:addnotes({bind:"Line 1"} {bind:"Line 2"})}.
|
482 |
+
|
483 |
+
{marker format}
|
484 |
+
{dlgtab:Document format}
|
485 |
+
|
486 |
+
{p 4 8 2}
|
487 |
+
{cmd:smcl}, {cmd:fixed}, {cmd:tab}, {cmd:csv}, {cmd:scsv}, {cmd:rtf},
|
488 |
+
{cmd:html}, {cmd:tex}, and {cmd:booktabs} choose the table's basic
|
489 |
+
output format. The default format is {cmd:smcl} unless
|
490 |
+
{cmd:using} is specified, in which case the default format
|
491 |
+
depends on the filename's suffix ({cmd:smcl} for ".smcl", {cmd:csv}
|
492 |
+
for ".csv", {cmd:rtf} for ".rtf",
|
493 |
+
{cmd:html} for ".htm" or ".html", {cmd:tex} for ".tex", and {cmd:fixed}
|
494 |
+
for all other filenames). To override the default behavior, specify one of the
|
495 |
+
following format options.
|
496 |
+
|
497 |
+
{p 8 8 2}
|
498 |
+
{cmd:smcl} produces a {help SMCL} formatted table to be displayed in the
|
499 |
+
Stata results window or the Stata viewer.
|
500 |
+
|
501 |
+
{p 8 8 2}
|
502 |
+
{cmd:fixed} produces a fixed-format ASCII table. This is suitable,
|
503 |
+
for example, if the table be displayed in a text editor.
|
504 |
+
|
505 |
+
{p 8 8 2}
|
506 |
+
{cmd:tab} produces a tab-delimited ASCII table.
|
507 |
+
{p_end}
|
508 |
+
{marker csv}
|
509 |
+
{p 8 8 2}
|
510 |
+
{cmd:csv} produces a CSV ({ul:C}omma {ul:S}eparated {ul:V}alue
|
511 |
+
format) table for use with Microsoft Excel. Delimiter is a comma. In
|
512 |
+
order to prevent Excel from interpreting the contents of the table
|
513 |
+
cells, they are enclosed double quotes preceded by an equal sign
|
514 |
+
(i.e. ="..."). However, if the {cmd:plain} option is specified, the
|
515 |
+
table cells are enclosed in double quotes without the leading equal
|
516 |
+
sign. The first method is appropriate if you want to preserve the
|
517 |
+
table's formatting. The second method is appropriate if you want to
|
518 |
+
use the table's contents for further computations in Excel.
|
519 |
+
{p_end}
|
520 |
+
{marker scsv}
|
521 |
+
{p 8 8 2}
|
522 |
+
{cmd:scsv} is a variant on the CSV format that uses a semicolon as
|
523 |
+
the delimiter. This is appropriate for some non-English versions of
|
524 |
+
Excel (e.g. the German version).
|
525 |
+
{p_end}
|
526 |
+
{marker rtf}
|
527 |
+
{p 8 8 2}
|
528 |
+
{cmd:rtf} produces a Rich Text Format table for use with word
|
529 |
+
processors.
|
530 |
+
|
531 |
+
{p 8 8 2}
|
532 |
+
{cmd:html} produces a simple HTML formatted table.
|
533 |
+
|
534 |
+
{p 8 8 2}
|
535 |
+
{cmd:tex} produces a LaTeX formatted table.
|
536 |
+
{p_end}
|
537 |
+
{marker booktabs}
|
538 |
+
{p 8 8 2}
|
539 |
+
{cmd:booktabs} produces a LaTeX formatted table for use with LaTeX's
|
540 |
+
{it:booktabs} package.
|
541 |
+
{p_end}
|
542 |
+
{marker fragment}
|
543 |
+
{p 4 8 2}
|
544 |
+
{cmd:fragment} causes the table's opening and closing specifications
|
545 |
+
to be suppressed. This is relevant primarily in LaTeX and HTML mode.
|
546 |
+
|
547 |
+
{p 4 8 2}
|
548 |
+
{cmd:page}[{cmd:(}{it:packages}{cmd:)}] adds opening and closing code
|
549 |
+
to define a whole LaTeX or HTML document. The default is to produce a
|
550 |
+
raw table that can then be included into an existing LaTeX or HTML
|
551 |
+
document. Specifying {it:packages} in parentheses causes
|
552 |
+
{cmd:\usepackage{c -(}}{it:packages}{cmd:{c )-}} to be added to the
|
553 |
+
preamble of the LaTeX document (note that the {it:booktabs} package
|
554 |
+
is automatically loaded if {cmd:booktabs} is specified).
|
555 |
+
|
556 |
+
{p 4 8 2}
|
557 |
+
{cmd:alignment(}{it:string}{cmd:)} may be used to specify the
|
558 |
+
alignment of the models' columns in LaTeX, HTML, or RTF mode.
|
559 |
+
|
560 |
+
{p 8 8 2}
|
561 |
+
In LaTeX mode {it:string} should be a LaTeX column specifier. The
|
562 |
+
default is to center the columns. To produce right-aligned columns,
|
563 |
+
for example, type {cmd:alignment(r)}. If the table contains multiple
|
564 |
+
columns per model/equation, the alignment specification should define
|
565 |
+
all columns. For example, if the {cmd:wide} option is specified, you
|
566 |
+
could type {cmd:alignment(cr)} to, say, center the point estimates
|
567 |
+
and right-align the t-statistics. Note that more sophisticated column
|
568 |
+
definitions are often needed to produce appealing results. In
|
569 |
+
particular, LaTeX's {it:dcolumn} package proves useful to align
|
570 |
+
columns on the decimal point.
|
571 |
+
|
572 |
+
{p 8 8 2}
|
573 |
+
In HTML mode {it:string} should be a HTML alignment specifier. The
|
574 |
+
default is to omit alignment specification, which results in left
|
575 |
+
aligned columns. To center the columns in HTML, for example, specify
|
576 |
+
{cmd:alignment(center)}. Other than in LaTeX mode, the same alignment
|
577 |
+
is used for all columns if the table contains multiple columns per
|
578 |
+
model/equation in the HTML mode.
|
579 |
+
|
580 |
+
{p 8 8 2}
|
581 |
+
In RTF mode {it:string} should be one of {cmd:l}, {cmd:c}, {cmd:r},
|
582 |
+
and {cmd:j}. The default is to center the columns. To produce
|
583 |
+
right-aligned columns, for example, type {cmd:alignment(r)}. The same
|
584 |
+
alignment is used for all columns if the table contains multiple
|
585 |
+
columns per model/equation in the RTF mode.
|
586 |
+
|
587 |
+
{p 8 8 2}
|
588 |
+
Note that {cmd:alignment()} does not change the alignment of the
|
589 |
+
variable names/labels in the left stub of the table. They are always
|
590 |
+
left-aligned.
|
591 |
+
|
592 |
+
{p 4 8 2}
|
593 |
+
{cmd:width(}{it:string}{cmd:)} sets the overall width of the table in
|
594 |
+
LaTeX or HTML. {it:string} should be LaTeX or HTML literal. For
|
595 |
+
example, specify {cmd:width(\hsize)} in LaTeX or {cmd:width(100%)} in
|
596 |
+
HTML to span the whole page. The table columns will spread regularly
|
597 |
+
over the specified width. Note that in RTF mode {helpb estout}'s
|
598 |
+
{cmd:varwidth()} and {cmd:modelwidth()} options may be used to change
|
599 |
+
the width of the table columns.
|
600 |
+
|
601 |
+
{p 4 8 2}
|
602 |
+
{cmdab:longtable} causes the {it:longtable} environment to be used in
|
603 |
+
LaTeX. Use {cmdab:longtable} for tables that are too
|
604 |
+
long to fit on a single page. {cmdab:longtable} cannot be combined
|
605 |
+
with {cmd:width()}. Make sure to load the {it:longtable} package
|
606 |
+
in the LaTeX document, i.e. include {cmd:\usepackage{longtable}} in the
|
607 |
+
document's preamble.
|
608 |
+
|
609 |
+
{marker output}
|
610 |
+
{dlgtab:Output}
|
611 |
+
|
612 |
+
{p 4 8 2}
|
613 |
+
{cmd:replace} permits {cmd:esttab} to overwrite an existing file.
|
614 |
+
|
615 |
+
{p 4 8 2}
|
616 |
+
{cmd:append} specifies that the output be appended to an existing
|
617 |
+
file. It may be used even if the file does not yet exist. Specifying
|
618 |
+
{cmd:append} together with {cmd:page} in TeX or HTML mode causes the
|
619 |
+
new table to be inserted at the end of the body of an existing
|
620 |
+
document ({cmd:esttab} seeks a line reading "\end{document}" or
|
621 |
+
"</body>", respectively, and starts appending from there;
|
622 |
+
contents after this line will be overwritten). In RTF mode, existing
|
623 |
+
documents are assumed to end with a line containing a single "}".
|
624 |
+
|
625 |
+
{p 4 8 2}
|
626 |
+
{cmd:type} specifies that the assembled table be printed in the
|
627 |
+
results window and the log file. This is the default unless
|
628 |
+
{cmd:using} is specified.
|
629 |
+
|
630 |
+
{p 4 8 2}
|
631 |
+
{cmd:noisily} displays the executed {helpb estout} command.
|
632 |
+
|
633 |
+
{marker advanced}
|
634 |
+
{dlgtab:Advanced}
|
635 |
+
|
636 |
+
{p 4 8 2}
|
637 |
+
{cmd:drop(}{it:droplist}{cmd:)} identifies the coefficients to be
|
638 |
+
dropped from the table. A {it:droplist} comprises one or more
|
639 |
+
specifications, separated by white space. A specification can be
|
640 |
+
either a parameter name (e.g. {cmd:price}), an equation name followed
|
641 |
+
by a colon (e.g. {cmd:mean:}), or a full name
|
642 |
+
(e.g. {cmd:mean:price}). You may use the {cmd:*} and {cmd:?} wildcards
|
643 |
+
in equation names and parameter names. Be sure to refer to the matched
|
644 |
+
equation names, and not to the original equation names in the models,
|
645 |
+
when using the {cmd:equations()} option to match equations.
|
646 |
+
|
647 |
+
{p 4 8 2}
|
648 |
+
{cmd:noomitted} drops omitted coefficients (only relevant in Stata 11 or
|
649 |
+
newer).
|
650 |
+
|
651 |
+
{p 4 8 2}
|
652 |
+
{cmd:nobaselevels} drops base levels of factor variables (only relevant
|
653 |
+
in Stata 11 or newer).
|
654 |
+
|
655 |
+
{p 4 8 2}
|
656 |
+
{cmd:keep(}{it:keeplist}{cmd:)} selects the coefficients to be
|
657 |
+
included in the table. {it:keeplist} is specified analogous to
|
658 |
+
{it:droplist} in {cmd:drop()} (see above).
|
659 |
+
|
660 |
+
{p 4 8 2}
|
661 |
+
{cmd:order(}{it:orderlist}{cmd:)} changes the order of the
|
662 |
+
coefficients and equations within the table. {it:orderlist} is
|
663 |
+
specified analogous to {it:droplist} in {cmd:drop()} (see above).
|
664 |
+
Coefficients and equations that do not appear in {it:orderlist} are
|
665 |
+
placed last (in their original order).
|
666 |
+
|
667 |
+
{p 4 8 2}
|
668 |
+
{cmd:equations(}{it:eqmatchlist}{cmd:)} specifies how the models'
|
669 |
+
equations are to be matched. This option is passed to the internal
|
670 |
+
call of {cmd:estimates table}. See help {helpb estimates} on how to
|
671 |
+
specify this option. The most common usage is {cmd:equations(1)} to
|
672 |
+
match all the first equations in the models.
|
673 |
+
|
674 |
+
{p 4 8 2}
|
675 |
+
{cmd:eform} displays the regression table in exponentiated form. The
|
676 |
+
exponent of a coefficient is displayed in lieu of the untransformed
|
677 |
+
coefficient; standard errors and confidence intervals are transformed
|
678 |
+
as well. Note that the intercept is dropped in eform-mode, unless
|
679 |
+
{cmd:constant} is specified.
|
680 |
+
|
681 |
+
{p 4 8 2}
|
682 |
+
{cmd:unstack} specifies that the individual equations from
|
683 |
+
multiple-equation models (e.g. {cmd:mlogit}, {cmd:reg3},
|
684 |
+
{cmd:heckman}) be placed in separate columns. The default is to place
|
685 |
+
the equations below one another in a single column.
|
686 |
+
|
687 |
+
{p 4 8 2}
|
688 |
+
{it:estout_options} are any other {cmd:estout} options (see help
|
689 |
+
{helpb estout}). Note that {cmd:estout} options take precedence over
|
690 |
+
{cmd:esttab} options. For example,
|
691 |
+
|
692 |
+
{p 8 20 2}
|
693 |
+
{cmd:cells()}{space 5}disables {cmd:b()}, {cmd:beta()}, {cmd:main()},
|
694 |
+
{cmd:t()}, {cmd:abs}, {cmd:not}, {cmd:se()}, {cmd:p()}, {cmd:ci()},
|
695 |
+
{cmd:aux()}, {cmd:star}, {cmd:staraux}, {cmd:wide}, {cmd:onecell},
|
696 |
+
{cmd:parentheses}, and {cmd:brackets},
|
697 |
+
|
698 |
+
{p 8 20 2}
|
699 |
+
{cmd:stats()}{space 5}disables {cmd:r2()}, {cmd:ar2()}, {cmd:pr2()},
|
700 |
+
{cmd:aic()}, {cmd:bic()}, {cmd:scalars()}, {cmd:sfmt()}, {cmd:noobs},
|
701 |
+
and {cmd:obslast}.
|
702 |
+
|
703 |
+
{p 8 8 2}
|
704 |
+
Other {cmd:estout} options that should be used with care are
|
705 |
+
{cmd:begin()}, {cmd:delimiter()}, {cmd:end()}, {cmd:prehead()},
|
706 |
+
{cmd:posthead()}, {cmd:prefoot()}, {cmd:postfoot()}, {cmd:mlabels()},
|
707 |
+
and {cmd:varlabels()}. Furthermore, note that {cmd:estout}'s {cmd:style()}
|
708 |
+
option does not have much effect because most options that would be affected
|
709 |
+
by {cmd:style()} are set explicitly by {cmd:esttab}.
|
710 |
+
|
711 |
+
{marker fmt}
|
712 |
+
{dlgtab:Numerical formats}
|
713 |
+
|
714 |
+
{p 4 4 2}
|
715 |
+
Numerical display formats may be specified in {cmd:esttab} as follows:
|
716 |
+
|
717 |
+
{p 5 8 2}
|
718 |
+
1. Official Stata's display formats: You may specify formats, such as
|
719 |
+
{cmd:%9.0g} or {cmd:%8.2f}. See help {help format} for a list
|
720 |
+
of available formats. {cmd:%g} or {cmd:g} may be used as a
|
721 |
+
synonym for {cmd:%9.0g}.
|
722 |
+
|
723 |
+
{p 5 8 2}
|
724 |
+
2. Fixed format: You may specify an integer value such as {cmd:0},
|
725 |
+
{cmd:1}, {cmd:2}, etc. to request a display format with a fixed number
|
726 |
+
of decimal places. For example, {cmd:t(3)} would display t-statistics
|
727 |
+
with three decimal places.
|
728 |
+
|
729 |
+
{p 5 8 2}
|
730 |
+
3. Automatic format: You may specify {cmd:a1}, {cmd:a2}, ..., or
|
731 |
+
{cmd:a9} to cause {cmd:esttab} to choose a reasonable display format for
|
732 |
+
each number depending on the number's value. {cmd:a} may be used as a
|
733 |
+
synonym for {cmd:a3}. The {it:#} in
|
734 |
+
{cmd:a}{it:#} determines the minimum precision according to the
|
735 |
+
following rules:
|
736 |
+
|
737 |
+
{p 10 12 2}
|
738 |
+
o Absolute numbers smaller than 1 are displayed with {it:#}
|
739 |
+
significant decimal places (i.e. with {it:#} decimal places ignoring
|
740 |
+
any leading zeros after the decimal point). For example,
|
741 |
+
{cmd:0.00123456} is displayed as {cmd:0.00123} if the format is
|
742 |
+
{cmd:a3}.
|
743 |
+
|
744 |
+
{p 10 12 2}
|
745 |
+
o Absolute numbers greater than 1 are displayed with as many digits
|
746 |
+
required to retain at least one decimal place and are displayed with
|
747 |
+
a minimum of ({it:#} + 1) digits. For example, if the format is
|
748 |
+
{cmd:a3}, {cmd:1.23456} is displayed as {cmd:1.235}, {cmd:12.3456} is
|
749 |
+
displayed as {cmd:12.35}, and {cmd:1234.56} is displayed as
|
750 |
+
{cmd:1234.6}.
|
751 |
+
|
752 |
+
{p 10 12 2}
|
753 |
+
o In any case, integers are displayed with zero decimal places, and
|
754 |
+
very large or very small absolute numbers are displayed in
|
755 |
+
exponential format.
|
756 |
+
|
757 |
+
{marker exa}
|
758 |
+
{title:Examples}
|
759 |
+
|
760 |
+
{p 4 4 2}
|
761 |
+
The following examples are intended to illustrate the basic usage of
|
762 |
+
{cmd:esttab}. Additional examples can be found at
|
763 |
+
{browse "http://repec.org/bocode/e/estout"}.
|
764 |
+
|
765 |
+
{p 4 4 2} The procedure is to first fit and store some models (see {helpb eststo}) and then apply
|
766 |
+
{cmd:esttab} to these stored estimates:
|
767 |
+
|
768 |
+
{com}. eststo clear
|
769 |
+
{txt}
|
770 |
+
{com}. sysuse auto
|
771 |
+
{txt}(1978 Automobile Data)
|
772 |
+
|
773 |
+
{com}. eststo: quietly regress price weight mpg
|
774 |
+
{txt}({res}est1{txt} stored)
|
775 |
+
|
776 |
+
{com}. eststo: quietly regress price weight mpg foreign
|
777 |
+
{txt}({res}est2{txt} stored)
|
778 |
+
|
779 |
+
{com}. esttab, ar2
|
780 |
+
{res}
|
781 |
+
{txt}{hline 44}
|
782 |
+
{txt} (1) (2)
|
783 |
+
{txt} price price
|
784 |
+
{txt}{hline 44}
|
785 |
+
{txt}weight {res} 1.747** 3.465***{txt}
|
786 |
+
{res} {ralign 12:{txt:(}2.72{txt:)}} {ralign 12:{txt:(}5.49{txt:)}} {txt}
|
787 |
+
|
788 |
+
{txt}mpg {res} -49.51 21.85 {txt}
|
789 |
+
{res} {ralign 12:{txt:(}-0.57{txt:)}} {ralign 12:{txt:(}0.29{txt:)}} {txt}
|
790 |
+
|
791 |
+
{txt}foreign {res} 3673.1***{txt}
|
792 |
+
{res} {ralign 12:{txt:(}5.37{txt:)}} {txt}
|
793 |
+
|
794 |
+
{txt}_cons {res} 1946.1 -5853.7 {txt}
|
795 |
+
{res} {ralign 12:{txt:(}0.54{txt:)}} {ralign 12:{txt:(}-1.73{txt:)}} {txt}
|
796 |
+
{txt}{hline 44}
|
797 |
+
{txt}N {res} 74 74 {txt}
|
798 |
+
{txt}adj. R-sq {res} 0.273 0.478 {txt}
|
799 |
+
{txt}{hline 44}
|
800 |
+
{txt}t statistics in parentheses
|
801 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
802 |
+
|
803 |
+
|
804 |
+
{p 4 4 2}
|
805 |
+
The same table using labels:
|
806 |
+
|
807 |
+
{com}. esttab, ar2 label
|
808 |
+
{res}
|
809 |
+
{txt}{hline 52}
|
810 |
+
{txt} (1) (2)
|
811 |
+
{txt} Price Price
|
812 |
+
{txt}{hline 52}
|
813 |
+
{txt}Weight (lbs.) {res} 1.747** 3.465***{txt}
|
814 |
+
{res} {ralign 12:{txt:(}2.72{txt:)}} {ralign 12:{txt:(}5.49{txt:)}} {txt}
|
815 |
+
|
816 |
+
{txt}Mileage (mpg) {res} -49.51 21.85 {txt}
|
817 |
+
{res} {ralign 12:{txt:(}-0.57{txt:)}} {ralign 12:{txt:(}0.29{txt:)}} {txt}
|
818 |
+
|
819 |
+
{txt}Car type {res} 3673.1***{txt}
|
820 |
+
{res} {ralign 12:{txt:(}5.37{txt:)}} {txt}
|
821 |
+
|
822 |
+
{txt}Constant {res} 1946.1 -5853.7 {txt}
|
823 |
+
{res} {ralign 12:{txt:(}0.54{txt:)}} {ralign 12:{txt:(}-1.73{txt:)}} {txt}
|
824 |
+
{txt}{hline 52}
|
825 |
+
{txt}Observations {res} 74 74 {txt}
|
826 |
+
{txt}Adjusted R-squared {res} 0.273 0.478 {txt}
|
827 |
+
{txt}{hline 52}
|
828 |
+
{txt}t statistics in parentheses
|
829 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
830 |
+
|
831 |
+
|
832 |
+
{p 4 4 2}
|
833 |
+
Plain table:
|
834 |
+
|
835 |
+
{com}. esttab, ar2 plain
|
836 |
+
{res}
|
837 |
+
{txt} est1 est2
|
838 |
+
{txt} b/t b/t
|
839 |
+
{txt}weight {res} 1.746559 3.464706{txt}
|
840 |
+
{res} 2.723238 5.493003{txt}
|
841 |
+
{txt}mpg {res} -49.51222 21.8536{txt}
|
842 |
+
{res} -.5746808 .2944391{txt}
|
843 |
+
{txt}foreign {res} 3673.06{txt}
|
844 |
+
{res} 5.370142{txt}
|
845 |
+
{txt}_cons {res} 1946.069 -5853.696{txt}
|
846 |
+
{res} .541018 -1.733408{txt}
|
847 |
+
{txt}N {res} 74 74{txt}
|
848 |
+
{txt}adj. R-sq {res} .2734846 .4781119{txt}
|
849 |
+
|
850 |
+
|
851 |
+
{p 4 4 2}
|
852 |
+
Using standard errors in brackets and suppress significance stars:
|
853 |
+
|
854 |
+
{com}. esttab, se nostar brackets
|
855 |
+
{res}
|
856 |
+
{txt}{hline 38}
|
857 |
+
{txt} (1) (2)
|
858 |
+
{txt} price price
|
859 |
+
{txt}{hline 38}
|
860 |
+
{txt}weight {res} 1.747 3.465{txt}
|
861 |
+
{res} {ralign 12:{txt:[}0.641{txt:]}} {ralign 12:{txt:[}0.631{txt:]}}{txt}
|
862 |
+
|
863 |
+
{txt}mpg {res} -49.51 21.85{txt}
|
864 |
+
{res} {ralign 12:{txt:[}86.16{txt:]}} {ralign 12:{txt:[}74.22{txt:]}}{txt}
|
865 |
+
|
866 |
+
{txt}foreign {res} 3673.1{txt}
|
867 |
+
{res} {ralign 12:{txt:[}684.0{txt:]}}{txt}
|
868 |
+
|
869 |
+
{txt}_cons {res} 1946.1 -5853.7{txt}
|
870 |
+
{res} {ralign 12:{txt:[}3597.0{txt:]}} {ralign 12:{txt:[}3377.0{txt:]}}{txt}
|
871 |
+
{txt}{hline 38}
|
872 |
+
{txt}N {res} 74 74{txt}
|
873 |
+
{txt}{hline 38}
|
874 |
+
{txt}Standard errors in brackets
|
875 |
+
|
876 |
+
|
877 |
+
{p 4 4 2}
|
878 |
+
Printing beta coefficients:
|
879 |
+
|
880 |
+
{com}. esttab, beta
|
881 |
+
{res}
|
882 |
+
{txt}{hline 44}
|
883 |
+
{txt} (1) (2)
|
884 |
+
{txt} price price
|
885 |
+
{txt}{hline 44}
|
886 |
+
{txt}weight {res} 0.460** 0.913***{txt}
|
887 |
+
{res} {ralign 12:{txt:(}2.72{txt:)}} {ralign 12:{txt:(}5.49{txt:)}} {txt}
|
888 |
+
|
889 |
+
{txt}mpg {res} -0.097 0.043 {txt}
|
890 |
+
{res} {ralign 12:{txt:(}-0.57{txt:)}} {ralign 12:{txt:(}0.29{txt:)}} {txt}
|
891 |
+
|
892 |
+
{txt}foreign {res} 0.573***{txt}
|
893 |
+
{res} {ralign 12:{txt:(}5.37{txt:)}} {txt}
|
894 |
+
{txt}{hline 44}
|
895 |
+
{txt}N {res} 74 74 {txt}
|
896 |
+
{txt}{hline 44}
|
897 |
+
{txt}Standardized beta coefficients; t statistics in parentheses
|
898 |
+
{txt}* p<0.05, ** p<0.01, *** p<0.001
|
899 |
+
|
900 |
+
{marker aut}
|
901 |
+
{title:Author}
|
902 |
+
|
903 |
+
{p 4 4 2}
|
904 |
+
Ben Jann, Institute of Sociology, University of Bern, [email protected]
|
905 |
+
|
906 |
+
{marker als}
|
907 |
+
{title:Also see}
|
908 |
+
|
909 |
+
Manual: {hi:[R] estimates}
|
910 |
+
|
911 |
+
{p 4 13 2}Online: help for
|
912 |
+
{helpb estimates},
|
913 |
+
{help estcom},
|
914 |
+
{helpb estout},
|
915 |
+
{helpb eststo},
|
916 |
+
{helpb estadd},
|
917 |
+
{helpb estpost}
|
918 |
+
{p_end}
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/figout.ado
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
program define figout
|
2 |
+
|
3 |
+
*! 1.0.1 Ian Watson 21mar07
|
4 |
+
* 1.0.0 Ian Watson 30mar05
|
5 |
+
* Program to create mini datasets extracted
|
6 |
+
* from tabout results for use in graphs
|
7 |
+
|
8 |
+
|
9 |
+
version 8.2
|
10 |
+
syntax using/ ///
|
11 |
+
, [REPlace] infile(string) ///
|
12 |
+
gvars(string) over(string) ///
|
13 |
+
start(string) stop(string)
|
14 |
+
|
15 |
+
|
16 |
+
if "`infile'" ~="" {
|
17 |
+
local infile = "`infile'"
|
18 |
+
local outfile = "`using'"
|
19 |
+
}
|
20 |
+
else {
|
21 |
+
local infile = "`using'"
|
22 |
+
local outfile = "`using'"
|
23 |
+
}
|
24 |
+
|
25 |
+
if "`replace'" == "replace" {
|
26 |
+
local opt "replace"
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
tempfile tempfile
|
31 |
+
tempname tablefile
|
32 |
+
tempname mainfile
|
33 |
+
|
34 |
+
capture file open `mainfile' using `tempfile', write `opt'
|
35 |
+
|
36 |
+
file write `mainfile' "`over'" _tab
|
37 |
+
tokenize "`gvars'"
|
38 |
+
while "`1'" ~= "" {
|
39 |
+
local outword = "`1'"
|
40 |
+
file write `mainfile' "`outword'" _tab
|
41 |
+
mac shift
|
42 |
+
}
|
43 |
+
file write `mainfile' _n
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
* open the table file with all the existing output
|
48 |
+
|
49 |
+
file open `tablefile' using "`infile'", read
|
50 |
+
|
51 |
+
file read `tablefile' line
|
52 |
+
while r(eof) == 0 {
|
53 |
+
if index("`line'","`start'") ~= 0 {
|
54 |
+
file read `tablefile' line
|
55 |
+
local end = 0
|
56 |
+
while `end' == 0 {
|
57 |
+
local cleanline = subinstr("`line'","\&","and",.)
|
58 |
+
local cleanline = subinstr("`line'","\","",.)
|
59 |
+
* local line : subinstr local line "\&" "and"
|
60 |
+
* local line : subinstr local line "\" ""
|
61 |
+
tokenize "`cleanline'", parse("&")
|
62 |
+
while "`1'" ~= "" {
|
63 |
+
local outword = "`1'"
|
64 |
+
file write `mainfile' "`outword'" _tab
|
65 |
+
mac shift 2
|
66 |
+
}
|
67 |
+
file write `mainfile' _n
|
68 |
+
file read `tablefile' line
|
69 |
+
local end = index("`line'","`stop'")
|
70 |
+
if r(eof)!=0 {
|
71 |
+
di as err "figout failed to find your stop word or phrase"
|
72 |
+
exit
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
else {
|
77 |
+
file read `tablefile' line
|
78 |
+
}
|
79 |
+
} // end while not eof
|
80 |
+
file write `mainfile' _n
|
81 |
+
|
82 |
+
file close `mainfile'
|
83 |
+
file close `tablefile'
|
84 |
+
|
85 |
+
clear
|
86 |
+
insheet using `tempfile'
|
87 |
+
if _N!=0 {
|
88 |
+
local k = _N
|
89 |
+
egen order = fill(1/`k')
|
90 |
+
keep `over' `gvars' order
|
91 |
+
save "`outfile'.dta", `opt'
|
92 |
+
list
|
93 |
+
}
|
94 |
+
else di as err "figout failed to find your start word or phrase"
|
95 |
+
|
96 |
+
end
|
97 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/figout.hlp
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* 21mar07}{...}
|
3 |
+
{hline}
|
4 |
+
help for {hi:figout}
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{p 4 4 2}{hi:figout} {hline 2} Ancillary program for {cmd:tabout} to create mini datatsets suitable for graphing
|
10 |
+
|
11 |
+
{title:Table of contents}
|
12 |
+
|
13 |
+
{help figout##syn:Syntax}
|
14 |
+
{help figout##des:Description}
|
15 |
+
{help figout##opt:Options}
|
16 |
+
{help figout##exa:Examples}
|
17 |
+
|
18 |
+
|
19 |
+
{marker syn}
|
20 |
+
{title:Syntax}
|
21 |
+
|
22 |
+
{p 8 15 2}
|
23 |
+
{cmdab:figout} {it:using} {cmd:,}
|
24 |
+
{cmd:infile(}{it:string}{cmd:)}
|
25 |
+
{cmd:gvars(}{it:string}{cmd:)}
|
26 |
+
{cmd:over(}{it:string}{cmd:)}
|
27 |
+
{cmd:start(}{it:string}{cmd:)}
|
28 |
+
{cmd:stop(}{it:string}{cmd:)}
|
29 |
+
[{cmdab:rep:lace(}{it:string}{cmd:)}]
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
{marker des}
|
34 |
+
{title:Description}
|
35 |
+
|
36 |
+
{p 4 4 2}{cmd:figout} is an ancillary program for {help tabout} to facilitate
|
37 |
+
the creation of graphs based on table panels. {cmd:figout} reads the output file
|
38 |
+
produced by {cmd:tabout} looking for a start word or phrase. It then extracts
|
39 |
+
the numbers it finds until it reaches the stop word or phrase.
|
40 |
+
It only extracts the number of columns for which you indicate {cmd: gvars},
|
41 |
+
which conveniently avoids extracting the totals column. Each line in the panel
|
42 |
+
becomes the basis for the {cmd:over} option in the subsequent graph. {cmd:figout} then loads those numbers into a mini dataset and saves it under the name you specify with {cmd:using}. If {cmd:figout} fails to find either the start word or the stop word, no mini dataset is produced and you are issued a warning. Once the mini dataset is created, it is an easy matter to create a {cmd:Stata} graph. The data is in a form suitable for graph's {cmd:over} option, and {cmd:figout} automatically creates an order variable for you, to preserve the same order that was used in your original table.
|
43 |
+
|
44 |
+
{p 4 4 2}{cmd:tabout} has a comprehensive tutorial which includes a full
|
45 |
+
example of using {cmd:figout}. This is available from the SSC with this help
|
46 |
+
file. The tutorial is also available here:
|
47 |
+
{browse "http://www.ianwatson.com.au/stata/tabout_tutorial.pdf"}.
|
48 |
+
|
49 |
+
|
50 |
+
{marker opt}
|
51 |
+
{title:Options}
|
52 |
+
|
53 |
+
{phang}
|
54 |
+
{cmd:using} is required, and indicates the filename for the output of the mini Stata dataset. Note that you do not need to add the {cmd:dta} filename extension.
|
55 |
+
|
56 |
+
{phang}
|
57 |
+
{cmd:infile} is required the name of the output file produced by {\tt tabout}, for example, {\tt table1.tex}. Note that you do need to add the filename extension because you may be using {\tt figout} with any number of file types ({\LaTeX}, csv, or tab-delimited).
|
58 |
+
|
59 |
+
{phang}
|
60 |
+
{cmd:gvars} are names you wish to assign to your graph variables, and they need to match a contiguous block of cells in your table. They are basically the categories of the horizontal variable in your table.
|
61 |
+
|
62 |
+
{phang}
|
63 |
+
{cmd:over} is the name of the graph variable to be used by the {cmd:over} option in the {cmd:graph} command. It is one the panels in your table, and basically matches one of your vertical variables.
|
64 |
+
|
65 |
+
{phang}
|
66 |
+
{cmd:start} is a unique word or phrase on the line above the block of cells. It can usually refer to the panel title in a {cmd:tabout} table, unless the title is repeated in another panel.
|
67 |
+
|
68 |
+
{phang}
|
69 |
+
{cmd:stop} is a unique word or phrase on the line beneath the block of cells. In the case of LaTeX, you can just use \midrule since this generally indicates the end of a panel if you are using the {cmd:ptotal(single)} option.
|
70 |
+
|
71 |
+
{phang}
|
72 |
+
{cmd:replace} is optional and follows usual Stata convention and prevents you accidentally over-writing an existing Stata dataset with your new mini dataset. If you are confident that there are no other datasets with the same name, you can use the {cmd:replace} option and this makes it more convenient if you need to develop your {cmd:figout} code using several attempts.
|
73 |
+
|
74 |
+
|
75 |
+
{marker exa}
|
76 |
+
{title:Examples}
|
77 |
+
|
78 |
+
{p 4 4 2}
|
79 |
+
The best example is the one given in the {cmd:tabout} tutorial
|
80 |
+
({browse "http://www.ianwatson.com.au/stata/tabout_tutorial.pdf"})
|
81 |
+
where it's use in batch files is demonstrated.
|
82 |
+
|
83 |
+
|
84 |
+
{com} sysuse nlsw88, clear
|
85 |
+
{com} gen wt = int(uniform()*10)
|
86 |
+
|
87 |
+
{com} tabout coll race smsa south [iw=wt] using fig_tab.tex, c(row) f(1) ///
|
88 |
+
{txt} style(tex) bt font(bold) topf(top.tex) botf(bot.tex) topstr(10cm) ///
|
89 |
+
{txt} botstr(nlsw88.dta) cl1(2-4) ptot(single)
|
90 |
+
|
91 |
+
{com} figout using fig_fig, infile(fig_tab.tex) rep ///
|
92 |
+
{txt} gvars(not_south south) ///
|
93 |
+
{txt} over(race) start(Race) stop(\midrule)
|
94 |
+
|
95 |
+
{com} gr hbar not_south south, over(race, sort(order)) ///
|
96 |
+
{txt} ytitle("Percentage", size(medium) ) ///
|
97 |
+
{txt} ylab(0(10)80, angle(0) format(%9.0f) ) ///
|
98 |
+
{txt} bar(1,bcolor(gs4)) bar(2,bcolor(gs8)) ///
|
99 |
+
{txt} legend(label( 1 "Does not live in south") ///
|
100 |
+
{txt} label(2 "Lives in south") ///
|
101 |
+
{txt} pos(4) cols(1) symxsize(3) ring(0) size(medium) ) ///
|
102 |
+
{txt} graphregion(lstyle(solid)) ///
|
103 |
+
{txt} scheme(s2mono) scale(1.1) saving(fig_fig,replace)
|
104 |
+
{com} gr use fig_fig.gph
|
105 |
+
{com} grexportpdf using fig_fig
|
106 |
+
|
107 |
+
|
108 |
+
{title:Author}
|
109 |
+
|
110 |
+
Ian Watson
|
111 |
+
Freelance researcher and
|
112 |
+
Visiting Senior Research Fellow
|
113 |
+
Macquarie University
|
114 |
+
Sydney Australia
|
115 | |
116 |
+
www.ianwatson.com.au
|
117 |
+
|
118 |
+
Version 1.0.1 21mar2007
|
119 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm.ado
ADDED
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.1 15may2009
|
4 |
+
* version 2.0.0 27aug2008
|
5 |
+
* version 1.2.1 29jul2008
|
6 |
+
* version 1.2.0 18jun2008
|
7 |
+
* version 1.0.0 06mar2007
|
8 |
+
|
9 |
+
program fmm, properties(ml_score svyb svyj svyr swml)
|
10 |
+
version 9.2
|
11 |
+
|
12 |
+
if replay() {
|
13 |
+
if ("`e(cmd)'" != "fmm") error 301
|
14 |
+
Replay `0'
|
15 |
+
}
|
16 |
+
else Estimate `0'
|
17 |
+
end
|
18 |
+
|
19 |
+
program Estimate, eclass
|
20 |
+
|
21 |
+
// parse the command
|
22 |
+
syntax varlist [if] [in] ///
|
23 |
+
[fweight pweight iweight] ///
|
24 |
+
, COMPonents(string) MIXtureof(string) ///
|
25 |
+
[PROBability(string) ///
|
26 |
+
Robust CLuster(varname) noCONStant ///
|
27 |
+
OFFset(varname numeric) ///
|
28 |
+
EXPosure(varname numeric) ///
|
29 |
+
SHift(real 0.05) SEarch(string) FRom(string) ///
|
30 |
+
DF(real 5) *]
|
31 |
+
|
32 |
+
mlopts mlopts, `options'
|
33 |
+
gettoken lhs rhs : varlist
|
34 |
+
|
35 |
+
if "`search'"=="" local search "off"
|
36 |
+
|
37 |
+
if "`cluster'" != "" {
|
38 |
+
local clopt cluster(`cluster')
|
39 |
+
}
|
40 |
+
|
41 |
+
if "`weight'" != "" {
|
42 |
+
tempvar wvar
|
43 |
+
quietly gen double `wvar' `exp'
|
44 |
+
local wgt "[`weight'=`wvar']"
|
45 |
+
}
|
46 |
+
|
47 |
+
if "`offset'" != "" {
|
48 |
+
local offopt "offset(`offset')"
|
49 |
+
}
|
50 |
+
if "`exposure'" != "" {
|
51 |
+
local expopt "exposure(`exposure')"
|
52 |
+
}
|
53 |
+
|
54 |
+
// mark the estimation sample
|
55 |
+
marksample touse
|
56 |
+
markout `touse' `wvar' `offset' `exposure'
|
57 |
+
markout `touse' `probability'
|
58 |
+
markout `touse' `cluster', strok
|
59 |
+
|
60 |
+
global fmm_components = `components'
|
61 |
+
global fmm_tdf = `df'
|
62 |
+
|
63 |
+
// check syntax for number of components
|
64 |
+
if "`components'"<"2" | "`components'">"9" {
|
65 |
+
di in red "number of components, components(#), is a required option"
|
66 |
+
di in red "# must be an integer greater than 1 and less than 10"
|
67 |
+
exit 198
|
68 |
+
}
|
69 |
+
|
70 |
+
// check syntax for the distribution mixtureof
|
71 |
+
if "`mixtureof'"!="" ///
|
72 |
+
& "`mixtureof'"!="gamma" ///
|
73 |
+
& "`mixtureof'"!="lognormal" ///
|
74 |
+
& "`mixtureof'"!="negbin1" ///
|
75 |
+
& "`mixtureof'"!="negbin2" ///
|
76 |
+
& "`mixtureof'"!="normal" ///
|
77 |
+
& "`mixtureof'"!="poisson" ///
|
78 |
+
& "`mixtureof'"!="studentt" ///
|
79 |
+
{
|
80 |
+
di in red "invalid syntax: component distribution, mixtureof(), incorrectly specified"
|
81 |
+
exit 198
|
82 |
+
}
|
83 |
+
|
84 |
+
// test collinearity for component RHS variables
|
85 |
+
_rmcoll `rhs' `wgt' if `touse', `constant'
|
86 |
+
local rhs `r(varlist)'
|
87 |
+
_rmcoll `probability' `wgt' if `touse', `constant'
|
88 |
+
local probability `r(varlist)'
|
89 |
+
|
90 |
+
// create density names and equations for ml model
|
91 |
+
local fx `"`fx' (component1: `lhs' = `rhs', `constant' `offopt' `expopt')"'
|
92 |
+
forvalues i=2/`components' {
|
93 |
+
local fx `"`fx' (component`i': = `rhs', `constant' `offopt' `expopt')"'
|
94 |
+
}
|
95 |
+
|
96 |
+
if "`mixtureof'"=="gamma" {
|
97 |
+
local densityname "Gamma"
|
98 |
+
forvalues i=1/`components' {
|
99 |
+
local scale `"`scale' /lnalpha`i'"'
|
100 |
+
}
|
101 |
+
}
|
102 |
+
if "`mixtureof'"=="lognormal" {
|
103 |
+
local densityname "Lognormal"
|
104 |
+
forvalues i=1/`components' {
|
105 |
+
local scale `"`scale' /lnsigma`i'"'
|
106 |
+
}
|
107 |
+
}
|
108 |
+
if "`mixtureof'"=="negbin1" {
|
109 |
+
local densityname "Negative Binomial-1"
|
110 |
+
forvalues i=1/`components' {
|
111 |
+
local scale `"`scale' /lndelta`i'"'
|
112 |
+
}
|
113 |
+
}
|
114 |
+
if "`mixtureof'"=="negbin2" {
|
115 |
+
local densityname "Negative Binomial-2"
|
116 |
+
forvalues i=1/`components' {
|
117 |
+
local scale `"`scale' /lnalpha`i'"'
|
118 |
+
}
|
119 |
+
}
|
120 |
+
if "`mixtureof'"=="normal" {
|
121 |
+
local densityname "Normal"
|
122 |
+
forvalues i=1/`components' {
|
123 |
+
local scale `"`scale' /lnsigma`i'"'
|
124 |
+
}
|
125 |
+
}
|
126 |
+
if "`mixtureof'"=="poisson" {
|
127 |
+
local densityname "Poisson"
|
128 |
+
}
|
129 |
+
if "`mixtureof'"=="studentt" {
|
130 |
+
local densityname "Student-t"
|
131 |
+
forvalues i=1/`components' {
|
132 |
+
local scale `"`scale' /lnsigma`i'"'
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
// SET UP MODELS WITH CONSTANT PROBABILITY SPECIFICATION
|
138 |
+
if "`probability'"=="" {
|
139 |
+
forvalues i=1/`=`components'-1' {
|
140 |
+
local ilp`i' "/imlogitpi`i'"
|
141 |
+
local ilp `" `ilp' `ilp`i'' "'
|
142 |
+
}
|
143 |
+
local Model `"`fx' `ilp' `scale' "'
|
144 |
+
|
145 |
+
|
146 |
+
// GENERATE STARTING VALUES
|
147 |
+
if "`from'"=="" {
|
148 |
+
|
149 |
+
if "`components'"=="2" {
|
150 |
+
tempname lln bn cbn sn bnincr s
|
151 |
+
if "`mixtureof'"=="gamma" {
|
152 |
+
// fit a glm gamma model
|
153 |
+
qui glm `lhs' `rhs' `wgt' if `touse' `in', family(gamma) link(log) ///
|
154 |
+
`constant' `offopt' `expopt'
|
155 |
+
matrix `bn' = e(b)
|
156 |
+
scalar `cbn' = colsof(`bn')
|
157 |
+
matrix `sn' = 0
|
158 |
+
matrix `s' = `bn', `sn'
|
159 |
+
// fit a gamma regression model
|
160 |
+
`quietly' display as txt _n "Fitting Gamma regression model:"
|
161 |
+
ml model d2 gammareg_lf (`lhs'=`rhs', `constant' `offopt' `expopt' ) ///
|
162 |
+
/lndelta `wgt' if `touse' `in' ///
|
163 |
+
, `robust' `clopt' `mlopts' collinear missing init(`s', copy) ///
|
164 |
+
maximize search(off)
|
165 |
+
matrix `bn' = e(b)
|
166 |
+
scalar `cbn' = colsof(`bn')
|
167 |
+
matrix `sn' = `bn'[1,`cbn']
|
168 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
169 |
+
matrix `bnincr'=`bn'
|
170 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]+`shift'
|
171 |
+
}
|
172 |
+
if "`mixtureof'"=="lognormal" {
|
173 |
+
// fit an ols regression model
|
174 |
+
tempvar loglhs
|
175 |
+
qui gen `loglhs' = ln(`lhs')
|
176 |
+
qui reg `loglhs' `rhs' `wgt' if `touse' `in', `constant'
|
177 |
+
matrix `bn' = e(b)
|
178 |
+
scalar `cbn' = colsof(`bn')
|
179 |
+
matrix `sn' = ln(e(rmse))
|
180 |
+
matrix `s' = `bn', `sn'
|
181 |
+
// fit a loglinear regression model
|
182 |
+
`quietly' display as txt _n "Fitting Logormal regression model:"
|
183 |
+
ml model d2 lognormalreg_lf (`lhs'=`rhs', `constant' `offopt' `expopt') ///
|
184 |
+
/lnsigma `wgt' if `touse' `in' ///
|
185 |
+
, `robust' `clopt' `mlopts' collinear missing init(`s', copy) ///
|
186 |
+
maximize search(off)
|
187 |
+
matrix `bn' = e(b)
|
188 |
+
scalar `cbn' = colsof(`bn')
|
189 |
+
matrix `sn' = `bn'[1,`cbn']
|
190 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
191 |
+
matrix `bnincr'=`bn'
|
192 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]*(1+`shift')
|
193 |
+
}
|
194 |
+
if "`mixtureof'"=="negbin1" {
|
195 |
+
// fit a nbreg model
|
196 |
+
`quietly' display as txt _n "Fitting Negative Binomial-1 model:"
|
197 |
+
nbreg `lhs' `rhs' `wgt' if `touse' `in' , `robust' `clopt' ///
|
198 |
+
dispersion(constant) nodisplay `constant' `offopt' `expopt'
|
199 |
+
matrix `bn' = e(b)
|
200 |
+
scalar `cbn' = colsof(`bn')
|
201 |
+
matrix `sn' = `bn'[1,`cbn']
|
202 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
203 |
+
matrix `bnincr'=`bn'
|
204 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]+`shift'
|
205 |
+
}
|
206 |
+
if "`mixtureof'"=="negbin2" {
|
207 |
+
// fit a nbreg model
|
208 |
+
`quietly' display as txt _n "Fitting Negative Binomial-2 model:"
|
209 |
+
nbreg `lhs' `rhs' `wgt' if `touse' `in' , `robust' `clopt' ///
|
210 |
+
dispersion(mean) nodisplay `constant' `offopt' `expopt'
|
211 |
+
matrix `bn' = e(b)
|
212 |
+
scalar `cbn' = colsof(`bn')
|
213 |
+
matrix `sn' = `bn'[1,`cbn']
|
214 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
215 |
+
matrix `bnincr'=`bn'
|
216 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]+`shift'
|
217 |
+
}
|
218 |
+
if "`mixtureof'"=="normal" {
|
219 |
+
// fit an ols regression model
|
220 |
+
qui reg `lhs' `rhs' `wgt' if `touse' `in', `constant'
|
221 |
+
matrix `bn' = e(b)
|
222 |
+
scalar `cbn' = colsof(`bn')
|
223 |
+
matrix `sn' = ln(e(rmse))
|
224 |
+
matrix `s' = `bn', `sn'
|
225 |
+
// fit a linear regression model
|
226 |
+
`quietly' display as txt _n "Fitting Normal regression model:"
|
227 |
+
ml model d2 normalreg_lf (`lhs'=`rhs', `constant' `offopt' `expopt') ///
|
228 |
+
/lnsigma `wgt' if `touse' `in' ///
|
229 |
+
, `robust' `clopt' `mlopts' collinear missing init(`s', copy) ///
|
230 |
+
maximize search(off)
|
231 |
+
matrix `bn' = e(b)
|
232 |
+
scalar `cbn' = colsof(`bn')
|
233 |
+
matrix `sn' = `bn'[1,`cbn']
|
234 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
235 |
+
matrix `bnincr'=`bn'
|
236 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]*(1+`shift')
|
237 |
+
}
|
238 |
+
if "`mixtureof'"=="poisson" {
|
239 |
+
// fit a Poisson model
|
240 |
+
`quietly' display as txt _n "Fitting Poisson model:"
|
241 |
+
poisson `lhs' `rhs' `wgt' if `touse' `in' , `robust' `clopt' ///
|
242 |
+
nodisplay `constant' `offopt' `expopt'
|
243 |
+
matrix `bn' = e(b)
|
244 |
+
scalar `cbn'=colsof(`bn')
|
245 |
+
matrix `bnincr'=`bn'
|
246 |
+
matrix `bnincr'[1,`cbn'] = `bnincr'[1,`cbn']+`shift'
|
247 |
+
matrix `s' = `bn', `bnincr', 1
|
248 |
+
local contin init(`s', copy) search(`search')
|
249 |
+
}
|
250 |
+
if "`mixtureof'"=="studentt" {
|
251 |
+
// fit an ols regression model
|
252 |
+
qui reg `lhs' `rhs' `wgt' if `touse' `in', `constant'
|
253 |
+
matrix `bn' = e(b)
|
254 |
+
scalar `cbn' = colsof(`bn')
|
255 |
+
matrix `sn' = ln(e(rmse))
|
256 |
+
matrix `s' = `bn', `sn'
|
257 |
+
// fit a Student-t regression model
|
258 |
+
`quietly' display as txt _n "Fitting Student-t regression model:"
|
259 |
+
ml model d2 studenttreg_lf (`lhs'=`rhs', `constant' `offopt' `expopt') ///
|
260 |
+
/lnsigma `wgt' if `touse' `in' ///
|
261 |
+
, `robust' `clopt' `mlopts' collinear missing init(`s', copy) ///
|
262 |
+
maximize search(off)
|
263 |
+
matrix `bn' = e(b)
|
264 |
+
scalar `cbn' = colsof(`bn')
|
265 |
+
matrix `sn' = `bn'[1,`cbn']
|
266 |
+
matrix `bn' = `bn'[1,1..(`cbn'-1)]
|
267 |
+
matrix `bnincr'=`bn'
|
268 |
+
matrix `bnincr'[1,`cbn'-1] = `bnincr'[1,`cbn'-1]*(1+`shift')
|
269 |
+
}
|
270 |
+
|
271 |
+
if "`mixtureof'"=="poisson" {
|
272 |
+
matrix `s' = `bn', `bnincr', 1
|
273 |
+
}
|
274 |
+
else {
|
275 |
+
matrix `s' = `bn', `bnincr', 1, `sn', `sn'
|
276 |
+
}
|
277 |
+
local contin init(`s', copy) search(`search')
|
278 |
+
|
279 |
+
}
|
280 |
+
|
281 |
+
if "`components'">"2" {
|
282 |
+
if "`e(cmd)'"!="fmm" | "`e(components)'"!="`=`components'-1'" ///
|
283 |
+
| "`e(mixtureof)'"!="`mixtureof'" | "`e(probability)'"!="" {
|
284 |
+
di in red "provide starting values or estimate `=`components'-1' component `mixtureof' model"
|
285 |
+
di in red "with constant component probabilities"
|
286 |
+
exit 198
|
287 |
+
}
|
288 |
+
|
289 |
+
if "`mixtureof'"=="poisson" {
|
290 |
+
forvalues i=1/`components' {
|
291 |
+
local tnames `" `tnames' b`i' "'
|
292 |
+
}
|
293 |
+
forvalues i=1/`=`components'-1' {
|
294 |
+
local tnames `" `tnames' ipi`i' pi`i' "'
|
295 |
+
}
|
296 |
+
|
297 |
+
tempname b cb cb1cl C incr den s sumpi `tnames' pi`components'
|
298 |
+
matrix `b' = e(b)
|
299 |
+
scalar `cb' = colsof(`b')
|
300 |
+
scalar `cb1cl' = (1/(`components'-1))*(`cb'-`components'+2)
|
301 |
+
forvalues i=1/`=`components'-1' {
|
302 |
+
matrix `b`i''=`b'[1,((`i'-1)*`cb1cl'+1)..(`i'*`cb1cl')]
|
303 |
+
}
|
304 |
+
|
305 |
+
forvalues i=1/`=`components'-2' {
|
306 |
+
scalar `ipi`i'' = `b'[1,`cb'-(`components'-2)+`i']
|
307 |
+
}
|
308 |
+
scalar `den' = 1
|
309 |
+
forvalues i=1/`=`components'-2' {
|
310 |
+
scalar `den' = `den' + exp(`ipi`i'')
|
311 |
+
}
|
312 |
+
scalar `sumpi' = 0
|
313 |
+
forvalues i=1/`=`components'-2' {
|
314 |
+
scalar `pi`i'' = exp(`ipi`i'')/`den'
|
315 |
+
scalar `sumpi' = `sumpi' + `pi`i''
|
316 |
+
}
|
317 |
+
scalar `pi`=`components'-1'' = 1-`sumpi'
|
318 |
+
|
319 |
+
matrix `b`components'' = `b1'
|
320 |
+
local C 1
|
321 |
+
matrix `incr'=J(1,`cb1cl',0)
|
322 |
+
matrix `incr'[1,`cb1cl'] = `shift'
|
323 |
+
forvalues i=2/`=`components'-1' {
|
324 |
+
if `pi`i'' > `pi`=`i'-1''{
|
325 |
+
local C `=`i''
|
326 |
+
matrix `b`components'' = `b`i''
|
327 |
+
}
|
328 |
+
}
|
329 |
+
scalar `pi`C'' = (1-`shift')*`pi`C''
|
330 |
+
scalar `pi`components'' = `shift'*`pi`C''
|
331 |
+
|
332 |
+
forvalues i=1/`=`components'-1' {
|
333 |
+
scalar `ipi`i'' = ln(`pi`i''/`pi`components'')
|
334 |
+
}
|
335 |
+
|
336 |
+
forvalues i=1/`=`components'-1' {
|
337 |
+
local bnames `" `bnames' `b`i'', "'
|
338 |
+
local ipinames `" `ipinames', `ipi`i'' "'
|
339 |
+
}
|
340 |
+
matrix `s' = `bnames' `b`components''+`incr' `ipinames'
|
341 |
+
local contin init(`s', copy) search(`search')
|
342 |
+
}
|
343 |
+
|
344 |
+
if "`mixtureof'"!="poisson" {
|
345 |
+
forvalues i=1/`components' {
|
346 |
+
local tnames `" `tnames' b`i' scale`i' "'
|
347 |
+
}
|
348 |
+
forvalues i=1/`=`components'-1' {
|
349 |
+
local tnames `" `tnames' ipi`i' pi`i' "'
|
350 |
+
}
|
351 |
+
|
352 |
+
tempname b cb cb1cl C bcincr den s sumpi `tnames' pi`components'
|
353 |
+
matrix `b' = e(b)
|
354 |
+
scalar `cb' = colsof(`b')
|
355 |
+
scalar `cb1cl' = (1/(`components'-1))*(`cb'-2*`components'+3)
|
356 |
+
forvalues i=1/`=`components'-1' {
|
357 |
+
matrix `b`i'' = `b'[1,((`i'-1)*`cb1cl'+1)..(`i'*`cb1cl')]
|
358 |
+
scalar `scale`i'' = `b'[1,`cb'-`components'+1+`i']
|
359 |
+
}
|
360 |
+
forvalues i=1/`=`components'-2' {
|
361 |
+
scalar `ipi`i'' = `b'[1,`cb'-2*`components'+3+`i']
|
362 |
+
}
|
363 |
+
scalar `den' = 1
|
364 |
+
forvalues i=1/`=`components'-2' {
|
365 |
+
scalar `den' = `den' + exp(`ipi`i'')
|
366 |
+
}
|
367 |
+
scalar `sumpi' = 0
|
368 |
+
forvalues i=1/`=`components'-2' {
|
369 |
+
scalar `pi`i'' = exp(`ipi`i'')/`den'
|
370 |
+
scalar `sumpi' = `sumpi' + `pi`i''
|
371 |
+
}
|
372 |
+
scalar `pi`=`components'-1'' = 1-`sumpi'
|
373 |
+
|
374 |
+
matrix `b`components'' = `b1'
|
375 |
+
matrix `scale`components'' = `scale1'
|
376 |
+
local C 1
|
377 |
+
forvalues i=2/`=`components'-1' {
|
378 |
+
if `pi`i'' > `pi`=`i'-1''{
|
379 |
+
local C `=`i''
|
380 |
+
matrix `b`components'' = `b`i''
|
381 |
+
scalar `scale`components'' = `scale`i''
|
382 |
+
}
|
383 |
+
}
|
384 |
+
matrix `bcincr'=`b`components''
|
385 |
+
matrix `bcincr'[1,`cb1cl'] = `bcincr'[1,`cb1cl']*(1+`shift')
|
386 |
+
scalar `pi`C'' = (1-`shift')*`pi`C''
|
387 |
+
scalar `pi`components'' = `shift'*`pi`C''
|
388 |
+
forvalues i=1/`=`components'-1' {
|
389 |
+
scalar `ipi`i'' = ln(`pi`i''/`pi`components'')
|
390 |
+
}
|
391 |
+
|
392 |
+
forvalues i=1/`=`components'-1' {
|
393 |
+
local bnames `" `bnames' `b`i'', "'
|
394 |
+
local ipinames `" `ipinames', `ipi`i'' "'
|
395 |
+
}
|
396 |
+
forvalues i=1/`components' {
|
397 |
+
local scalenames `" `scalenames', `scale`i'' "'
|
398 |
+
}
|
399 |
+
matrix `s' = `bnames' `bcincr' `ipinames' `scalenames'
|
400 |
+
local contin init(`s', copy) search(`search')
|
401 |
+
}
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
// if starting values are provided
|
406 |
+
if `"`from'"'!="" {
|
407 |
+
local contin init(`from',copy) search(`search')
|
408 |
+
}
|
409 |
+
|
410 |
+
|
411 |
+
// fit the full model
|
412 |
+
local title "`components' component `densityname' regression"
|
413 |
+
`quietly' display as txt _n "Fitting `components' component `densityname' model:"
|
414 |
+
/* ml model d2debug fmm_`mixtureof'_lf `Model' `wgt' if `touse' `in' ///
|
415 |
+
, `contin' maximize */
|
416 |
+
ml model d2 fmm_`mixtureof'_lf `Model' `wgt' if `touse' `in' ///
|
417 |
+
, title(`title') `robust' `clopt' `mlopts' `contin' ///
|
418 |
+
collinear missing waldtest(`components') maximize
|
419 |
+
ereturn local cmd fmm
|
420 |
+
ereturn local components "`components'"
|
421 |
+
ereturn local mixtureof "`mixtureof'"
|
422 |
+
ereturn local predict "fmm_`mixtureof'_p"
|
423 |
+
if "`mixtureof'"=="poisson" {
|
424 |
+
ereturn scalar k_aux = `components'-1
|
425 |
+
}
|
426 |
+
else {
|
427 |
+
ereturn scalar k_aux = 2*`components'-1
|
428 |
+
}
|
429 |
+
|
430 |
+
Replay
|
431 |
+
}
|
432 |
+
|
433 |
+
// SET UP MODELS WITH REGRESSORS IN THE PROBABILITY SPECIFICATION
|
434 |
+
if "`probability'"!="" {
|
435 |
+
forvalues i=1/`=`components'-1' {
|
436 |
+
local ilp `" `ilp' (imlogitpi`i': = `probability')"'
|
437 |
+
}
|
438 |
+
local Model `"`fx' `ilp' `scale' "'
|
439 |
+
|
440 |
+
if "`from'"=="" {
|
441 |
+
if "`e(cmd)'"!="fmm" | "`e(components)'"!="`=`components''" ///
|
442 |
+
| "`e(mixtureof)'"!="`mixtureof'" | "`e(probability)'"!="" {
|
443 |
+
di in red "provide starting values or estimate `components' component `densityname' model"
|
444 |
+
di in red "with constant component probabilities"
|
445 |
+
exit 198
|
446 |
+
}
|
447 |
+
|
448 |
+
// get starting values from prior LC model
|
449 |
+
tempname s
|
450 |
+
mat `s'= e(b)
|
451 |
+
local contin init(`s') search(`search')
|
452 |
+
}
|
453 |
+
|
454 |
+
if `"`from'"'!="" {
|
455 |
+
local contin init(`from',copy) search(`search')
|
456 |
+
}
|
457 |
+
|
458 |
+
// fit the full model
|
459 |
+
local title `title'
|
460 |
+
`quietly' display as txt _n "Fitting `components' component `densityname' model:"
|
461 |
+
ml model d2 fmm_`mixtureof'_lf `Model' `wgt' if `touse' `in' ///
|
462 |
+
, title(`title') `robust' `clopt' `mlopts' `contin' ///
|
463 |
+
collinear missing waldtest(`components') maximize
|
464 |
+
|
465 |
+
ereturn local cmd fmm
|
466 |
+
ereturn local components "`components'"
|
467 |
+
ereturn local mixtureof "`mixtureof'"
|
468 |
+
ereturn local probability "`probability'"
|
469 |
+
ereturn local predict "fmm_`mixtureof'_p"
|
470 |
+
if "`mixtureof'"=="poisson" {
|
471 |
+
ereturn scalar k_aux = 0
|
472 |
+
}
|
473 |
+
else {
|
474 |
+
ereturn scalar k_aux = `components'
|
475 |
+
}
|
476 |
+
|
477 |
+
Replay
|
478 |
+
}
|
479 |
+
|
480 |
+
end
|
481 |
+
|
482 |
+
|
483 |
+
program Replay, eclass
|
484 |
+
|
485 |
+
ml display
|
486 |
+
|
487 |
+
local components `e(components)'
|
488 |
+
local mixtureof `e(mixtureof)'
|
489 |
+
local probability `e(probability)'
|
490 |
+
|
491 |
+
if "`mixtureof'"=="gamma" {
|
492 |
+
local scale `"alpha"'
|
493 |
+
}
|
494 |
+
if "`mixtureof'"=="lognormal" {
|
495 |
+
local scale `"sigma"'
|
496 |
+
}
|
497 |
+
if "`mixtureof'"=="negbin1" {
|
498 |
+
local scale "delta"
|
499 |
+
}
|
500 |
+
if "`mixtureof'"=="negbin2" {
|
501 |
+
local scale "alpha"
|
502 |
+
}
|
503 |
+
if "`mixtureof'"=="normal" {
|
504 |
+
local scale `"sigma"'
|
505 |
+
}
|
506 |
+
if "`mixtureof'"=="studentt" {
|
507 |
+
local scale `"sigma"'
|
508 |
+
}
|
509 |
+
|
510 |
+
if "`probability'"=="" {
|
511 |
+
|
512 |
+
if `components'==2 {
|
513 |
+
if "`mixtureof'"!="poisson" {
|
514 |
+
_diparm ln`scale'1, exp label(`scale'1)
|
515 |
+
ereturn scalar `scale'1_est = r(est)
|
516 |
+
ereturn scalar `scale'1_se = r(se)
|
517 |
+
_diparm ln`scale'2, exp label(`scale'2)
|
518 |
+
ereturn scalar `scale'2_est = r(est)
|
519 |
+
ereturn scalar `scale'2_se = r(se)
|
520 |
+
}
|
521 |
+
_diparm imlogitpi1, invlogit label(pi1)
|
522 |
+
ereturn scalar pi1_est = r(est)
|
523 |
+
ereturn scalar pi1_se = r(se)
|
524 |
+
local prob2 diparm(imlogitpi1, func(1-exp(@)/(1+exp(@))) ///
|
525 |
+
der(-exp(@)/((1+exp(@))^2)) label(pi2))
|
526 |
+
_diparm imlogitpi1, func(1-exp(@)/(1+exp(@))) ///
|
527 |
+
der(-exp(@)/((1+exp(@))^2)) label(pi2)
|
528 |
+
ereturn scalar pi2_est = r(est)
|
529 |
+
ereturn scalar pi2_se = r(se)
|
530 |
+
}
|
531 |
+
|
532 |
+
if `components'>=3 {
|
533 |
+
if "`mixtureof'"!="poisson" {
|
534 |
+
forvalues j=1/`components' {
|
535 |
+
_diparm ln`scale'`j', exp label(`scale'`j')
|
536 |
+
ereturn scalar `scale'`j'_est = r(est)
|
537 |
+
ereturn scalar `scale'`j'_se = r(se)
|
538 |
+
|
539 |
+
}
|
540 |
+
}
|
541 |
+
local den "1"
|
542 |
+
forvalues i=1/`=`components'-1' {
|
543 |
+
local den `"`den'+exp(@`i')"'
|
544 |
+
local invml `"`invml' imlogitpi`i'"'
|
545 |
+
}
|
546 |
+
forvalues i=1/`=`components'-1' {
|
547 |
+
local prob`i' `"_diparm `invml', func(exp(@`i')/(`den')) der("'
|
548 |
+
forvalues j=1/`=`components'-1' {
|
549 |
+
if `i'==`j' {
|
550 |
+
local prod `"`den'-exp(@`i')"'
|
551 |
+
local der`i'`j' `"+0+exp(@`i')*(`prod')/((`den')^2)"'
|
552 |
+
}
|
553 |
+
else {
|
554 |
+
local der`i'`j' `"-exp(@`i')*exp(@`j')/((`den')^2)"'
|
555 |
+
}
|
556 |
+
local prob`i' `"`prob`i'' `der`i'`j''"'
|
557 |
+
}
|
558 |
+
local prob`i' `" `prob`i'' ) label(pi`i') ci(logit) "'
|
559 |
+
`prob`i''
|
560 |
+
ereturn scalar pi`i'_est = r(est)
|
561 |
+
ereturn scalar pi`i'_se = r(se)
|
562 |
+
|
563 |
+
}
|
564 |
+
forvalues j=1/`=`components'-1' {
|
565 |
+
forvalues i=1/`=`components'-1' {
|
566 |
+
local sumder`j' `"`sumder`j''`der`i'`j''"'
|
567 |
+
}
|
568 |
+
local derivs `"`derivs'`sumder`j'' "'
|
569 |
+
}
|
570 |
+
_diparm `invml', func(1-(`den'-1)/(`den')) ///
|
571 |
+
der(`derivs') label(pi`components')
|
572 |
+
ereturn scalar pi`components'_est = r(est)
|
573 |
+
ereturn scalar pi`components'_se = r(se)
|
574 |
+
}
|
575 |
+
_diparm __bot__
|
576 |
+
}
|
577 |
+
|
578 |
+
if "`probability'"!="" {
|
579 |
+
if "`mixtureof'"!="poisson" {
|
580 |
+
forvalues j=1/`components' {
|
581 |
+
_diparm ln`scale'`j', exp label(`scale'`j')
|
582 |
+
ereturn scalar `scale'`j'_est = r(est)
|
583 |
+
ereturn scalar `scale'`j'_se = r(se)
|
584 |
+
}
|
585 |
+
_diparm __bot__
|
586 |
+
}
|
587 |
+
}
|
588 |
+
|
589 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm.hlp
ADDED
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* documented: June 12, 2007}{...}
|
3 |
+
{* revised: February 12, 2012}{...}
|
4 |
+
{cmd:help fmm} {right:also see: {helpb fmm postestimation}}
|
5 |
+
|
6 |
+
{hline}
|
7 |
+
|
8 |
+
{title:Title}
|
9 |
+
|
10 |
+
{cmd :fmm} {hline 2} Finite mixture models
|
11 |
+
|
12 |
+
|
13 |
+
{title:Syntax}
|
14 |
+
|
15 |
+
{phang}
|
16 |
+
Finite mixture models
|
17 |
+
|
18 |
+
{p 8 14 2}
|
19 |
+
{cmd:fmm} {depvar} [{indepvars}] {ifin} {weight}{cmd:,} {opt comp:onents(#)}
|
20 |
+
{opth mix:tureof(fmm##density:density)} [{it:{help fmm##fmm_options:fmm_options}}]
|
21 |
+
|
22 |
+
{synoptset 28 tabbed}{...}
|
23 |
+
{marker fmm_options}{...}
|
24 |
+
{synopthdr :fmm_options}
|
25 |
+
{synoptline}
|
26 |
+
{syntab :Model}
|
27 |
+
{synopt :{opt comp:onents(#)}}specifies the number of mixture components. It is
|
28 |
+
required.{p_end}
|
29 |
+
{synopt :{opth mix:tureof(fmm##density:density)}}specifies the component density.
|
30 |
+
It is required.{p_end}
|
31 |
+
|
32 |
+
{syntab :Model 2}
|
33 |
+
{synopt :{opth prob:ability(varlist)}}specifies the variables used to model the component probabilities.{p_end}
|
34 |
+
{synopt :{opt df(#)}}specifies the degrees of freedom of the Student-t density. The default is 5.{p_end}
|
35 |
+
{synopt :{opt nocons:tant}}suppress constant term{p_end}
|
36 |
+
{synopt :{opth exp:osure(varname)}}include ln({it:varname}) in model with
|
37 |
+
coefficient constrained to 1.{p_end}
|
38 |
+
{synopt :{opth off:set(varname)}}include {it:varname} in model with coefficient
|
39 |
+
constrained to 1.{p_end}
|
40 |
+
{synopt :{opth cons:traint(constraint)}}apply specified linear constraints.{p_end}
|
41 |
+
|
42 |
+
{syntab :SE/Robust}
|
43 |
+
{synopt :{opth vce(vcetype)}}{it:vcetype} may be {opt oim}, {opt r:obust}, {opt opg}, {opt boot:strap}, or {opt jack:knife}{p_end}
|
44 |
+
{synopt :{opt r:obust}}synonym for {cmd:vce(robust)}{p_end}
|
45 |
+
{synopt :{opth cl:uster(varname)}}adjust standard errors for intragroup correlation{p_end}
|
46 |
+
|
47 |
+
{syntab :Max options}
|
48 |
+
{synopt :{it:{help fmm##fmm_maximize:maximize_options}}}control the maximization process; some options may be useful{p_end}
|
49 |
+
{synoptline}
|
50 |
+
{p2colreset}{...}
|
51 |
+
{p 4 6 2} {it:depvar}, {it:indepvars}, {it:varname_e}, and {it:varname_o} may
|
52 |
+
contain time-series operators; see {help tsvarlist}.{p_end}
|
53 |
+
|
54 |
+
{p 4 6 2} {cmd:fweight}s, {cmd:pweight}s, {cmd:iweight}s, and {cmd:aweight}s
|
55 |
+
are allowed; see {help weight}.{p_end}
|
56 |
+
{p 4 6 2} See {help postestimation commands} for features available after estimation.
|
57 |
+
|
58 |
+
{marker density}{...}
|
59 |
+
{synoptset 23}{...}
|
60 |
+
{synopthdr :density}
|
61 |
+
{synoptline}
|
62 |
+
{synopt :{opt gamma}}Gamma{p_end}
|
63 |
+
{synopt :{opt lognormal}}Lognormal{p_end}
|
64 |
+
{synopt :{opt negbin1}}Negative Binomial-1 (constant dispersion){p_end}
|
65 |
+
{synopt :{opt negbin2}}Negative Binomial-2 (mean dispersion){p_end}
|
66 |
+
{synopt :{opt normal}}Normal or Gaussian{p_end}
|
67 |
+
{synopt :{opt poisson}}Poisson{p_end}
|
68 |
+
{synopt :{opt studentt}}Student-t with {opt df} degrees of freedom{p_end}
|
69 |
+
{synoptline}
|
70 |
+
{p2colreset}{...}
|
71 |
+
|
72 |
+
|
73 |
+
{title:Description}
|
74 |
+
|
75 |
+
{pstd}
|
76 |
+
{cmd:fmm} fits a finite mixture regression model of {it:depvar} on {it:indepvars}
|
77 |
+
using maximum likelihood estimation. The model is a {it:J}-component finite mixture
|
78 |
+
of densities, with the density within a component (j) allowed to vary in location
|
79 |
+
and scale. Optionally, the mixing probabilities may be specified with covariates.
|
80 |
+
|
81 |
+
|
82 |
+
{title:Options for fmm}
|
83 |
+
|
84 |
+
{dlgtab:Model}
|
85 |
+
|
86 |
+
{phang}
|
87 |
+
{opt comp:onents(#)} specifies the number of mixing components. It is an
|
88 |
+
integral part of specifying the finite mixture model and is not optional.
|
89 |
+
{it:#} should be an integer between 2 and 9.
|
90 |
+
|
91 |
+
{phang}
|
92 |
+
{opt mix:tureof(density)} specifies the component density in the
|
93 |
+
mixture model. It is not optional. For more on the available choices of
|
94 |
+
component densities and associated specifications of conditional means, see
|
95 |
+
{opt Remarks} below.
|
96 |
+
|
97 |
+
{dlgtab:Model 2}
|
98 |
+
|
99 |
+
{phang}
|
100 |
+
{opt prob:ability(varlist)} specifies the variables used to model
|
101 |
+
the component probabilities. The probabilities are specified using a
|
102 |
+
multinomial logit parameterization.
|
103 |
+
|
104 |
+
{phang}
|
105 |
+
{opt df(#)} specifies the degrees of freedom if a Student-t component density
|
106 |
+
is specified. The default value is 5.
|
107 |
+
|
108 |
+
{phang}
|
109 |
+
{opt nocons:tant}, {opth exp:osure(varname)}, {opt off:set(varname)},
|
110 |
+
{opt cons:traints(constraints)}; see {help estimation options}.
|
111 |
+
|
112 |
+
{dlgtab:SE/Robust}
|
113 |
+
|
114 |
+
{phang}
|
115 |
+
{opt vce(vcetype)}; see {it:{help vce_option}}.
|
116 |
+
|
117 |
+
{phang}
|
118 |
+
{opt r:obust}, {opt cl:uster(varname)}; see {help estimation options}.
|
119 |
+
{opt cl:uster()} can be used with {help pweight}s to produce estimates for
|
120 |
+
unstratified cluster-sampled data.
|
121 |
+
|
122 |
+
{dlgtab:Reporting}
|
123 |
+
|
124 |
+
{phang}
|
125 |
+
{opt level(#)}; see {help estimation options}.
|
126 |
+
|
127 |
+
{marker fmm_maximize}{...}
|
128 |
+
{dlgtab:Max options}
|
129 |
+
|
130 |
+
{phang}
|
131 |
+
{it:maximize_options}: {opt dif:ficult}, {opt tech:nique(algorithm_spec)},
|
132 |
+
{opt iter:ate(#)}, [{cmdab:no:}]{opt lo:g}, {opt tr:ace},
|
133 |
+
{opt grad:ient}, {opt showstep}, {opt hess:ian},
|
134 |
+
{opt shownr:tolerance}, {opt tol:erance(#)}, {opt ltol:erance(#)},
|
135 |
+
{opt gtol:erance(#)}, {opt nrtol:erance(#)}, {opt nonrtol:erance},
|
136 |
+
{opt fr:om(init_specs)}; see {help maximize} are standard {help ml} options.{p_end}
|
137 |
+
|
138 |
+
|
139 |
+
{phang}
|
140 |
+
{opt sh:ift(#)} generates alternative starting values by systematically
|
141 |
+
shifting some values from the default algorithm by the proportion {opt #}.{p_end}
|
142 |
+
|
143 |
+
|
144 |
+
{phang}
|
145 |
+
{opt se:arch(spec)} {it:spec} may be {opt on} or {opt off} and specifies whether
|
146 |
+
{help ml}'s initial search algorithm is used. The default is {opt off}.{p_end}
|
147 |
+
|
148 |
+
{phang}
|
149 |
+
Because finite mixture models have complicated likelihood functions,
|
150 |
+
{opt shift(#)}, {opt search(spec)}, {opt dif:ficult} and {opt from(init_specs)}
|
151 |
+
may be useful choices if the default setup fails. The other options are seldom
|
152 |
+
used.{p_end}
|
153 |
+
|
154 |
+
|
155 |
+
{title:Remarks}
|
156 |
+
|
157 |
+
{pstd}
|
158 |
+
If {opt components(2)} is specified, default starting values are specified using
|
159 |
+
the parameters from the associate degenerate mixture model. In order to take
|
160 |
+
advantage of the built-in algorithms for specifying starting values for models
|
161 |
+
with {it #} components, ({it #}>2), the user must estimate models sequentially
|
162 |
+
{it #}=2. This is the preferred estimation approach. But {cmd:fmm} will not
|
163 |
+
check for reasonableness of the prior {cmd:fmm} estimates, so proceed
|
164 |
+
carefully. Otherwise, {cmd:fmm} expects the user to specify starting values
|
165 |
+
using the {opt from(init_specs)} option.{p_end}
|
166 |
+
|
167 |
+
{pstd}
|
168 |
+
The available component densities and the associated conditional means are
|
169 |
+
|
170 |
+
{tab}Density {col 30} {cmd:fmm} option {col 50} cond. mean
|
171 |
+
{tab}{hline 70}
|
172 |
+
{tab}Gamma {col 30} {cmd:density(gamma)} {col 50} alpha_j exp(xb_j)
|
173 |
+
{tab}Lognormal {col 30} {cmd:density(lognormal)} {col 50} exp(xb_j + 0.5 sigma_j^2)
|
174 |
+
{tab}Negative Binomial-1 {col 30} {cmd:density(negbin1)} {col 50} exp(xb_j)
|
175 |
+
{tab}Negative Binomial-2 {col 30} {cmd:density(negbin2)} {col 50} exp(xb_j)
|
176 |
+
{tab}Normal(Gaussian) {col 30} {cmd:density(normal)} {col 50} xb_j
|
177 |
+
{tab}Poisson {col 30} {cmd:density(poisson)} {col 50} exp(xb_j)
|
178 |
+
{tab}Student-t {col 30} {cmd:density(studentt)} {col 50} xb_j
|
179 |
+
|
180 |
+
{pstd}
|
181 |
+
Note that {cmd:fmm} has not been updated to accommodate factor variables.
|
182 |
+
|
183 |
+
|
184 |
+
{title:Saved results}
|
185 |
+
|
186 |
+
{pstd}In addition to standard results saved by maximum likelihood procedures
|
187 |
+
in {opt e()}, {cmd:fmm} saves the following scalars:
|
188 |
+
|
189 |
+
{tab}{opt e(parname_est)} parameter estimate
|
190 |
+
{tab}{opt e(parname_se)} standard error of estimate
|
191 |
+
|
192 |
+
{pstd}where {it:parname} denotes either a scale parameter or a mixing
|
193 |
+
probability parameter.
|
194 |
+
|
195 |
+
|
196 |
+
{title:Examples}
|
197 |
+
|
198 |
+
{pstd}Mixture of normals
|
199 |
+
|
200 |
+
{phang}{stata "webuse womenwk, clear" : . webuse womenwk, clear}
|
201 |
+
|
202 |
+
{phang}{stata "fmm wagefull educ age married, mix(normal) comp(2)" : . fmm wagefull educ age married, mix(normal) comp(2)}
|
203 |
+
|
204 |
+
|
205 |
+
{pstd}Mixture of Negative Binomials (Type 2)
|
206 |
+
|
207 |
+
{phang}{stata "webuse medpar, clear" : . webuse medpar, clear}
|
208 |
+
|
209 |
+
{phang}{stata "gen los0 = los - 1" : . gen los0 = los - 1}
|
210 |
+
|
211 |
+
{phang}{stata "fmm los0 died hmo type2-type3, mix(negbin2) comp(2)" : . fmm exlos died hmo type2-type3, mix(negbin2) comp(2) comp(2)}
|
212 |
+
|
213 |
+
|
214 |
+
{title:References}
|
215 |
+
|
216 |
+
{p 4 8 2}Conway, K. and P. Deb, (2005), Is Prenatal Care Really Ineffective?
|
217 |
+
Or, is the 'Devil' in the Distribution?, {it:Journal of Health Economics},
|
218 |
+
24, 489-513.
|
219 |
+
|
220 |
+
{p 4 8 2}Deb, P. and P. K. Trivedi (1997), Demand for Medical Care by
|
221 |
+
the Elderly: A Finite Mixture Approach, {it:Journal of Applied Econometrics},
|
222 |
+
12, 313-326.
|
223 |
+
|
224 |
+
{p 4 8 2}McLachlan, G.J., and D. Peel (2000), {it:Finite Mixture Models},
|
225 |
+
New York: John Wiley.
|
226 |
+
|
227 |
+
{p 4 8 2}Titterington, D.M., A.F.M. Smith and U.E. Makow (1985),
|
228 |
+
{it:Statistical Analysis of Finite Mixture Distributions}, New York: John Wiley, 1985.
|
229 |
+
|
230 |
+
|
231 |
+
{title:Author}
|
232 |
+
|
233 |
+
{phang}Partha Deb, Hunter College and the Graduate Center, City University of New York, USA{p_end}
|
234 |
+
{phang}[email protected]{p_end}
|
235 |
+
|
236 |
+
|
237 |
+
{title:Also see}
|
238 |
+
|
239 |
+
{psee}
|
240 |
+
Online: {help fmm postestimation}{p_end}
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_gamma_lf.ado
ADDED
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.1 24apr2007
|
4 |
+
* version 1.0.0 06mar2007
|
5 |
+
|
6 |
+
program fmm_gamma_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_exb `"`L_exb' exb`i'"'
|
12 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
13 |
+
local L_pr `"`L_pr' pr`i'"'
|
14 |
+
local L_lalp `"`L_lalp' lnalpha`i'"'
|
15 |
+
local L_alp `"`L_alp' alpha`i'"'
|
16 |
+
local L_gb `"`L_gb' gb`i'"'
|
17 |
+
local L_gs `"`L_gs' gs`i'"'
|
18 |
+
}
|
19 |
+
|
20 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
21 |
+
local L_gL `"`L_gL' gL`i'"'
|
22 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
23 |
+
local L_h `"`L_h' h`i'`j'"'
|
24 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
forvalues i = 1/`=$fmm_components-1' {
|
29 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
30 |
+
forvalues j = 1/`=$fmm_components-1' {
|
31 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
// model arguments and temporary variables
|
36 |
+
args todo b lnf g negH `L_gL'
|
37 |
+
tempname `L_xb' `L_exb' `L_fxb' `L_lalp' `L_alp' `L_lpr' `L_pr' ///
|
38 |
+
den prob gi `L_gb' `L_ga' `L_gs' hij `L_h' `L_nh'
|
39 |
+
|
40 |
+
// set up equations
|
41 |
+
forvalues i=1/$fmm_components {
|
42 |
+
mleval `xb`i'' = `b', eq(`i')
|
43 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
44 |
+
mleval `lnalpha`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
45 |
+
qui gen double `alpha`i'' = exp(`lnalpha`i'')
|
46 |
+
}
|
47 |
+
|
48 |
+
qui gen double `den' = 1
|
49 |
+
forvalues i=1/`=$fmm_components-1' {
|
50 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
51 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
52 |
+
}
|
53 |
+
|
54 |
+
forvalues i=1/`=$fmm_components-1' {
|
55 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
56 |
+
}
|
57 |
+
|
58 |
+
qui gen double `pr$fmm_components' = 1
|
59 |
+
forvalues i=1/`=$fmm_components-1' {
|
60 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
// calculate the likelihood function
|
65 |
+
qui gen double `prob' = 0
|
66 |
+
forvalues i=1/$fmm_components {
|
67 |
+
qui gen double `fxb`i'' = gammaden(`alpha`i'',`exb`i'',0,$ML_y)
|
68 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
69 |
+
}
|
70 |
+
|
71 |
+
mlsum `lnf' = ln(`prob')
|
72 |
+
|
73 |
+
|
74 |
+
// CALCULATE GRADIENT TERMS
|
75 |
+
// gradient bi
|
76 |
+
forvalues i = 1/$fmm_components {
|
77 |
+
qui gen double `gb`i'' = -`alpha`i'' + $ML_y/`exb`i'' // density specific
|
78 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
79 |
+
}
|
80 |
+
|
81 |
+
// gradient prj
|
82 |
+
forvalues j = 1/`=$fmm_components-1' {
|
83 |
+
local m = `=$fmm_components+`j''
|
84 |
+
qui replace `gL`m'' = 0
|
85 |
+
forvalues k = 1/`=$fmm_components-1' {
|
86 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
87 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
88 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
// gradient alphai
|
93 |
+
forvalues i=1/$fmm_components {
|
94 |
+
local k = `=2*$fmm_components-1+`i''
|
95 |
+
qui gen double `gs`i'' = (-digamma(`alpha`i'') - `xb`i'' ///
|
96 |
+
+ log($ML_y))*`alpha`i'' // density specific
|
97 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
98 |
+
}
|
99 |
+
|
100 |
+
// collect gradient terms into vector
|
101 |
+
local np = colsof(`b')
|
102 |
+
local c 1
|
103 |
+
matrix `g' = J(1,`np',0)
|
104 |
+
|
105 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
106 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
107 |
+
matrix `g'[1,`c'] = `gi'
|
108 |
+
local c = `c' + colsof(`gi')
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
// CALCULATE HESSIAN TERMS
|
113 |
+
// hessian - b terms
|
114 |
+
local c 1
|
115 |
+
qui gen double `hij' = .
|
116 |
+
forvalues i = 1/$fmm_components {
|
117 |
+
// hessian (bi,bi)
|
118 |
+
qui replace `hij' = -$ML_y/`exb`i'' // density specific
|
119 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
120 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
121 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
122 |
+
// hessian (bi,bj)
|
123 |
+
if (`i'<$fmm_components) {
|
124 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
125 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
126 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
// hessian (bi,prj)
|
131 |
+
if (`i'<$fmm_components) {
|
132 |
+
forvalues j = 1/`=$fmm_components-1' {
|
133 |
+
local m = `=$fmm_components+`j''
|
134 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
135 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
136 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
137 |
+
}
|
138 |
+
}
|
139 |
+
else {
|
140 |
+
forvalues j = 1/`=$fmm_components-1' {
|
141 |
+
local m = `=$fmm_components+`j''
|
142 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
143 |
+
forvalues k = 1/`=$fmm_components-1' {
|
144 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
145 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
146 |
+
}
|
147 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
// hessian (bi,alpha)
|
152 |
+
forvalues j = 1/$fmm_components {
|
153 |
+
local k = `=2*$fmm_components-1+`j''
|
154 |
+
// hessian (bi,alphai)
|
155 |
+
if (`i'==`j') {
|
156 |
+
qui replace `hij' = -`alpha`j'' // density specific
|
157 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
158 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
159 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
160 |
+
}
|
161 |
+
else {
|
162 |
+
// hessian (bi,alphaj)
|
163 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
164 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
// hessian - pr terms
|
170 |
+
// hessian (prj,pri)
|
171 |
+
forvalues i = 1/`=$fmm_components-1' {
|
172 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
173 |
+
local m = `=$fmm_components+`i''
|
174 |
+
local n = `=$fmm_components+`j''
|
175 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
176 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
177 |
+
forvalues k = 1/`=$fmm_components-1' {
|
178 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
179 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
180 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
181 |
+
}
|
182 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
// hessian - alpha terms
|
187 |
+
forvalues i = 1/$fmm_components {
|
188 |
+
// hessian w.r.t. alphai
|
189 |
+
local m = `=2*$fmm_components-1+`i''
|
190 |
+
qui replace `hij' = (-digamma(`alpha`i'') - `xb`i'' + log($ML_y) ///
|
191 |
+
- trigamma(`alpha`i'')*`alpha`i'')*`alpha`i'' // density specific
|
192 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
193 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
194 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
195 |
+
// hessian w.r.t. alphaj (cross partials)
|
196 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
197 |
+
local n = `=2*$fmm_components-1+`j''
|
198 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
199 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
200 |
+
}
|
201 |
+
|
202 |
+
// hessian (alphai,prj)
|
203 |
+
if (`i'<$fmm_components) {
|
204 |
+
forvalues j = 1/`=$fmm_components-1' {
|
205 |
+
local n = `=2*$fmm_components-1+`i''
|
206 |
+
local m = `=$fmm_components+`j''
|
207 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
208 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
209 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
210 |
+
}
|
211 |
+
}
|
212 |
+
else {
|
213 |
+
forvalues j = 1/`=$fmm_components-1' {
|
214 |
+
local n = `=2*$fmm_components-1+`i''
|
215 |
+
local m = `=$fmm_components+`j''
|
216 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
217 |
+
forvalues k = 1/`=$fmm_components-1' {
|
218 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
219 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
220 |
+
}
|
221 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
222 |
+
}
|
223 |
+
}
|
224 |
+
}
|
225 |
+
|
226 |
+
// collect hessian terms into matrix
|
227 |
+
local np = colsof(`b')
|
228 |
+
local r 1
|
229 |
+
matrix `negH' = J(`np',`np',0)
|
230 |
+
|
231 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
232 |
+
local c = `r'
|
233 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
234 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
235 |
+
if (`j'>`i') {
|
236 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
237 |
+
}
|
238 |
+
local c = `c' + colsof(`nh`i'`j'')
|
239 |
+
}
|
240 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
241 |
+
}
|
242 |
+
|
243 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_gamma_p.ado
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.1 29jul2011
|
4 |
+
* version 2.0.0 27aug2008
|
5 |
+
* version 1.1.0 12jul2007
|
6 |
+
* version 1.0.0 06mar2007
|
7 |
+
|
8 |
+
program fmm_gamma_p
|
9 |
+
version 9.2
|
10 |
+
|
11 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
12 |
+
|
13 |
+
syntax newvarname [if] [in] [, * ]
|
14 |
+
|
15 |
+
forvalues i=1/$fmm_components {
|
16 |
+
local L_exb `"`L_exb' exb`i'"'
|
17 |
+
local L_pr `"`L_pr' pr`i'"'
|
18 |
+
local L_lod `"`L_lod' lnalpha`i'"'
|
19 |
+
local L_od `"`L_od' alpha`i'"'
|
20 |
+
}
|
21 |
+
forvalues i=1/`=$fmm_components-1' {
|
22 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
23 |
+
}
|
24 |
+
|
25 |
+
tempvar `L_exb' `L_lpr' `L_pr' `L_lod' `L_od' den
|
26 |
+
|
27 |
+
forvalues i=1/$fmm_components {
|
28 |
+
qui _predict `typlist' `exb`i'' `if' `in', equation(component`i')
|
29 |
+
qui replace `exb`i'' = exp(`exb`i'')
|
30 |
+
qui _predict double `lnalpha`i'' `if' `in', equation(lnalpha`i')
|
31 |
+
qui gen double `alpha`i'' = exp(`lnalpha`i'')
|
32 |
+
}
|
33 |
+
|
34 |
+
qui gen double `den' = 1
|
35 |
+
forvalues i=1/`=$fmm_components-1' {
|
36 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
37 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
38 |
+
}
|
39 |
+
|
40 |
+
forvalues i=1/`=$fmm_components-1' {
|
41 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
42 |
+
}
|
43 |
+
|
44 |
+
qui gen double `pr$fmm_components' = 1
|
45 |
+
forvalues i=1/`=$fmm_components-1' {
|
46 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
47 |
+
}
|
48 |
+
|
49 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
50 |
+
gen `typlist' `varlist' `if' `in' = 0
|
51 |
+
local i = substr("`equation'",-1,1)
|
52 |
+
qui replace `varlist' = `alpha`i'' * `exb`i''
|
53 |
+
label variable `varlist' "predicted mean: `equation'"
|
54 |
+
exit
|
55 |
+
}
|
56 |
+
|
57 |
+
if "`equation'" == "" & "`prior'" == "" & "`posterior'" == "" {
|
58 |
+
gen `typlist' `varlist' `if' `in' = 0
|
59 |
+
forvalues i=1/$fmm_components {
|
60 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `alpha`i'' * `exb`i''
|
61 |
+
}
|
62 |
+
label variable `varlist' "predicted mean"
|
63 |
+
exit
|
64 |
+
}
|
65 |
+
|
66 |
+
if "`prior'" == "prior" {
|
67 |
+
local i = substr("`equation'",-1,1)
|
68 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
69 |
+
label variable `varlist' "prior probability: `equation'"
|
70 |
+
exit
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
if "`posterior'" == "posterior" {
|
75 |
+
tempvar prob probcomponent
|
76 |
+
|
77 |
+
local fmm_y = e(depvar)
|
78 |
+
qui gen double `prob' = 0
|
79 |
+
forvalues i=1/$fmm_components {
|
80 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
81 |
+
* gammaden(`alpha`i'',`exb`i'',0,`fmm_y')
|
82 |
+
if "`equation'"=="component`i'" {
|
83 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
84 |
+
* gammaden(`alpha`i'',`exb`i'',0,`fmm_y')
|
85 |
+
}
|
86 |
+
}
|
87 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
88 |
+
label variable `varlist' "posterior probability: `equation'"
|
89 |
+
exit
|
90 |
+
}
|
91 |
+
|
92 |
+
end
|
93 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_lognormal_lf.ado
ADDED
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.0 05sep2011
|
4 |
+
|
5 |
+
program fmm_lognormal_lf
|
6 |
+
version 9.2
|
7 |
+
|
8 |
+
forvalues i = 1/$fmm_components {
|
9 |
+
local L_xb `"`L_xb' xb`i'"'
|
10 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
11 |
+
local L_pr `"`L_pr' pr`i'"'
|
12 |
+
local L_z `"`L_z' z`i'"'
|
13 |
+
local L_lsig `"`L_lsig' lnsigma`i'"'
|
14 |
+
local L_sig `"`L_sig' sigma`i'"'
|
15 |
+
local L_gb `"`L_gb' gb`i'"'
|
16 |
+
local L_gs `"`L_gs' gs`i'"'
|
17 |
+
}
|
18 |
+
|
19 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
20 |
+
local L_gL `"`L_gL' gL`i'"'
|
21 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
22 |
+
local L_h `"`L_h' h`i'`j'"'
|
23 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
forvalues i = 1/`=$fmm_components-1' {
|
28 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
29 |
+
forvalues j = 1/`=$fmm_components-1' {
|
30 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
// model arguments and temporary variables
|
35 |
+
args todo b lnf g negH `L_gL'
|
36 |
+
tempname `L_xb' `L_fxb' `L_lsig' `L_sig' `L_lpr' `L_pr' `L_z' ///
|
37 |
+
den prob gi `L_gb' `L_ga' `L_gs' hij `L_h' `L_nh'
|
38 |
+
|
39 |
+
// set up equations
|
40 |
+
forvalues i=1/$fmm_components {
|
41 |
+
mleval `xb`i'' = `b', eq(`i')
|
42 |
+
mleval `lnsigma`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
43 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
44 |
+
}
|
45 |
+
|
46 |
+
qui gen double `den' = 1
|
47 |
+
forvalues i=1/`=$fmm_components-1' {
|
48 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
49 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
50 |
+
}
|
51 |
+
|
52 |
+
forvalues i=1/`=$fmm_components-1' {
|
53 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
54 |
+
}
|
55 |
+
|
56 |
+
qui gen double `pr$fmm_components' = 1
|
57 |
+
forvalues i=1/`=$fmm_components-1' {
|
58 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
// calculate the likelihood function
|
63 |
+
qui gen double `prob' = 0
|
64 |
+
forvalues i=1/$fmm_components {
|
65 |
+
qui gen double `z`i'' = .
|
66 |
+
qui gen double `fxb`i'' = normalden(ln($ML_y),`xb`i'',`sigma`i'') / $ML_y
|
67 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
68 |
+
}
|
69 |
+
|
70 |
+
mlsum `lnf' = ln(`prob')
|
71 |
+
|
72 |
+
|
73 |
+
// CALCULATE GRADIENT TERMS
|
74 |
+
// gradient bi
|
75 |
+
forvalues i = 1/$fmm_components {
|
76 |
+
qui replace `z`i'' = (ln($ML_y)-`xb`i'')/`sigma`i''
|
77 |
+
qui gen double `gb`i'' = `z`i''/`sigma`i'' // density specific
|
78 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
79 |
+
}
|
80 |
+
|
81 |
+
// gradient prj
|
82 |
+
forvalues j = 1/`=$fmm_components-1' {
|
83 |
+
local m = `=$fmm_components+`j''
|
84 |
+
qui replace `gL`m'' = 0
|
85 |
+
forvalues k = 1/`=$fmm_components-1' {
|
86 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
87 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
88 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
// gradient sigmai
|
93 |
+
forvalues i=1/$fmm_components {
|
94 |
+
local k = `=2*$fmm_components-1+`i''
|
95 |
+
qui gen double `gs`i'' = `z`i''*`z`i''-1 // density specific
|
96 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
97 |
+
}
|
98 |
+
|
99 |
+
// collect gradient terms into vector
|
100 |
+
local np = colsof(`b')
|
101 |
+
local c 1
|
102 |
+
matrix `g' = J(1,`np',0)
|
103 |
+
|
104 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
105 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
106 |
+
matrix `g'[1,`c'] = `gi'
|
107 |
+
local c = `c' + colsof(`gi')
|
108 |
+
}
|
109 |
+
|
110 |
+
|
111 |
+
// CALCULATE HESSIAN TERMS
|
112 |
+
// hessian - b terms
|
113 |
+
local c 1
|
114 |
+
qui gen double `hij' = .
|
115 |
+
forvalues i = 1/$fmm_components {
|
116 |
+
// hessian (bi,bi)
|
117 |
+
qui replace `hij' = -1/(`sigma`i''^2) // density specific
|
118 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
119 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
120 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
121 |
+
// hessian (bi,bj)
|
122 |
+
if (`i'<$fmm_components) {
|
123 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
124 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
125 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
// hessian (bi,prj)
|
130 |
+
if (`i'<$fmm_components) {
|
131 |
+
forvalues j = 1/`=$fmm_components-1' {
|
132 |
+
local m = `=$fmm_components+`j''
|
133 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
134 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
135 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
136 |
+
}
|
137 |
+
}
|
138 |
+
else {
|
139 |
+
forvalues j = 1/`=$fmm_components-1' {
|
140 |
+
local m = `=$fmm_components+`j''
|
141 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
142 |
+
forvalues k = 1/`=$fmm_components-1' {
|
143 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
144 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
145 |
+
}
|
146 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
|
151 |
+
// hessian (bi,sigma)
|
152 |
+
forvalues j = 1/$fmm_components {
|
153 |
+
local k = `=2*$fmm_components-1+`j''
|
154 |
+
// hessian (bi,sigmai)
|
155 |
+
if (`i'==`j') {
|
156 |
+
qui replace `hij' = -2*`z`j''/`sigma`j'' // density specific
|
157 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
158 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
159 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
160 |
+
}
|
161 |
+
else {
|
162 |
+
// hessian (bi,sigmaj)
|
163 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
164 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
// hessian - pr terms
|
170 |
+
// hessian (prj,pri)
|
171 |
+
forvalues i = 1/`=$fmm_components-1' {
|
172 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
173 |
+
local m = `=$fmm_components+`i''
|
174 |
+
local n = `=$fmm_components+`j''
|
175 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
176 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
177 |
+
forvalues k = 1/`=$fmm_components-1' {
|
178 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
179 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
180 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
181 |
+
}
|
182 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
|
187 |
+
// hessian - sigma terms
|
188 |
+
forvalues i = 1/$fmm_components {
|
189 |
+
// hessian w.r.t. sigmai
|
190 |
+
local m = `=2*$fmm_components-1+`i''
|
191 |
+
qui replace `hij' = -2*(`z`i''^2) // density specific
|
192 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
193 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
194 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
195 |
+
// hessian w.r.t. sigmaj (cross partials)
|
196 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
197 |
+
local n = `=2*$fmm_components-1+`j''
|
198 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
199 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
200 |
+
}
|
201 |
+
|
202 |
+
// hessian (sigmai,prj)
|
203 |
+
if (`i'<$fmm_components) {
|
204 |
+
forvalues j = 1/`=$fmm_components-1' {
|
205 |
+
local n = `=2*$fmm_components-1+`i''
|
206 |
+
local m = `=$fmm_components+`j''
|
207 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
208 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
209 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
210 |
+
}
|
211 |
+
}
|
212 |
+
else {
|
213 |
+
forvalues j = 1/`=$fmm_components-1' {
|
214 |
+
local n = `=2*$fmm_components-1+`i''
|
215 |
+
local m = `=$fmm_components+`j''
|
216 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
217 |
+
forvalues k = 1/`=$fmm_components-1' {
|
218 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
219 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
220 |
+
}
|
221 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
222 |
+
}
|
223 |
+
}
|
224 |
+
}
|
225 |
+
|
226 |
+
// collect hessian terms into matrix
|
227 |
+
local np = colsof(`b')
|
228 |
+
local r 1
|
229 |
+
matrix `negH' = J(`np',`np',0)
|
230 |
+
|
231 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
232 |
+
local c = `r'
|
233 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
234 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
235 |
+
if (`j'>`i') {
|
236 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
237 |
+
}
|
238 |
+
local c = `c' + colsof(`nh`i'`j'')
|
239 |
+
}
|
240 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
241 |
+
}
|
242 |
+
|
243 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_lognormal_p.ado
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.0 05sep2011
|
4 |
+
|
5 |
+
program fmm_lognormal_p
|
6 |
+
version 9.2
|
7 |
+
|
8 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
9 |
+
|
10 |
+
syntax newvarname [if] [in] [, * ]
|
11 |
+
|
12 |
+
forvalues i=1/$fmm_components {
|
13 |
+
local L_xb `"`L_xb' xb`i'"'
|
14 |
+
local L_pr `"`L_pr' pr`i'"'
|
15 |
+
local L_lod `"`L_lod' lnsigma`i'"'
|
16 |
+
local L_od `"`L_od' sigma`i'"'
|
17 |
+
}
|
18 |
+
forvalues i=1/`=$fmm_components-1' {
|
19 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
20 |
+
}
|
21 |
+
|
22 |
+
tempvar `L_xb' `L_lpr' `L_pr' `L_lod' `L_od' den
|
23 |
+
|
24 |
+
forvalues i=1/$fmm_components {
|
25 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
26 |
+
qui _predict `typlist' `lnsigma`i'' `if' `in', equation(lnsigma`i')
|
27 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
28 |
+
}
|
29 |
+
|
30 |
+
qui gen double `den' = 1
|
31 |
+
forvalues i=1/`=$fmm_components-1' {
|
32 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
33 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
34 |
+
}
|
35 |
+
|
36 |
+
forvalues i=1/`=$fmm_components-1' {
|
37 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
38 |
+
}
|
39 |
+
|
40 |
+
qui gen double `pr$fmm_components' = 1
|
41 |
+
forvalues i=1/`=$fmm_components-1' {
|
42 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
43 |
+
}
|
44 |
+
|
45 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
46 |
+
gen `typlist' `varlist' `if' `in' = 0
|
47 |
+
local i = substr("`equation'",-1,1)
|
48 |
+
qui replace `varlist' = exp(`xb`i'' + 0.5*(`sigma`i'')^2)
|
49 |
+
label variable `varlist' "predicted mean: `equation'"
|
50 |
+
exit
|
51 |
+
}
|
52 |
+
|
53 |
+
if "`equation'" == "" & "`prior'" == "" & "`posterior'" == "" {
|
54 |
+
gen `typlist' `varlist' `if' `in' = 0
|
55 |
+
forvalues i=1/$fmm_components {
|
56 |
+
qui replace `varlist' = `varlist' + `pr`i'' * ///
|
57 |
+
exp(`xb`i'' + 0.5*(`sigma`i'')^2)
|
58 |
+
}
|
59 |
+
label variable `varlist' "predicted mean"
|
60 |
+
exit
|
61 |
+
}
|
62 |
+
|
63 |
+
if "`prior'" == "prior" {
|
64 |
+
local i = substr("`equation'",-1,1)
|
65 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
66 |
+
label variable `varlist' "prior probability: `equation'"
|
67 |
+
exit
|
68 |
+
}
|
69 |
+
|
70 |
+
if "`posterior'" == "posterior" {
|
71 |
+
tempvar prob probcomponent
|
72 |
+
|
73 |
+
local fmm_y = e(depvar)
|
74 |
+
qui gen double `prob' = 0
|
75 |
+
forvalues i=1/$fmm_components {
|
76 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
77 |
+
* normalden(ln(`fmm_y'),`xb`i'',`sigma`i'') / `fmm_y'
|
78 |
+
if "`equation'"=="component`i'" {
|
79 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
80 |
+
* normalden(ln(`fmm_y'),`xb`i'',`sigma`i'') / `fmm_y'
|
81 |
+
}
|
82 |
+
}
|
83 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
84 |
+
label variable `varlist' "posterior probability: `equation'"
|
85 |
+
exit
|
86 |
+
}
|
87 |
+
|
88 |
+
end
|
89 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin1_lf.ado
ADDED
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.1 24apr2007
|
4 |
+
* version 1.0.0 06mar2007
|
5 |
+
|
6 |
+
program fmm_negbin1_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_exb `"`L_exb' exb`i'"'
|
12 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
13 |
+
local L_pr `"`L_pr' pr`i'"'
|
14 |
+
local L_ldel `"`L_ldel' lndelta`i'"'
|
15 |
+
local L_del `"`L_del' delta`i'"'
|
16 |
+
local L_psi `"`L_psi' psi`i'"'
|
17 |
+
local L_phi `"`L_phi' phi`i'"'
|
18 |
+
local L_gb `"`L_gb' gb`i'"'
|
19 |
+
local L_gs `"`L_gs' gs`i'"'
|
20 |
+
local L_hterm `"`L_hterm' hterm`i'"'
|
21 |
+
}
|
22 |
+
|
23 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
24 |
+
local L_gL `"`L_gL' gL`i'"'
|
25 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
26 |
+
local L_h `"`L_h' h`i'`j'"'
|
27 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
forvalues i = 1/`=$fmm_components-1' {
|
32 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
33 |
+
forvalues j = 1/`=$fmm_components-1' {
|
34 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
// model arguments and temporary variables
|
39 |
+
args todo b lnf g negH `L_gL'
|
40 |
+
tempname `L_xb' `L_exb' `L_fxb' `L_ldel' `L_del' `L_psi' `L_lpr' `L_pr' ///
|
41 |
+
den prob `L_phi' gi `L_gb' `L_ga' `L_gs' hterm hij `L_h' `L_nh' ///
|
42 |
+
`L_hterm'
|
43 |
+
|
44 |
+
// set up equations
|
45 |
+
forvalues i=1/$fmm_components {
|
46 |
+
mleval `xb`i'' = `b', eq(`i')
|
47 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
48 |
+
mleval `lndelta`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
49 |
+
qui gen double `delta`i'' = exp(`lndelta`i'')
|
50 |
+
qui gen double `psi`i'' = `exb`i'' / `delta`i''
|
51 |
+
qui gen double `phi`i'' = ln(1+`delta`i'')
|
52 |
+
}
|
53 |
+
|
54 |
+
qui gen double `den' = 1
|
55 |
+
forvalues i=1/`=$fmm_components-1' {
|
56 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
57 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
58 |
+
}
|
59 |
+
|
60 |
+
forvalues i=1/`=$fmm_components-1' {
|
61 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
62 |
+
}
|
63 |
+
|
64 |
+
qui gen double `pr$fmm_components' = 1
|
65 |
+
forvalues i=1/`=$fmm_components-1' {
|
66 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
// calculate the likelihood function
|
71 |
+
qui gen double `prob' = 0
|
72 |
+
forvalues i=1/$fmm_components {
|
73 |
+
qui gen double `fxb`i'' = exp(lngamma($ML_y+`psi`i'') ///
|
74 |
+
- lngamma($ML_y+1) - lngamma(`psi`i'') + `lndelta`i''*$ML_y ///
|
75 |
+
- ($ML_y+`psi`i'')*`phi`i'')
|
76 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
77 |
+
}
|
78 |
+
|
79 |
+
mlsum `lnf' = ln(`prob')
|
80 |
+
|
81 |
+
|
82 |
+
// CALCULATE GRADIENT TERMS
|
83 |
+
// gradient bi
|
84 |
+
forvalues i = 1/$fmm_components {
|
85 |
+
qui gen double `gb`i'' = `psi`i''*(digamma($ML_y+`psi`i'') ///
|
86 |
+
- digamma(`psi`i'') - `phi`i'') // density specific
|
87 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
88 |
+
}
|
89 |
+
|
90 |
+
// gradient prj
|
91 |
+
forvalues j = 1/`=$fmm_components-1' {
|
92 |
+
local m = `=$fmm_components+`j''
|
93 |
+
qui replace `gL`m'' = 0
|
94 |
+
forvalues k = 1/`=$fmm_components-1' {
|
95 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
96 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
97 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
// gradient deltai
|
102 |
+
forvalues i=1/$fmm_components {
|
103 |
+
local k = `=2*$fmm_components-1+`i''
|
104 |
+
qui gen double `gs`i'' = -($ML_y+`psi`i'')*`delta`i''/(1+`delta`i'') ///
|
105 |
+
+ $ML_y - `gb`i'' // density specific
|
106 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
107 |
+
}
|
108 |
+
|
109 |
+
// collect gradient terms into vector
|
110 |
+
local np = colsof(`b')
|
111 |
+
local c 1
|
112 |
+
matrix `g' = J(1,`np',0)
|
113 |
+
|
114 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
115 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
116 |
+
matrix `g'[1,`c'] = `gi'
|
117 |
+
local c = `c' + colsof(`gi')
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
// CALCULATE HESSIAN TERMS
|
122 |
+
// hessian - b terms
|
123 |
+
local c 1
|
124 |
+
qui gen double `hij' = .
|
125 |
+
forvalues i = 1/$fmm_components {
|
126 |
+
// hessian (bi,bi)
|
127 |
+
qui gen double `hterm`i'' = `psi`i''*(digamma($ML_y+`psi`i'') ///
|
128 |
+
- digamma(`psi`i'') + `psi`i''*(trigamma($ML_y+`psi`i'') ///
|
129 |
+
- trigamma(`psi`i'')) - `phi`i'') // density specific
|
130 |
+
qui replace `hij' = `hterm`i''
|
131 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
132 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
133 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
134 |
+
// hessian (bi,bj)
|
135 |
+
if (`i'<$fmm_components) {
|
136 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
137 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
138 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
// hessian (bi,prj)
|
143 |
+
if (`i'<$fmm_components) {
|
144 |
+
forvalues j = 1/`=$fmm_components-1' {
|
145 |
+
local m = `=$fmm_components+`j''
|
146 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
147 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
148 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
149 |
+
}
|
150 |
+
}
|
151 |
+
else {
|
152 |
+
forvalues j = 1/`=$fmm_components-1' {
|
153 |
+
local m = `=$fmm_components+`j''
|
154 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
155 |
+
forvalues k = 1/`=$fmm_components-1' {
|
156 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
157 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
158 |
+
}
|
159 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
// hessian (bi,delta)
|
164 |
+
forvalues j = 1/$fmm_components {
|
165 |
+
local k = `=2*$fmm_components-1+`j''
|
166 |
+
// hessian (bi,deltai)
|
167 |
+
if (`i'==`j') {
|
168 |
+
qui replace `hij' = -`psi`i''*`delta`i''/(1+`delta`i'') - `hterm`i'' // density specific
|
169 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
170 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
171 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
172 |
+
}
|
173 |
+
else {
|
174 |
+
// hessian (bi,deltaj)
|
175 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
176 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
// hessian - pr terms
|
182 |
+
// hessian (prj,pri)
|
183 |
+
forvalues i = 1/`=$fmm_components-1' {
|
184 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
185 |
+
local m = `=$fmm_components+`i''
|
186 |
+
local n = `=$fmm_components+`j''
|
187 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
188 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
189 |
+
forvalues k = 1/`=$fmm_components-1' {
|
190 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
191 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
192 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
193 |
+
}
|
194 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
// hessian - delta terms
|
199 |
+
forvalues i = 1/$fmm_components {
|
200 |
+
// hessian w.r.t. deltai
|
201 |
+
local m = `=2*$fmm_components-1+`i''
|
202 |
+
qui replace `hij' = -`delta`i''*($ML_y-`psi`i''*(1+2*`delta`i'')) ///
|
203 |
+
/(1+`delta`i'')^2 + `hterm`i'' // density specific
|
204 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
205 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
206 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
207 |
+
// hessian w.r.t. deltaj (cross partials)
|
208 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
209 |
+
local n = `=2*$fmm_components-1+`j''
|
210 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
211 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
212 |
+
}
|
213 |
+
|
214 |
+
// hessian (deltai,prj)
|
215 |
+
if (`i'<$fmm_components) {
|
216 |
+
forvalues j = 1/`=$fmm_components-1' {
|
217 |
+
local n = `=2*$fmm_components-1+`i''
|
218 |
+
local m = `=$fmm_components+`j''
|
219 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
220 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
221 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
222 |
+
}
|
223 |
+
}
|
224 |
+
else {
|
225 |
+
forvalues j = 1/`=$fmm_components-1' {
|
226 |
+
local n = `=2*$fmm_components-1+`i''
|
227 |
+
local m = `=$fmm_components+`j''
|
228 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
229 |
+
forvalues k = 1/`=$fmm_components-1' {
|
230 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
231 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
232 |
+
}
|
233 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
// collect hessian terms into matrix
|
239 |
+
local np = colsof(`b')
|
240 |
+
local r 1
|
241 |
+
matrix `negH' = J(`np',`np',0)
|
242 |
+
|
243 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
244 |
+
local c = `r'
|
245 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
246 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
247 |
+
if (`j'>`i') {
|
248 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
249 |
+
}
|
250 |
+
local c = `c' + colsof(`nh`i'`j'')
|
251 |
+
}
|
252 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
253 |
+
}
|
254 |
+
|
255 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin1_p.ado
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.0 27aug2008
|
4 |
+
* version 1.1.0 12jul2007
|
5 |
+
* version 1.0.0 06mar2007
|
6 |
+
|
7 |
+
program fmm_negbin1_p
|
8 |
+
version 9.2
|
9 |
+
|
10 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
11 |
+
|
12 |
+
syntax newvarname [if] [in] [, * ]
|
13 |
+
|
14 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
15 |
+
_predict `typlist' `varlist' `if' `in', equation(`equation')
|
16 |
+
qui replace `varlist' = exp(`varlist')
|
17 |
+
label variable `varlist' "predicted mean: `equation'"
|
18 |
+
exit
|
19 |
+
}
|
20 |
+
|
21 |
+
if "`equation'" == "" | "`prior'" == "prior" | "`posterior'" == "posterior" {
|
22 |
+
|
23 |
+
forvalues i=1/$fmm_components {
|
24 |
+
local L_xb `"`L_xb' xb`i'"'
|
25 |
+
local L_exb `"`L_exb' exb`i'"'
|
26 |
+
local L_pr `"`L_pr' pr`i'"'
|
27 |
+
local L_lod `"`L_lod' lndelta`i'"'
|
28 |
+
local L_od `"`L_od' delta`i'"'
|
29 |
+
local L_psi `"`L_psi' psi`i'"'
|
30 |
+
local L_phi `"`L_phi' phi`i'"'
|
31 |
+
}
|
32 |
+
forvalues i=1/`=$fmm_components-1' {
|
33 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
34 |
+
}
|
35 |
+
|
36 |
+
tempvar `L_xb' `L_exb' `L_lpr' `L_pr' `L_lod' `L_od' `L_psi' `L_phi' den
|
37 |
+
|
38 |
+
forvalues i=1/$fmm_components {
|
39 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
40 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
41 |
+
qui _predict `typlist' `lndelta`i'' `if' `in', equation(lndelta`i')
|
42 |
+
qui gen double `delta`i'' = exp(`lndelta`i'')
|
43 |
+
qui gen double `psi`i'' = `exb`i'' / `delta`i''
|
44 |
+
qui gen double `phi`i'' = ln(1+`delta`i'')
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
qui gen double `den' = 1
|
49 |
+
forvalues i=1/`=$fmm_components-1' {
|
50 |
+
_predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
51 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
52 |
+
}
|
53 |
+
|
54 |
+
forvalues i=1/`=$fmm_components-1' {
|
55 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
56 |
+
}
|
57 |
+
|
58 |
+
qui gen double `pr$fmm_components' = 1
|
59 |
+
forvalues i=1/`=$fmm_components-1' {
|
60 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
if "`prior'" == "" & "`posterior'" == "" {
|
65 |
+
gen `typlist' `varlist' `if' `in' = 0
|
66 |
+
forvalues i=1/$fmm_components {
|
67 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `exb`i''
|
68 |
+
}
|
69 |
+
label variable `varlist' "predicted mean"
|
70 |
+
exit
|
71 |
+
}
|
72 |
+
|
73 |
+
if "`prior'" == "prior" {
|
74 |
+
local i = substr("`equation'",-1,1)
|
75 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
76 |
+
label variable `varlist' "prior probability: `equation'"
|
77 |
+
exit
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
if "`posterior'" == "posterior" {
|
82 |
+
tempvar prob probcomponent
|
83 |
+
|
84 |
+
local fmm_y = e(depvar)
|
85 |
+
qui gen double `prob' = 0
|
86 |
+
forvalues i=1/$fmm_components {
|
87 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
88 |
+
* exp(lngamma(`fmm_y'+`psi`i'') ///
|
89 |
+
- lngamma(`fmm_y'+1) - lngamma(`psi`i'') + `lndelta`i''*`fmm_y' ///
|
90 |
+
- (`fmm_y'+`psi`i'')*`phi`i'')
|
91 |
+
if "`equation'"=="component`i'" {
|
92 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
93 |
+
* exp(lngamma(`fmm_y'+`psi`i'') ///
|
94 |
+
- lngamma(`fmm_y'+1) - lngamma(`psi`i'') + `lndelta`i''*`fmm_y' ///
|
95 |
+
- (`fmm_y'+`psi`i'')*`phi`i'')
|
96 |
+
}
|
97 |
+
}
|
98 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
99 |
+
label variable `varlist' "posterior probability: `equation'"
|
100 |
+
exit
|
101 |
+
}
|
102 |
+
|
103 |
+
end
|
104 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin2_lf.ado
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.1 24apr2007
|
4 |
+
* version 1.0.0 06mar2007
|
5 |
+
|
6 |
+
program fmm_negbin2_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_exb `"`L_exb' exb`i'"'
|
12 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
13 |
+
local L_pr `"`L_pr' pr`i'"'
|
14 |
+
local L_lalp `"`L_lalp' lnalpha`i'"'
|
15 |
+
local L_alp `"`L_alp' alpha`i'"'
|
16 |
+
local L_psi `"`L_psi' psi`i'"'
|
17 |
+
local L_phi `"`L_phi' phi`i'"'
|
18 |
+
local L_gb `"`L_gb' gb`i'"'
|
19 |
+
local L_gs `"`L_gs' gs`i'"'
|
20 |
+
}
|
21 |
+
|
22 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
23 |
+
local L_gL `"`L_gL' gL`i'"'
|
24 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
25 |
+
local L_h `"`L_h' h`i'`j'"'
|
26 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
forvalues i = 1/`=$fmm_components-1' {
|
31 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
32 |
+
forvalues j = 1/`=$fmm_components-1' {
|
33 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
// model arguments and temporary variables
|
38 |
+
args todo b lnf g negH `L_gL'
|
39 |
+
tempname `L_xb' `L_exb' `L_fxb' `L_lalp' `L_alp' `L_psi' `L_lpr' `L_pr' ///
|
40 |
+
den prob `L_phi' gi `L_gb' `L_ga' `L_gs' hij `L_h' `L_nh'
|
41 |
+
|
42 |
+
// set up equations
|
43 |
+
forvalues i=1/$fmm_components {
|
44 |
+
mleval `xb`i'' = `b', eq(`i')
|
45 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
46 |
+
mleval `lnalpha`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
47 |
+
qui gen double `alpha`i'' = exp(`lnalpha`i'')
|
48 |
+
qui gen double `psi`i'' = 1 / `alpha`i''
|
49 |
+
qui gen double `phi`i'' = 1 / (1 + `alpha`i''*`exb`i'')
|
50 |
+
}
|
51 |
+
|
52 |
+
qui gen double `den' = 1
|
53 |
+
forvalues i=1/`=$fmm_components-1' {
|
54 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
55 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
56 |
+
}
|
57 |
+
|
58 |
+
forvalues i=1/`=$fmm_components-1' {
|
59 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
60 |
+
}
|
61 |
+
|
62 |
+
qui gen double `pr$fmm_components' = 1
|
63 |
+
forvalues i=1/`=$fmm_components-1' {
|
64 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
// calculate the likelihood function
|
69 |
+
qui gen double `prob' = 0
|
70 |
+
forvalues i=1/$fmm_components {
|
71 |
+
qui gen double `fxb`i'' = exp(lngamma(`psi`i''+$ML_y) - lngamma($ML_y+1) ///
|
72 |
+
- lngamma(`psi`i'') - `psi`i''*ln(1+exp(`xb`i''+`lnalpha`i'')) ///
|
73 |
+
- $ML_y*ln(1+exp(-`xb`i''-`lnalpha`i'')))
|
74 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
75 |
+
}
|
76 |
+
|
77 |
+
mlsum `lnf' = ln(`prob')
|
78 |
+
|
79 |
+
|
80 |
+
// CALCULATE GRADIENT TERMS
|
81 |
+
// gradient bi
|
82 |
+
forvalues i = 1/$fmm_components {
|
83 |
+
qui gen double `gb`i'' = ($ML_y-`exb`i'')*`phi`i'' // density specific
|
84 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
85 |
+
}
|
86 |
+
|
87 |
+
// gradient prj
|
88 |
+
forvalues j = 1/`=$fmm_components-1' {
|
89 |
+
local m = `=$fmm_components+`j''
|
90 |
+
qui replace `gL`m'' = 0
|
91 |
+
forvalues k = 1/`=$fmm_components-1' {
|
92 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
93 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
94 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
// gradient alphai
|
99 |
+
forvalues i=1/$fmm_components {
|
100 |
+
local k = `=2*$fmm_components-1+`i''
|
101 |
+
qui gen double `gs`i'' = `psi`i''*(digamma(`psi`i'') - digamma($ML_y+`psi`i'') ///
|
102 |
+
- ln(`phi`i'')) + `phi`i''*($ML_y-`exb`i'') // density specific
|
103 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
104 |
+
}
|
105 |
+
|
106 |
+
// collect gradient terms into vector
|
107 |
+
local np = colsof(`b')
|
108 |
+
local c 1
|
109 |
+
matrix `g' = J(1,`np',0)
|
110 |
+
|
111 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
112 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
113 |
+
matrix `g'[1,`c'] = `gi'
|
114 |
+
local c = `c' + colsof(`gi')
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
// CALCULATE HESSIAN TERMS
|
119 |
+
// hessian - b terms
|
120 |
+
local c 1
|
121 |
+
qui gen double `hij' = .
|
122 |
+
forvalues i = 1/$fmm_components {
|
123 |
+
// hessian (bi,bi)
|
124 |
+
qui replace `hij' = -`exb`i'' * `phi`i'' ///
|
125 |
+
*(`alpha`i''*`phi`i''*($ML_y-`exb`i'')+1) // density specific
|
126 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
127 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
128 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
129 |
+
// hessian (bi,bj)
|
130 |
+
if (`i'<$fmm_components) {
|
131 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
132 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
133 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
// hessian (bi,prj)
|
138 |
+
if (`i'<$fmm_components) {
|
139 |
+
forvalues j = 1/`=$fmm_components-1' {
|
140 |
+
local m = `=$fmm_components+`j''
|
141 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
142 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
143 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
144 |
+
}
|
145 |
+
}
|
146 |
+
else {
|
147 |
+
forvalues j = 1/`=$fmm_components-1' {
|
148 |
+
local m = `=$fmm_components+`j''
|
149 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
150 |
+
forvalues k = 1/`=$fmm_components-1' {
|
151 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
152 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
153 |
+
}
|
154 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
// hessian (bi,alpha)
|
159 |
+
forvalues j = 1/$fmm_components {
|
160 |
+
local k = `=2*$fmm_components-1+`j''
|
161 |
+
// hessian (bi,alphai)
|
162 |
+
if (`i'==`j') {
|
163 |
+
qui replace `hij' = -`alpha`j'' * `exb`j'' * `phi`j''^2 ///
|
164 |
+
* ($ML_y-`exb`j'') // density specific
|
165 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
166 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
167 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
168 |
+
}
|
169 |
+
else {
|
170 |
+
// hessian (bi,alphaj)
|
171 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
172 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
// hessian - pr terms
|
178 |
+
// hessian (prj,pri)
|
179 |
+
forvalues i = 1/`=$fmm_components-1' {
|
180 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
181 |
+
local m = `=$fmm_components+`i''
|
182 |
+
local n = `=$fmm_components+`j''
|
183 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
184 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
185 |
+
forvalues k = 1/`=$fmm_components-1' {
|
186 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
187 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
188 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
189 |
+
}
|
190 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
// hessian - alpha terms
|
195 |
+
forvalues i = 1/$fmm_components {
|
196 |
+
// hessian w.r.t. alphai
|
197 |
+
local m = `=2*$fmm_components-1+`i''
|
198 |
+
qui replace `hij' = -(`psi`i''*(digamma(`psi`i'') ///
|
199 |
+
- digamma($ML_y+`psi`i'') - ln(`phi`i'') ///
|
200 |
+
- `psi`i''*(trigamma($ML_y+`psi`i'') - trigamma(`psi`i''))) ///
|
201 |
+
+ `exb`i''*`phi`i''*(`alpha`i''*`phi`i''*($ML_y-`exb`i'')- 1)) // density specific
|
202 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
203 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
204 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
205 |
+
// hessian w.r.t. alphaj (cross partials)
|
206 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
207 |
+
local n = `=2*$fmm_components-1+`j''
|
208 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
209 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
210 |
+
}
|
211 |
+
|
212 |
+
// hessian (alphai,prj)
|
213 |
+
if (`i'<$fmm_components) {
|
214 |
+
forvalues j = 1/`=$fmm_components-1' {
|
215 |
+
local n = `=2*$fmm_components-1+`i''
|
216 |
+
local m = `=$fmm_components+`j''
|
217 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
218 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
219 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
220 |
+
}
|
221 |
+
}
|
222 |
+
else {
|
223 |
+
forvalues j = 1/`=$fmm_components-1' {
|
224 |
+
local n = `=2*$fmm_components-1+`i''
|
225 |
+
local m = `=$fmm_components+`j''
|
226 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
227 |
+
forvalues k = 1/`=$fmm_components-1' {
|
228 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
229 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
230 |
+
}
|
231 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
232 |
+
}
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
// collect hessian terms into matrix
|
237 |
+
local np = colsof(`b')
|
238 |
+
local r 1
|
239 |
+
matrix `negH' = J(`np',`np',0)
|
240 |
+
|
241 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
242 |
+
local c = `r'
|
243 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
244 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
245 |
+
if (`j'>`i') {
|
246 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
247 |
+
}
|
248 |
+
local c = `c' + colsof(`nh`i'`j'')
|
249 |
+
}
|
250 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
251 |
+
}
|
252 |
+
|
253 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_negbin2_p.ado
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.0 27aug2008
|
4 |
+
* version 1.1.0 12jul2007
|
5 |
+
* version 1.0.0 06mar2007
|
6 |
+
|
7 |
+
program fmm_negbin2_p
|
8 |
+
version 9.2
|
9 |
+
|
10 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
11 |
+
|
12 |
+
syntax newvarname [if] [in] [, * ]
|
13 |
+
|
14 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
15 |
+
_predict `typlist' `varlist' `if' `in', equation(`equation')
|
16 |
+
qui replace `varlist' = exp(`varlist')
|
17 |
+
label variable `varlist' "predicted mean: `equation'"
|
18 |
+
exit
|
19 |
+
}
|
20 |
+
|
21 |
+
if "`equation'" == "" | "`prior'" == "prior" | "`posterior'" == "posterior" {
|
22 |
+
|
23 |
+
forvalues i=1/$fmm_components {
|
24 |
+
local L_xb `"`L_xb' xb`i'"'
|
25 |
+
local L_exb `"`L_exb' exb`i'"'
|
26 |
+
local L_pr `"`L_pr' pr`i'"'
|
27 |
+
local L_lod `"`L_lod' lnalpha`i'"'
|
28 |
+
local L_od `"`L_od' alpha`i'"'
|
29 |
+
local L_psi `"`L_psi' psi`i'"'
|
30 |
+
local L_phi `"`L_phi' phi`i'"'
|
31 |
+
}
|
32 |
+
forvalues i=1/`=$fmm_components-1' {
|
33 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
34 |
+
}
|
35 |
+
|
36 |
+
tempvar `L_xb' `L_exb' `L_lpr' `L_pr' `L_lod' `L_od' `L_psi' `L_phi' den
|
37 |
+
|
38 |
+
forvalues i=1/$fmm_components {
|
39 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
40 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
41 |
+
qui _predict `typlist' `lnalpha`i'' `if' `in', equation(lnalpha`i')
|
42 |
+
qui gen double `alpha`i'' = exp(`lnalpha`i'')
|
43 |
+
qui gen double `psi`i'' = 1 / `alpha`i''
|
44 |
+
qui gen double `phi`i'' = 1 / (1 + `alpha`i''*`exb`i'')
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
qui gen double `den' = 1
|
49 |
+
forvalues i=1/`=$fmm_components-1' {
|
50 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
51 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
52 |
+
}
|
53 |
+
|
54 |
+
forvalues i=1/`=$fmm_components-1' {
|
55 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
56 |
+
}
|
57 |
+
|
58 |
+
qui gen double `pr$fmm_components' = 1
|
59 |
+
forvalues i=1/`=$fmm_components-1' {
|
60 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
if "`prior'" == "" & "`posterior'" == "" {
|
65 |
+
gen `typlist' `varlist' `if' `in' = 0
|
66 |
+
forvalues i=1/$fmm_components {
|
67 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `exb`i''
|
68 |
+
}
|
69 |
+
label variable `varlist' "predicted mean"
|
70 |
+
exit
|
71 |
+
}
|
72 |
+
|
73 |
+
if "`prior'" == "prior" {
|
74 |
+
local i = substr("`equation'",-1,1)
|
75 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
76 |
+
label variable `varlist' "prior probability: `equation'"
|
77 |
+
exit
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
if "`posterior'" == "posterior" {
|
82 |
+
tempvar prob probcomponent
|
83 |
+
|
84 |
+
local fmm_y = e(depvar)
|
85 |
+
qui gen double `prob' = 0
|
86 |
+
forvalues i=1/$fmm_components {
|
87 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
88 |
+
* exp(lngamma(`psi`i''+`fmm_y') - lngamma(`fmm_y'+1) ///
|
89 |
+
- lngamma(`psi`i'') - `psi`i''*ln(1+exp(`xb`i''+`lnalpha`i'')) ///
|
90 |
+
- `fmm_y'*ln(1+exp(-`xb`i''-`lnalpha`i'')))
|
91 |
+
if "`equation'"=="component`i'" {
|
92 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
93 |
+
* exp(lngamma(`psi`i''+`fmm_y') - lngamma(`fmm_y'+1) ///
|
94 |
+
- lngamma(`psi`i'') - `psi`i''*ln(1+exp(`xb`i''+`lnalpha`i'')) ///
|
95 |
+
- `fmm_y'*ln(1+exp(-`xb`i''-`lnalpha`i'')))
|
96 |
+
}
|
97 |
+
}
|
98 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
99 |
+
label variable `varlist' "posterior probability: `equation'"
|
100 |
+
exit
|
101 |
+
}
|
102 |
+
|
103 |
+
end
|
104 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_normal_lf.ado
ADDED
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.1 24apr2007
|
4 |
+
* version 1.0.0 06mar2007
|
5 |
+
|
6 |
+
program fmm_normal_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
12 |
+
local L_pr `"`L_pr' pr`i'"'
|
13 |
+
local L_z `"`L_z' z`i'"'
|
14 |
+
local L_lsig `"`L_lsig' lnsigma`i'"'
|
15 |
+
local L_sig `"`L_sig' sigma`i'"'
|
16 |
+
local L_gb `"`L_gb' gb`i'"'
|
17 |
+
local L_gs `"`L_gs' gs`i'"'
|
18 |
+
}
|
19 |
+
|
20 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
21 |
+
local L_gL `"`L_gL' gL`i'"'
|
22 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
23 |
+
local L_h `"`L_h' h`i'`j'"'
|
24 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
forvalues i = 1/`=$fmm_components-1' {
|
29 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
30 |
+
forvalues j = 1/`=$fmm_components-1' {
|
31 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
// model arguments and temporary variables
|
36 |
+
args todo b lnf g negH `L_gL'
|
37 |
+
tempname `L_xb' `L_fxb' `L_lsig' `L_sig' `L_lpr' `L_pr' `L_z' ///
|
38 |
+
den prob gi `L_gb' `L_ga' `L_gs' hij `L_h' `L_nh'
|
39 |
+
|
40 |
+
// set up equations
|
41 |
+
forvalues i=1/$fmm_components {
|
42 |
+
mleval `xb`i'' = `b', eq(`i')
|
43 |
+
mleval `lnsigma`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
44 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
45 |
+
}
|
46 |
+
|
47 |
+
qui gen double `den' = 1
|
48 |
+
forvalues i=1/`=$fmm_components-1' {
|
49 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
50 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
51 |
+
}
|
52 |
+
|
53 |
+
forvalues i=1/`=$fmm_components-1' {
|
54 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
55 |
+
}
|
56 |
+
|
57 |
+
qui gen double `pr$fmm_components' = 1
|
58 |
+
forvalues i=1/`=$fmm_components-1' {
|
59 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
// calculate the likelihood function
|
64 |
+
qui gen double `prob' = 0
|
65 |
+
forvalues i=1/$fmm_components {
|
66 |
+
qui gen double `z`i'' = .
|
67 |
+
qui gen double `fxb`i'' = normalden($ML_y,`xb`i'',`sigma`i'')
|
68 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
69 |
+
}
|
70 |
+
|
71 |
+
mlsum `lnf' = ln(`prob')
|
72 |
+
|
73 |
+
|
74 |
+
// CALCULATE GRADIENT TERMS
|
75 |
+
// gradient bi
|
76 |
+
forvalues i = 1/$fmm_components {
|
77 |
+
qui replace `z`i'' = ($ML_y-`xb`i'')/`sigma`i''
|
78 |
+
qui gen double `gb`i'' = `z`i''/`sigma`i'' // density specific
|
79 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
80 |
+
}
|
81 |
+
|
82 |
+
// gradient prj
|
83 |
+
forvalues j = 1/`=$fmm_components-1' {
|
84 |
+
local m = `=$fmm_components+`j''
|
85 |
+
qui replace `gL`m'' = 0
|
86 |
+
forvalues k = 1/`=$fmm_components-1' {
|
87 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
88 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
89 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
// gradient sigmai
|
94 |
+
forvalues i=1/$fmm_components {
|
95 |
+
local k = `=2*$fmm_components-1+`i''
|
96 |
+
qui gen double `gs`i'' = `z`i''*`z`i''-1 // density specific
|
97 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
98 |
+
}
|
99 |
+
|
100 |
+
// collect gradient terms into vector
|
101 |
+
local np = colsof(`b')
|
102 |
+
local c 1
|
103 |
+
matrix `g' = J(1,`np',0)
|
104 |
+
|
105 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
106 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
107 |
+
matrix `g'[1,`c'] = `gi'
|
108 |
+
local c = `c' + colsof(`gi')
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
// CALCULATE HESSIAN TERMS
|
113 |
+
// hessian - b terms
|
114 |
+
local c 1
|
115 |
+
qui gen double `hij' = .
|
116 |
+
forvalues i = 1/$fmm_components {
|
117 |
+
// hessian (bi,bi)
|
118 |
+
qui replace `hij' = -1/(`sigma`i''^2) // density specific
|
119 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
120 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
121 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
122 |
+
// hessian (bi,bj)
|
123 |
+
if (`i'<$fmm_components) {
|
124 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
125 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
126 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
// hessian (bi,prj)
|
131 |
+
if (`i'<$fmm_components) {
|
132 |
+
forvalues j = 1/`=$fmm_components-1' {
|
133 |
+
local m = `=$fmm_components+`j''
|
134 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
135 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
136 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
137 |
+
}
|
138 |
+
}
|
139 |
+
else {
|
140 |
+
forvalues j = 1/`=$fmm_components-1' {
|
141 |
+
local m = `=$fmm_components+`j''
|
142 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
143 |
+
forvalues k = 1/`=$fmm_components-1' {
|
144 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
145 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
146 |
+
}
|
147 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
|
152 |
+
// hessian (bi,sigma)
|
153 |
+
forvalues j = 1/$fmm_components {
|
154 |
+
local k = `=2*$fmm_components-1+`j''
|
155 |
+
// hessian (bi,sigmai)
|
156 |
+
if (`i'==`j') {
|
157 |
+
qui replace `hij' = -2*`z`j''/`sigma`j'' // density specific
|
158 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
159 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
160 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
161 |
+
}
|
162 |
+
else {
|
163 |
+
// hessian (bi,sigmaj)
|
164 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
165 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// hessian - pr terms
|
171 |
+
// hessian (prj,pri)
|
172 |
+
forvalues i = 1/`=$fmm_components-1' {
|
173 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
174 |
+
local m = `=$fmm_components+`i''
|
175 |
+
local n = `=$fmm_components+`j''
|
176 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
177 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
178 |
+
forvalues k = 1/`=$fmm_components-1' {
|
179 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
180 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
181 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
182 |
+
}
|
183 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
|
188 |
+
// hessian - sigma terms
|
189 |
+
forvalues i = 1/$fmm_components {
|
190 |
+
// hessian w.r.t. sigmai
|
191 |
+
local m = `=2*$fmm_components-1+`i''
|
192 |
+
qui replace `hij' = -2*(`z`i''^2) // density specific
|
193 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
194 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
195 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
196 |
+
// hessian w.r.t. sigmaj (cross partials)
|
197 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
198 |
+
local n = `=2*$fmm_components-1+`j''
|
199 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
200 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
201 |
+
}
|
202 |
+
|
203 |
+
// hessian (sigmai,prj)
|
204 |
+
if (`i'<$fmm_components) {
|
205 |
+
forvalues j = 1/`=$fmm_components-1' {
|
206 |
+
local n = `=2*$fmm_components-1+`i''
|
207 |
+
local m = `=$fmm_components+`j''
|
208 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
209 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
210 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
211 |
+
}
|
212 |
+
}
|
213 |
+
else {
|
214 |
+
forvalues j = 1/`=$fmm_components-1' {
|
215 |
+
local n = `=2*$fmm_components-1+`i''
|
216 |
+
local m = `=$fmm_components+`j''
|
217 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
218 |
+
forvalues k = 1/`=$fmm_components-1' {
|
219 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
220 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
221 |
+
}
|
222 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
|
227 |
+
// collect hessian terms into matrix
|
228 |
+
local np = colsof(`b')
|
229 |
+
local r 1
|
230 |
+
matrix `negH' = J(`np',`np',0)
|
231 |
+
|
232 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
233 |
+
local c = `r'
|
234 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
235 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
236 |
+
if (`j'>`i') {
|
237 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
238 |
+
}
|
239 |
+
local c = `c' + colsof(`nh`i'`j'')
|
240 |
+
}
|
241 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
242 |
+
}
|
243 |
+
|
244 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_normal_p.ado
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.0 27aug2008
|
4 |
+
* version 1.1.0 12jul2007
|
5 |
+
* version 1.0.0 06mar2007
|
6 |
+
|
7 |
+
program fmm_normal_p
|
8 |
+
version 9.2
|
9 |
+
|
10 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
11 |
+
|
12 |
+
syntax newvarname [if] [in] [, * ]
|
13 |
+
|
14 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
15 |
+
_predict `typlist' `varlist' `if' `in', equation(`equation')
|
16 |
+
label variable `varlist' "predicted mean: `equation'"
|
17 |
+
exit
|
18 |
+
}
|
19 |
+
|
20 |
+
if "`equation'" == "" | "`prior'" == "prior" | "`posterior'" == "posterior" {
|
21 |
+
|
22 |
+
forvalues i=1/$fmm_components {
|
23 |
+
local L_xb `"`L_xb' xb`i'"'
|
24 |
+
local L_pr `"`L_pr' pr`i'"'
|
25 |
+
local L_lod `"`L_lod' lnsigma`i'"'
|
26 |
+
local L_od `"`L_od' sigma`i'"'
|
27 |
+
}
|
28 |
+
forvalues i=1/`=$fmm_components-1' {
|
29 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
30 |
+
}
|
31 |
+
|
32 |
+
tempvar `L_xb' `L_lpr' `L_pr' `L_lod' `L_od' den
|
33 |
+
|
34 |
+
forvalues i=1/$fmm_components {
|
35 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
36 |
+
qui _predict `typlist' `lnsigma`i'' `if' `in', equation(lnsigma`i')
|
37 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
38 |
+
}
|
39 |
+
|
40 |
+
qui gen double `den' = 1
|
41 |
+
forvalues i=1/`=$fmm_components-1' {
|
42 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
43 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
44 |
+
}
|
45 |
+
|
46 |
+
forvalues i=1/`=$fmm_components-1' {
|
47 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
48 |
+
}
|
49 |
+
|
50 |
+
qui gen double `pr$fmm_components' = 1
|
51 |
+
forvalues i=1/`=$fmm_components-1' {
|
52 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
if "`prior'" == "" & "`posterior'" == "" {
|
57 |
+
gen `typlist' `varlist' `if' `in' = 0
|
58 |
+
forvalues i=1/$fmm_components {
|
59 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `xb`i''
|
60 |
+
}
|
61 |
+
label variable `varlist' "predicted mean"
|
62 |
+
exit
|
63 |
+
}
|
64 |
+
|
65 |
+
if "`prior'" == "prior" {
|
66 |
+
local i = substr("`equation'",-1,1)
|
67 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
68 |
+
label variable `varlist' "prior probability: `equation'"
|
69 |
+
exit
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
if "`posterior'" == "posterior" {
|
74 |
+
tempvar prob probcomponent
|
75 |
+
|
76 |
+
local fmm_y = e(depvar)
|
77 |
+
qui gen double `prob' = 0
|
78 |
+
forvalues i=1/$fmm_components {
|
79 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
80 |
+
* normalden(`fmm_y',`xb`i'',`sigma`i'')
|
81 |
+
if "`equation'"=="component`i'" {
|
82 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
83 |
+
* normalden(`fmm_y',`xb`i'',`sigma`i'')
|
84 |
+
}
|
85 |
+
}
|
86 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
87 |
+
label variable `varlist' "posterior probability: `equation'"
|
88 |
+
exit
|
89 |
+
}
|
90 |
+
|
91 |
+
end
|
92 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_poisson_lf.ado
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.0.1 24apr2007
|
4 |
+
* version 1.0.0 06mar2007
|
5 |
+
|
6 |
+
program fmm_poisson_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_exb `"`L_exb' exb`i'"'
|
12 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
13 |
+
local L_pr `"`L_pr' pr`i'"'
|
14 |
+
local L_gb `"`L_gb' gb`i'"'
|
15 |
+
}
|
16 |
+
|
17 |
+
forvalues i = 1/`=2*$fmm_components-1' {
|
18 |
+
local L_gL `"`L_gL' gL`i'"'
|
19 |
+
forvalues j = `i'/`=2*$fmm_components-1' {
|
20 |
+
local L_h `"`L_h' h`i'`j'"'
|
21 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
forvalues i = 1/`=$fmm_components-1' {
|
26 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
27 |
+
forvalues j = 1/`=$fmm_components-1' {
|
28 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
// model arguments and temporary variables
|
33 |
+
args todo b lnf g negH `L_gL'
|
34 |
+
tempname `L_xb' `L_exb' `L_fxb' `L_lpr' `L_pr' ///
|
35 |
+
den prob gi `L_gb' `L_ga' hij `L_h' `L_nh'
|
36 |
+
|
37 |
+
// set up equations
|
38 |
+
forvalues i=1/$fmm_components {
|
39 |
+
mleval `xb`i'' = `b', eq(`i')
|
40 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
41 |
+
}
|
42 |
+
|
43 |
+
qui gen double `den' = 1
|
44 |
+
forvalues i=1/`=$fmm_components-1' {
|
45 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
46 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
47 |
+
}
|
48 |
+
|
49 |
+
forvalues i=1/`=$fmm_components-1' {
|
50 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
51 |
+
}
|
52 |
+
|
53 |
+
qui gen double `pr$fmm_components' = 1
|
54 |
+
forvalues i=1/`=$fmm_components-1' {
|
55 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
// calculate the likelihood function
|
60 |
+
qui gen double `prob' = 0
|
61 |
+
forvalues i=1/$fmm_components {
|
62 |
+
qui gen double `fxb`i'' = exp($ML_y*`xb`i'' - `exb`i'' ///
|
63 |
+
- lngamma($ML_y+1))
|
64 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
65 |
+
}
|
66 |
+
|
67 |
+
mlsum `lnf' = ln(`prob')
|
68 |
+
|
69 |
+
|
70 |
+
// CALCULATE GRADIENT TERMS
|
71 |
+
// gradient bi
|
72 |
+
forvalues i = 1/$fmm_components {
|
73 |
+
qui gen double `gb`i'' = $ML_y-`exb`i'' // density specific
|
74 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
75 |
+
}
|
76 |
+
|
77 |
+
// gradient prj
|
78 |
+
forvalues j = 1/`=$fmm_components-1' {
|
79 |
+
local m = `=$fmm_components+`j''
|
80 |
+
qui replace `gL`m'' = 0
|
81 |
+
forvalues k = 1/`=$fmm_components-1' {
|
82 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
83 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
84 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
// collect gradient terms into vector
|
89 |
+
local np = colsof(`b')
|
90 |
+
local c 1
|
91 |
+
matrix `g' = J(1,`np',0)
|
92 |
+
|
93 |
+
forvalues i = 1/`=2*$fmm_components-1' {
|
94 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
95 |
+
matrix `g'[1,`c'] = `gi'
|
96 |
+
local c = `c' + colsof(`gi')
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
// CALCULATE HESSIAN TERMS
|
101 |
+
// hessian - b terms
|
102 |
+
local c 1
|
103 |
+
qui gen double `hij' = .
|
104 |
+
forvalues i = 1/$fmm_components {
|
105 |
+
// hessian (bi,bi)
|
106 |
+
qui replace `hij' = -`exb`i'' // density specific
|
107 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
108 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
109 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
110 |
+
// hessian (bi,bj)
|
111 |
+
if (`i'<$fmm_components) {
|
112 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
113 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
114 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
// hessian (bi,prj)
|
119 |
+
if (`i'<$fmm_components) {
|
120 |
+
forvalues j = 1/`=$fmm_components-1' {
|
121 |
+
local m = `=$fmm_components+`j''
|
122 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
123 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
124 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
125 |
+
}
|
126 |
+
}
|
127 |
+
else {
|
128 |
+
forvalues j = 1/`=$fmm_components-1' {
|
129 |
+
local m = `=$fmm_components+`j''
|
130 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
131 |
+
forvalues k = 1/`=$fmm_components-1' {
|
132 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
133 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
134 |
+
}
|
135 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
// hessian - pr terms
|
141 |
+
// hessian (prj,pri)
|
142 |
+
forvalues i = 1/`=$fmm_components-1' {
|
143 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
144 |
+
local m = `=$fmm_components+`i''
|
145 |
+
local n = `=$fmm_components+`j''
|
146 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
147 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
148 |
+
forvalues k = 1/`=$fmm_components-1' {
|
149 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
150 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
151 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
152 |
+
}
|
153 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
// collect hessian terms into matrix
|
158 |
+
local np = colsof(`b')
|
159 |
+
local r 1
|
160 |
+
matrix `negH' = J(`np',`np',0)
|
161 |
+
|
162 |
+
forvalues i = 1/`=2*$fmm_components-1' {
|
163 |
+
local c = `r'
|
164 |
+
forvalues j = `i'/`=2*$fmm_components-1' {
|
165 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
166 |
+
if (`j'>`i') {
|
167 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
168 |
+
}
|
169 |
+
local c = `c' + colsof(`nh`i'`j'')
|
170 |
+
}
|
171 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
172 |
+
}
|
173 |
+
|
174 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_poisson_p.ado
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 2.0.0 27aug2008
|
4 |
+
* version 1.1.0 12jul2007
|
5 |
+
* version 1.0.0 06mar2007
|
6 |
+
|
7 |
+
program fmm_poisson_p
|
8 |
+
version 9.2
|
9 |
+
|
10 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRIor POSterior EQuation(string) ]
|
11 |
+
|
12 |
+
syntax newvarname [if] [in] [, * ]
|
13 |
+
|
14 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
15 |
+
_predict `typlist' `varlist' `if' `in', equation(`equation')
|
16 |
+
qui replace `varlist' = exp(`varlist')
|
17 |
+
label variable `varlist' "predicted mean: `equation'"
|
18 |
+
exit
|
19 |
+
}
|
20 |
+
|
21 |
+
if "`equation'" == "" | "`prior'" == "prior" | "`posterior'" == "posterior" {
|
22 |
+
|
23 |
+
forvalues i=1/$fmm_components {
|
24 |
+
local L_xb `"`L_xb' xb`i'"'
|
25 |
+
local L_exb `"`L_exb' exb`i'"'
|
26 |
+
local L_pr `"`L_pr' pr`i'"'
|
27 |
+
}
|
28 |
+
forvalues i=1/`=$fmm_components-1' {
|
29 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
30 |
+
}
|
31 |
+
|
32 |
+
tempvar `L_xb' `L_exb' `L_lpr' `L_pr' den
|
33 |
+
|
34 |
+
forvalues i=1/$fmm_components {
|
35 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
36 |
+
qui gen double `exb`i'' = exp(`xb`i'')
|
37 |
+
}
|
38 |
+
|
39 |
+
qui gen double `den' = 1
|
40 |
+
forvalues i=1/`=$fmm_components-1' {
|
41 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
42 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
43 |
+
}
|
44 |
+
|
45 |
+
forvalues i=1/`=$fmm_components-1' {
|
46 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
47 |
+
}
|
48 |
+
|
49 |
+
qui gen double `pr$fmm_components' = 1
|
50 |
+
forvalues i=1/`=$fmm_components-1' {
|
51 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
if "`prior'" == "" & "`posterior'" == "" {
|
56 |
+
gen `typlist' `varlist' `if' `in' = 0
|
57 |
+
forvalues i=1/$fmm_components {
|
58 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `exb`i''
|
59 |
+
}
|
60 |
+
label variable `varlist' "predicted mean"
|
61 |
+
exit
|
62 |
+
}
|
63 |
+
|
64 |
+
if "`prior'" == "prior" {
|
65 |
+
local i = substr("`equation'",-1,1)
|
66 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
67 |
+
label variable `varlist' "prior probability: `equation'"
|
68 |
+
exit
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
if "`posterior'" == "posterior" {
|
73 |
+
tempvar prob probcomponent
|
74 |
+
|
75 |
+
local fmm_y = e(depvar)
|
76 |
+
qui gen double `prob' = 0
|
77 |
+
forvalues i=1/$fmm_components {
|
78 |
+
qui replace `prob' = `prob' + `pr`i'' * exp(`fmm_y'*`xb`i'' ///
|
79 |
+
- `exb`i'' - lngamma(`fmm_y'+1))
|
80 |
+
if "`equation'"=="component`i'" {
|
81 |
+
qui gen double `probcomponent' = `pr`i'' * exp(`fmm_y'*`xb`i'' ///
|
82 |
+
- `exb`i'' - lngamma(`fmm_y'+1))
|
83 |
+
}
|
84 |
+
}
|
85 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
86 |
+
label variable `varlist' "posterior probability: `equation'"
|
87 |
+
exit
|
88 |
+
}
|
89 |
+
|
90 |
+
end
|
91 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_postestimation.hlp
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* documented: June 12, 2007}{...}
|
3 |
+
{* revised: February 12, 2012}{...}
|
4 |
+
{cmd:help fmm postestimation} {right:also see: {helpb fmm} }
|
5 |
+
{hline}
|
6 |
+
|
7 |
+
{title:Title}
|
8 |
+
|
9 |
+
{hi:fmm postestimation} {hline 2} Postestimation tools for {cmd:fmm}
|
10 |
+
|
11 |
+
|
12 |
+
{title:Description}
|
13 |
+
|
14 |
+
{pstd}
|
15 |
+
The following postestimation commands are available for {opt fmm}:
|
16 |
+
|
17 |
+
{synoptset 11}{...}
|
18 |
+
{p2coldent :command}description{p_end}
|
19 |
+
{synoptline}
|
20 |
+
INCLUDE help post_estat
|
21 |
+
INCLUDE help post_estimates
|
22 |
+
INCLUDE help post_lincom
|
23 |
+
INCLUDE help post_lrtest
|
24 |
+
INCLUDE help post_margins
|
25 |
+
INCLUDE help post_nlcom
|
26 |
+
{synopt :{helpb fmm postestimation##predict:predict}}predictions including component
|
27 |
+
probabilities{p_end}
|
28 |
+
INCLUDE help post_test
|
29 |
+
INCLUDE help post_testnl
|
30 |
+
{synoptline}
|
31 |
+
{p2colreset}{...}
|
32 |
+
|
33 |
+
|
34 |
+
{marker predict}{...}
|
35 |
+
{title:Syntax for predict}
|
36 |
+
|
37 |
+
{p 8 16 2}
|
38 |
+
{cmd:predict} {dtype} {newvar} {ifin} [{cmd:,} {it:statistic}
|
39 |
+
{opt eq:uation(component#)}]
|
40 |
+
|
41 |
+
{synoptset 11 tabbed}{...}
|
42 |
+
{synopthdr :statistic}
|
43 |
+
{synoptline}
|
44 |
+
{syntab :Main}
|
45 |
+
{synopt :{opt me:an}}predicted mean; the default{p_end}
|
46 |
+
{synopt :{opt pri:or}}prior component probability{p_end}
|
47 |
+
{synopt :{opt pos:terior}}posterior component probability{p_end}
|
48 |
+
{synoptline}
|
49 |
+
{p2colreset}{...}
|
50 |
+
{p 4 6 2}
|
51 |
+
Option {opt eq:uation(component#)} is required for {opt pri:or} and {opt pos:terior}.
|
52 |
+
It is also required for {opt me:an} if predicted within-component means are desired.
|
53 |
+
{p_end}
|
54 |
+
|
55 |
+
INCLUDE help esample
|
56 |
+
|
57 |
+
|
58 |
+
{title:Options for predict}
|
59 |
+
|
60 |
+
{phang}
|
61 |
+
{opt me:an}, the default, calculates the predicted mean.
|
62 |
+
|
63 |
+
{pmore}
|
64 |
+
To obtain within component means, specify the {opt eq:uation(component#)} option.
|
65 |
+
|
66 |
+
{phang}
|
67 |
+
{opt pri:or} calculates the prior component probabilities. With {opt prior},
|
68 |
+
{opt eq:uation(component#)} must also be specified.
|
69 |
+
|
70 |
+
{phang}
|
71 |
+
{opt pos:terior} calculates the posterior component probabilities. With
|
72 |
+
{opt posterior}, {opt eq:uation(component#)} must also be specified.
|
73 |
+
|
74 |
+
|
75 |
+
{title:Marginal effects}
|
76 |
+
|
77 |
+
{pstd}
|
78 |
+
Marginal effects can be calculated separately for the overall conditional mean
|
79 |
+
as well as for within-component means, prior and posterior probabilities. To calculate
|
80 |
+
marginal effects for within-component means, prior and posterior probabilities, run
|
81 |
+
{cmd:margins} separately for each component, as shown in the examples below. Note that {cmd:fmm} has not been updated to accommodate factor variables.
|
82 |
+
|
83 |
+
|
84 |
+
{title:Examples}
|
85 |
+
|
86 |
+
{pstd}Mixture of normals
|
87 |
+
|
88 |
+
{phang}{stata "webuse womenwk, clear" : . webuse womenwk, clear}
|
89 |
+
|
90 |
+
{phang}{stata "fmm wagefull educ age married, mix(normal) comp(2)" : . fmm wagefull educ age married, mix(normal) comp(2)}
|
91 |
+
|
92 |
+
{phang}{stata "predict wfhat" : . predict wfhat}
|
93 |
+
|
94 |
+
{phang}{stata "predict wfhat1, eq(component1)" : . predict wfhat1, eq(component1)}
|
95 |
+
|
96 |
+
{phang}{stata "predict wfhat2, eq(component2)" : . predict wfhat2, eq(component2)}
|
97 |
+
|
98 |
+
{phang}{stata "predict wfhatpri, prior eq(component1)" : . predict wfhatpri, prior eq(component1)}
|
99 |
+
|
100 |
+
{phang}{stata "predict wfhatpos, posterior eq(component1)" : . predict wfhatpos, posterior eq(component1)}
|
101 |
+
|
102 |
+
{phang}{stata "sum wagefull wfhat*" : . sum wagefull wfhat*}
|
103 |
+
|
104 |
+
{phang}{stata "drop wfhat*" : . drop wfhat*}
|
105 |
+
|
106 |
+
|
107 |
+
{pstd}Mixture of Negative Binomials (Type 2)
|
108 |
+
|
109 |
+
{phang}{stata "webuse medpar, clear" : . webuse medpar, clear}
|
110 |
+
|
111 |
+
{phang}{stata "gen los0 = los - 1" : . gen los0 = los - 1}
|
112 |
+
|
113 |
+
{phang}{stata "fmm los0 died hmo type2-type3, mix(negbin2) comp(2)" : . fmm exlos died hmo type2-type3, mix(negbin2) comp(2) comp(2)}
|
114 |
+
|
115 |
+
{phang}{stata "predict wfhat" : . predict wfhat}
|
116 |
+
|
117 |
+
{phang}{stata "predict l0hat1, eq(component1)" : . predict l0hat1, eq(component1)}
|
118 |
+
|
119 |
+
{phang}{stata "predict l0hat2, eq(component2)" : . predict l0hat2, eq(component2)}
|
120 |
+
|
121 |
+
{phang}{stata "predict l0hatpri, prior eq(component1)" : . predict l0hatpri, prior eq(component1)}
|
122 |
+
|
123 |
+
{phang}{stata "predict l0hatpos, posterior eq(component1)" : . predict l0hatpos, posterior eq(component1)}
|
124 |
+
|
125 |
+
{phang}{stata "sum los0 l0hat*" : . sum los0 l0hat*}
|
126 |
+
|
127 |
+
{phang}{stata "drop l0hat*" : . drop l0hat*}
|
128 |
+
|
129 |
+
{phang}{stata "margins, dydx(*) predict(eq(component1))" : . margins, dydx(*) predict(eq(component1))}
|
130 |
+
|
131 |
+
{phang}{stata "margins, dydx(*) predict(eq(component2))" : . margins, dydx(*) predict(eq(component2))}
|
132 |
+
|
133 |
+
{phang}{stata "margins, dydx(*)" : . margins, dydx(*)}
|
134 |
+
|
135 |
+
|
136 |
+
{title:Also see}
|
137 |
+
|
138 |
+
{psee}
|
139 |
+
{helpb fmm};
|
140 |
+
{helpb estimates},
|
141 |
+
{helpb lincom},
|
142 |
+
{helpb lrtest},
|
143 |
+
{helpb margins},
|
144 |
+
{helpb nlcom},
|
145 |
+
{helpb predictnl},
|
146 |
+
{helpb suest},
|
147 |
+
{helpb test},
|
148 |
+
{helpb testnl}
|
149 |
+
{p_end}
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_studentt_lf.ado
ADDED
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.1.0 12jul2007
|
4 |
+
* version 1.1.0 12jul2007
|
5 |
+
|
6 |
+
program fmm_studentt_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
forvalues i = 1/$fmm_components {
|
10 |
+
local L_xb `"`L_xb' xb`i'"'
|
11 |
+
local L_fxb `"`L_fxb' fxb`i'"'
|
12 |
+
local L_pr `"`L_pr' pr`i'"'
|
13 |
+
local L_z `"`L_z' z`i'"'
|
14 |
+
local L_lsig `"`L_lsig' lnsigma`i'"'
|
15 |
+
local L_sig `"`L_sig' sigma`i'"'
|
16 |
+
local L_gb `"`L_gb' gb`i'"'
|
17 |
+
local L_gs `"`L_gs' gs`i'"'
|
18 |
+
local L_z2bydf `"`L_z2bydf' z2bydf`i'"'
|
19 |
+
local L_inv1plz2bydf `"`L_inv1plz2bydf' inv1plz2bydf`i'"'
|
20 |
+
}
|
21 |
+
|
22 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
23 |
+
local L_gL `"`L_gL' gL`i'"'
|
24 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
25 |
+
local L_h `"`L_h' h`i'`j'"'
|
26 |
+
local L_nh `"`L_nh' nh`i'`j'"'
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
forvalues i = 1/`=$fmm_components-1' {
|
31 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
32 |
+
forvalues j = 1/`=$fmm_components-1' {
|
33 |
+
local L_ga `"`L_ga' ga`i'`j'"'
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
// model arguments and temporary variables
|
38 |
+
args todo b lnf g negH `L_gL'
|
39 |
+
tempname `L_xb' `L_fxb' `L_lsig' `L_sig' `L_lpr' `L_pr' `L_z' ///
|
40 |
+
den prob gi `L_gb' `L_ga' `L_gs' hij `L_h' `L_nh' ///
|
41 |
+
dfpl1 `L_z2bydf' `L_inv1plz2bydf'
|
42 |
+
|
43 |
+
// set up equations
|
44 |
+
forvalues i=1/$fmm_components {
|
45 |
+
mleval `xb`i'' = `b', eq(`i')
|
46 |
+
mleval `lnsigma`i'' = `b', eq(`=2*$fmm_components-1+`i'')
|
47 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
48 |
+
}
|
49 |
+
|
50 |
+
qui gen double `den' = 1
|
51 |
+
forvalues i=1/`=$fmm_components-1' {
|
52 |
+
mleval `lpr`i'' = `b', eq(`=$fmm_components+`i'')
|
53 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
54 |
+
}
|
55 |
+
|
56 |
+
forvalues i=1/`=$fmm_components-1' {
|
57 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
58 |
+
}
|
59 |
+
|
60 |
+
qui gen double `pr$fmm_components' = 1
|
61 |
+
forvalues i=1/`=$fmm_components-1' {
|
62 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
// calculate the likelihood function
|
67 |
+
qui gen double `prob' = 0
|
68 |
+
forvalues i=1/$fmm_components {
|
69 |
+
qui gen double `z`i'' = ($ML_y-`xb`i'')/`sigma`i''
|
70 |
+
qui gen double `z2bydf`i'' = (`z`i''^2)/$fmm_tdf
|
71 |
+
qui gen double `inv1plz2bydf`i'' = 1/(1 + `z2bydf`i'')
|
72 |
+
qui gen double `fxb`i'' = tden($fmm_tdf,`z`i'')/`sigma`i''
|
73 |
+
qui replace `prob' = `prob' + `pr`i''*`fxb`i''
|
74 |
+
}
|
75 |
+
|
76 |
+
mlsum `lnf' = ln(`prob')
|
77 |
+
|
78 |
+
|
79 |
+
// CALCULATE GRADIENT TERMS
|
80 |
+
qui gen double `dfpl1' = $fmm_tdf + 1
|
81 |
+
// gradient bi
|
82 |
+
forvalues i = 1/$fmm_components {
|
83 |
+
qui gen double `gb`i'' = `dfpl1' * `inv1plz2bydf`i'' ///
|
84 |
+
* `z`i'' / ($fmm_tdf*`sigma`i'') // density specific
|
85 |
+
qui replace `gL`i'' = (`pr`i'' * `fxb`i'' * `gb`i'')/`prob'
|
86 |
+
}
|
87 |
+
|
88 |
+
// gradient prj
|
89 |
+
forvalues j = 1/`=$fmm_components-1' {
|
90 |
+
local m = `=$fmm_components+`j''
|
91 |
+
qui replace `gL`m'' = 0
|
92 |
+
forvalues k = 1/`=$fmm_components-1' {
|
93 |
+
qui gen double `ga`k'`j'' = ((`j'==`k') - `pr`j'')
|
94 |
+
qui replace `gL`m'' = `gL`m'' + `pr`k''*`ga`k'`j'' ///
|
95 |
+
*(`fxb`k'' - `fxb$fmm_components')/`prob'
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
// gradient sigmai
|
100 |
+
forvalues i=1/$fmm_components {
|
101 |
+
local k = `=2*$fmm_components-1+`i''
|
102 |
+
qui gen double `gs`i'' = `dfpl1' * `inv1plz2bydf`i'' ///
|
103 |
+
* `z2bydf`i'' - 1 // density specific
|
104 |
+
qui replace `gL`k'' = (`pr`i'' * `fxb`i'' * `gs`i'')/`prob'
|
105 |
+
}
|
106 |
+
|
107 |
+
// collect gradient terms into vector
|
108 |
+
local np = colsof(`b')
|
109 |
+
local c 1
|
110 |
+
matrix `g' = J(1,`np',0)
|
111 |
+
|
112 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
113 |
+
mlvecsum `lnf' `gi' = `gL`i'', eq(`i')
|
114 |
+
matrix `g'[1,`c'] = `gi'
|
115 |
+
local c = `c' + colsof(`gi')
|
116 |
+
}
|
117 |
+
|
118 |
+
|
119 |
+
// CALCULATE HESSIAN TERMS
|
120 |
+
// hessian - b terms
|
121 |
+
local c 1
|
122 |
+
qui gen double `hij' = .
|
123 |
+
forvalues i = 1/$fmm_components {
|
124 |
+
// hessian (bi,bi)
|
125 |
+
qui replace `hij' = `dfpl1' * `inv1plz2bydf`i'' / ($fmm_tdf*(`sigma`i''^2)) ///
|
126 |
+
* (`inv1plz2bydf`i'' * 2 * `z2bydf`i'' - 1) // density specific
|
127 |
+
qui gen double `h`i'`i'' = `pr`i''/`prob'*`fxb`i'' ///
|
128 |
+
*(-`gL`i''*`gb`i'' + `gb`i''^2 + `hij')
|
129 |
+
mlmatsum `lnf' `nh`i'`i'' = -`h`i'`i'', eq(`i',`i')
|
130 |
+
// hessian (bi,bj)
|
131 |
+
if (`i'<$fmm_components) {
|
132 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
133 |
+
qui gen double `h`i'`j'' = `pr`i''/`prob'*(-`gL`j''*`fxb`i''*`gb`i'')
|
134 |
+
mlmatsum `lnf' `nh`i'`j'' = -`h`i'`j'', eq(`i',`j')
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
// hessian (bi,prj)
|
139 |
+
if (`i'<$fmm_components) {
|
140 |
+
forvalues j = 1/`=$fmm_components-1' {
|
141 |
+
local m = `=$fmm_components+`j''
|
142 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i'' ///
|
143 |
+
+ 1/`prob'*`fxb`i''*`gb`i''*`pr`i''*`ga`i'`j''
|
144 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
145 |
+
}
|
146 |
+
}
|
147 |
+
else {
|
148 |
+
forvalues j = 1/`=$fmm_components-1' {
|
149 |
+
local m = `=$fmm_components+`j''
|
150 |
+
qui gen double `h`i'`m'' = -`gL`m''*`gL`i''
|
151 |
+
forvalues k = 1/`=$fmm_components-1' {
|
152 |
+
qui replace `h`i'`m'' = `h`i'`m'' ///
|
153 |
+
- 1/`prob'*`fxb`i''*`gb`i''*`pr`k''*`ga`k'`j''
|
154 |
+
}
|
155 |
+
mlmatsum `lnf' `nh`i'`m'' = -`h`i'`m'', eq(`i',`m')
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
// hessian (bi,sigma)
|
161 |
+
forvalues j = 1/$fmm_components {
|
162 |
+
local k = `=2*$fmm_components-1+`j''
|
163 |
+
// hessian (bi,sigmai)
|
164 |
+
if (`i'==`j') {
|
165 |
+
qui replace `hij' = -2 * `dfpl1' * `inv1plz2bydf`i'' * `z`i'' ///
|
166 |
+
/ ($fmm_tdf*`sigma`i'') ///
|
167 |
+
* (1 - `inv1plz2bydf`i'' * `z2bydf`i'') // density specific
|
168 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*`fxb`i'' ///
|
169 |
+
*(-`gL`k''*`gb`i'' + `gs`j''*`gb`i'' + `hij')
|
170 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
171 |
+
}
|
172 |
+
else {
|
173 |
+
// hessian (bi,sigmaj)
|
174 |
+
qui gen double `h`i'`k'' = `pr`i''/`prob'*(-`gL`k''*`fxb`i''*`gb`i'')
|
175 |
+
mlmatsum `lnf' `nh`i'`k'' = -`h`i'`k'', eq(`i',`k')
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
179 |
+
|
180 |
+
// hessian - pr terms
|
181 |
+
// hessian (prj,pri)
|
182 |
+
forvalues i = 1/`=$fmm_components-1' {
|
183 |
+
forvalues j = `i'/`=$fmm_components-1' {
|
184 |
+
local m = `=$fmm_components+`i''
|
185 |
+
local n = `=$fmm_components+`j''
|
186 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
187 |
+
qui replace `hij' = -`pr`i''*((`i'==`j') - `pr`j'')
|
188 |
+
forvalues k = 1/`=$fmm_components-1' {
|
189 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
190 |
+
+ 1/`prob'*`pr`k''*(`fxb`k'' - `fxb$fmm_components') ///
|
191 |
+
*(`ga`k'`i''*`ga`k'`j'' + `hij')
|
192 |
+
}
|
193 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
|
198 |
+
// hessian - sigma terms
|
199 |
+
forvalues i = 1/$fmm_components {
|
200 |
+
// hessian w.r.t. sigmai
|
201 |
+
local m = `=2*$fmm_components-1+`i''
|
202 |
+
qui replace `hij' = 2 * `dfpl1' * `inv1plz2bydf`i'' * `z2bydf`i'' ///
|
203 |
+
* (`inv1plz2bydf`i'' * `z2bydf`i'' - 1) // density specific
|
204 |
+
qui gen double `h`m'`m'' = `pr`i''/`prob'*`fxb`i'' ///
|
205 |
+
*(-`gL`m''*`gs`i'' + `gs`i''^2 + `hij')
|
206 |
+
mlmatsum `lnf' `nh`m'`m'' = -`h`m'`m'', eq(`m',`m')
|
207 |
+
// hessian w.r.t. sigmaj (cross partials)
|
208 |
+
forvalues j = `=`i'+1'/$fmm_components {
|
209 |
+
local n = `=2*$fmm_components-1+`j''
|
210 |
+
qui gen double `h`m'`n'' = `pr`i''/`prob'*(-`gL`n''*`fxb`i''*`gs`i'')
|
211 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
212 |
+
}
|
213 |
+
|
214 |
+
// hessian (sigmai,prj)
|
215 |
+
if (`i'<$fmm_components) {
|
216 |
+
forvalues j = 1/`=$fmm_components-1' {
|
217 |
+
local n = `=2*$fmm_components-1+`i''
|
218 |
+
local m = `=$fmm_components+`j''
|
219 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n'' ///
|
220 |
+
+ 1/`prob'*`fxb`i''*`gs`i''*`pr`i''*`ga`i'`j''
|
221 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
222 |
+
}
|
223 |
+
}
|
224 |
+
else {
|
225 |
+
forvalues j = 1/`=$fmm_components-1' {
|
226 |
+
local n = `=2*$fmm_components-1+`i''
|
227 |
+
local m = `=$fmm_components+`j''
|
228 |
+
qui gen double `h`m'`n'' = -`gL`m''*`gL`n''
|
229 |
+
forvalues k = 1/`=$fmm_components-1' {
|
230 |
+
qui replace `h`m'`n'' = `h`m'`n'' ///
|
231 |
+
- 1/`prob'*`fxb`i''*`gs`i''*`pr`k''*`ga`k'`j''
|
232 |
+
}
|
233 |
+
mlmatsum `lnf' `nh`m'`n'' = -`h`m'`n'', eq(`m',`n')
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
// collect hessian terms into matrix
|
239 |
+
local np = colsof(`b')
|
240 |
+
local r 1
|
241 |
+
matrix `negH' = J(`np',`np',0)
|
242 |
+
|
243 |
+
forvalues i = 1/`=3*$fmm_components-1' {
|
244 |
+
local c = `r'
|
245 |
+
forvalues j = `i'/`=3*$fmm_components-1' {
|
246 |
+
matrix `negH'[`r',`c'] = `nh`i'`j''
|
247 |
+
if (`j'>`i') {
|
248 |
+
matrix `negH'[`c',`r'] = `nh`i'`j'''
|
249 |
+
}
|
250 |
+
local c = `c' + colsof(`nh`i'`j'')
|
251 |
+
}
|
252 |
+
local r = `r' + rowsof(`nh`i'`i'')
|
253 |
+
}
|
254 |
+
|
255 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/f/fmm_studentt_p.ado
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.1.0 12jul2007
|
4 |
+
* version 1.0.0 12jul2007
|
5 |
+
|
6 |
+
program fmm_studentt_p
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
syntax anything(id="newvarname") [if] [in] [, MEan PRior POsterior EQuation(string) ]
|
10 |
+
|
11 |
+
syntax newvarname [if] [in] [, * ]
|
12 |
+
|
13 |
+
if "`equation'" != "" & "`prior'" == "" & "`posterior'" == "" {
|
14 |
+
_predict `typlist' `varlist' `if' `in', equation(`equation')
|
15 |
+
label variable `varlist' "predicted mean: `equation'"
|
16 |
+
exit
|
17 |
+
}
|
18 |
+
|
19 |
+
if "`equation'" == "" | "`prior'" == "prior" | "`posterior'" == "posterior" {
|
20 |
+
|
21 |
+
forvalues i=1/$fmm_components {
|
22 |
+
local L_xb `"`L_xb' xb`i'"'
|
23 |
+
local L_pr `"`L_pr' pr`i'"'
|
24 |
+
local L_lod `"`L_lod' lnsigma`i'"'
|
25 |
+
local L_od `"`L_od' sigma`i'"'
|
26 |
+
}
|
27 |
+
forvalues i=1/`=$fmm_components-1' {
|
28 |
+
local L_lpr `"`L_lpr' lpr`i'"'
|
29 |
+
}
|
30 |
+
|
31 |
+
tempvar `L_xb' `L_lpr' `L_pr' `L_lod' `L_od' den
|
32 |
+
|
33 |
+
forvalues i=1/$fmm_components {
|
34 |
+
qui _predict `typlist' `xb`i'' `if' `in', equation(component`i')
|
35 |
+
qui _predict `typlist' `lnsigma`i'' `if' `in', equation(lnsigma`i')
|
36 |
+
qui gen double `sigma`i'' = exp(`lnsigma`i'')
|
37 |
+
}
|
38 |
+
|
39 |
+
qui gen double `den' = 1
|
40 |
+
forvalues i=1/`=$fmm_components-1' {
|
41 |
+
qui _predict `typlist' `lpr`i'' `if' `in', equation(imlogitpi`i')
|
42 |
+
qui replace `den' = `den' + exp(`lpr`i'')
|
43 |
+
}
|
44 |
+
|
45 |
+
forvalues i=1/`=$fmm_components-1' {
|
46 |
+
qui gen double `pr`i'' = exp(`lpr`i'')/`den'
|
47 |
+
}
|
48 |
+
|
49 |
+
qui gen double `pr$fmm_components' = 1
|
50 |
+
forvalues i=1/`=$fmm_components-1' {
|
51 |
+
qui replace `pr$fmm_components' = `pr$fmm_components' - `pr`i''
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
if "`prior'" == "" & "`posterior'" == "" {
|
56 |
+
gen `typlist' `varlist' `if' `in' = 0
|
57 |
+
forvalues i=1/$fmm_components {
|
58 |
+
qui replace `varlist' = `varlist' + `pr`i'' * `xb`i''
|
59 |
+
}
|
60 |
+
label variable `varlist' "predicted mean"
|
61 |
+
exit
|
62 |
+
}
|
63 |
+
|
64 |
+
if "`prior'" == "prior" {
|
65 |
+
local i = substr("`equation'",-1,1)
|
66 |
+
gen `typlist' `varlist' = `pr`i'' `if' `in'
|
67 |
+
label variable `varlist' "prior probability: `equation'"
|
68 |
+
exit
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
if "`posterior'" == "posterior" {
|
73 |
+
tempvar prob probcomponent
|
74 |
+
|
75 |
+
local fmm_y = e(depvar)
|
76 |
+
qui gen double `prob' = 0
|
77 |
+
forvalues i=1/$fmm_components {
|
78 |
+
qui replace `prob' = `prob' + `pr`i'' ///
|
79 |
+
* tden($fmm_tdf,(`fmm_y'-`xb`i'')/`sigma`i'')/`sigma`i''
|
80 |
+
if "`equation'"=="component`i'" {
|
81 |
+
qui gen double `probcomponent' = `pr`i'' ///
|
82 |
+
* tden($fmm_tdf,(`fmm_y'-`xb`i'')/`sigma`i'')/`sigma`i''
|
83 |
+
}
|
84 |
+
}
|
85 |
+
gen `typlist' `varlist' = `probcomponent' / `prob'
|
86 |
+
label variable `varlist' "posterior probability: `equation'"
|
87 |
+
exit
|
88 |
+
}
|
89 |
+
|
90 |
+
end
|
91 |
+
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/gammareg_lf.ado
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! version 2.1.0 12feb2012
|
2 |
+
*! author: Partha Deb
|
3 |
+
* version 1.1.0 12jul2007
|
4 |
+
* version 1.0.0 21dec2006
|
5 |
+
|
6 |
+
program gammareg_lf
|
7 |
+
version 9.2
|
8 |
+
|
9 |
+
args todo b lnf g negH g1 g2
|
10 |
+
|
11 |
+
tempname xb exb lnalpha alpha G1 G2 h11 h21 h22 H11 H21 H22
|
12 |
+
|
13 |
+
mleval `xb' = `b', eq(1)
|
14 |
+
mleval `lnalpha' = `b', eq(2)
|
15 |
+
|
16 |
+
quietly {
|
17 |
+
gen double `exb' = exp(`xb')
|
18 |
+
gen double `alpha' = exp(`lnalpha')
|
19 |
+
|
20 |
+
mlsum `lnf' = ln(gammaden(`alpha',`exb',0,$ML_y))
|
21 |
+
|
22 |
+
replace `g1' = -`alpha' + $ML_y/`exb'
|
23 |
+
replace `g2' = (-digamma(`alpha') - `xb' + log($ML_y))*`alpha'
|
24 |
+
|
25 |
+
mlvecsum `lnf' `G1' = `g1', eq(1)
|
26 |
+
mlvecsum `lnf' `G2' = `g2', eq(2)
|
27 |
+
matrix `g' = (`G1', `G2')
|
28 |
+
|
29 |
+
gen double `h11' = - $ML_y/`exb'
|
30 |
+
gen double `h21' = -`alpha'
|
31 |
+
gen double `h22' = (-digamma(`alpha') - `xb' + log($ML_y) ///
|
32 |
+
- trigamma(`alpha')*`alpha')*`alpha'
|
33 |
+
|
34 |
+
mlmatsum `lnf' `H11' = -`h11', eq(1,1)
|
35 |
+
mlmatsum `lnf' `H21' = -`h21', eq(2,1)
|
36 |
+
mlmatsum `lnf' `H22' = -`h22', eq(2,2)
|
37 |
+
matrix `negH' = (`H11',`H21'' \ ///
|
38 |
+
`H21',`H22')
|
39 |
+
}
|
40 |
+
|
41 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/glcurve.ado
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*! 3.2.0 Philippe Van Kerm - Stephen P. Jenkins 07 February 2007
|
2 |
+
* - Concentration curves with ties in ranking variable do not depend on initial sort order anymore: 'maximal concentration' now imposed
|
3 |
+
* 3.1.0 Philippe Van Kerm - Stephen P. Jenkins 24 August 2006
|
4 |
+
* - fix for TIP curves with varying (observation-specific) poverty lines (cumulation was not incorrect)
|
5 |
+
* - minor fix for -replace- options with non existing pvar and glvar
|
6 |
+
* - revision of labels (more meaningful labels, identification of TIP curves, etc.)
|
7 |
+
* 3.0.2 Philippe Van Kerm - Stephen P. Jenkins 15 May 2006
|
8 |
+
* -one fix: sort stability issue with ties in weights and sort variable
|
9 |
+
* -minor change to help file (label specification)
|
10 |
+
* 3.0.0 Philippe Van Kerm - Stephen P. Jenkins 26 October 2004 (SJ 4-4: gr0001_1)
|
11 |
+
* touched by NJC 24 October 2004
|
12 |
+
* 2.0 Philippe Van Kerm - Stephen P. Jenkins, 19 Feb 2001 (TSJ-1: gr0001)
|
13 |
+
* 1.2 Stephen P. Jenkins - Philippe Van Kerm, Apr 1999 STB-49 sg107.1
|
14 |
+
* Syntax: glcurve y [fw aw] [if in], [GLvar(x1) Pvar(x2) SOrtvar(svar)
|
15 |
+
* Lorenz RTIP(string) ATIP(string)
|
16 |
+
* BY(gvar) SPlit GRaph REPLACE plot(plot) graph_options]
|
17 |
+
|
18 |
+
program glcurve, sort
|
19 |
+
version 8.0
|
20 |
+
syntax varname [if] [in] [fweight aweight] ///
|
21 |
+
[, GLvar(string) Pvar(string) SOrtvar(varname) ///
|
22 |
+
Lorenz RTIP(string) ATIP(string) ///
|
23 |
+
BY(varname numeric) SPlit NOGRaph REPLACE PLOT(string asis) * ]
|
24 |
+
|
25 |
+
tempvar inc cumwy cumw maxw badinc wi gl p
|
26 |
+
tempname byname
|
27 |
+
|
28 |
+
local graph = cond("`nograph'" != "", "", "graph")
|
29 |
+
|
30 |
+
if "`by'" != "" {
|
31 |
+
if "`graph'" != "" & "`split'" == "" {
|
32 |
+
di as err "{p}split must be used to combine by()" ///
|
33 |
+
" with a graph; nograph option assumed{p_end}"
|
34 |
+
local graph
|
35 |
+
}
|
36 |
+
}
|
37 |
+
else {
|
38 |
+
if "`split'" != "" {
|
39 |
+
di as err "{p}split must be combined with by(); " ///
|
40 |
+
" split ignored{p_end}"
|
41 |
+
local split
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
/* this code modified in v3.0.3 to avoid problems with non-existing variables */
|
46 |
+
if "`replace'" != "" {
|
47 |
+
cap confirm new variable `pvar'
|
48 |
+
if (_rc!=0) {
|
49 |
+
drop `pvar'
|
50 |
+
}
|
51 |
+
if "`split'" != "" & "`by'" != "" {
|
52 |
+
local prefix "`glvar'"
|
53 |
+
cap drop `prefix'_*
|
54 |
+
}
|
55 |
+
else {
|
56 |
+
cap confirm new variable `glvar'
|
57 |
+
if (_rc!=0) {
|
58 |
+
drop `glvar'
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
if "`weight'" == "" qui gen byte `wi' = 1
|
64 |
+
else qui gen `wi' `exp'
|
65 |
+
|
66 |
+
marksample touse
|
67 |
+
markout `touse' `sortvar' `by'
|
68 |
+
|
69 |
+
if "`split'" == "" {
|
70 |
+
if "`glvar'" != "" {
|
71 |
+
confirm new variable `glvar'
|
72 |
+
di as txt "new variable `glvar' created"
|
73 |
+
}
|
74 |
+
else tempvar glvar
|
75 |
+
}
|
76 |
+
else qui {
|
77 |
+
if "`glvar'" == "" {
|
78 |
+
tab `by' `by' if `touse', matrow(`byname')
|
79 |
+
local nv = rowsof(`byname')
|
80 |
+
forval i = 1/`nv' {
|
81 |
+
tempvar newvar`i'
|
82 |
+
}
|
83 |
+
}
|
84 |
+
else {
|
85 |
+
tab `by' `by' if `touse', matrow(`byname')
|
86 |
+
local prefix "`glvar'"
|
87 |
+
local nv = rowsof(`byname')
|
88 |
+
forval i = 1/`nv' {
|
89 |
+
local suffix = `byname'[`i',1]
|
90 |
+
local newvar`i' "`prefix'_`suffix'"
|
91 |
+
confirm new variable `newvar`i''
|
92 |
+
noi di as txt "new variable `newvar`i'' created"
|
93 |
+
}
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
if "`pvar'" != "" {
|
98 |
+
confirm new variable `pvar'
|
99 |
+
di as txt "new variable `pvar' created"
|
100 |
+
}
|
101 |
+
else tempvar pvar
|
102 |
+
|
103 |
+
qui gen `inc' = `varlist' if `touse'
|
104 |
+
|
105 |
+
qui if "`atip'" != "" {
|
106 |
+
if "`rtip'" != "" {
|
107 |
+
di as err "cannot use options atip() and rtip() together"
|
108 |
+
exit 198
|
109 |
+
}
|
110 |
+
if "`lorenz'" != ""{
|
111 |
+
di as err "cannot use option atip() with lorenz"
|
112 |
+
exit 198
|
113 |
+
}
|
114 |
+
replace `inc' = max(0,`atip' - `varlist') if `touse'
|
115 |
+
/* if "`sortvar'" == "" local sortvar "`varlist'" : incorrect if obs.-specific atip */
|
116 |
+
tempvar incratio
|
117 |
+
gen double `incratio' = (`varlist'/`atip')
|
118 |
+
if "`sortvar'" == "" local sortvar "`incratio'"
|
119 |
+
}
|
120 |
+
|
121 |
+
qui if "`rtip'" != "" {
|
122 |
+
if "`lorenz'" != ""{
|
123 |
+
di as err "cannot use option rtip() with lorenz"
|
124 |
+
exit 198
|
125 |
+
}
|
126 |
+
replace `inc' = max(0,(`rtip' - `varlist')/`rtip') if `touse'
|
127 |
+
/* if "`sortvar'" == "" local sortvar "`varlist'" : incorrect if obs.-specific rtip */
|
128 |
+
tempvar incratio
|
129 |
+
gen double `incratio' = (`varlist'/`rtip')
|
130 |
+
if "`sortvar'" == "" local sortvar "`incratio'"
|
131 |
+
}
|
132 |
+
|
133 |
+
quietly {
|
134 |
+
count if `inc' < 0 & `touse'
|
135 |
+
if r(N) > 0 {
|
136 |
+
noi di as txt _n "warning: `inc' has `r(N)' values < 0;" ///
|
137 |
+
"used in calculations"
|
138 |
+
}
|
139 |
+
|
140 |
+
if "`by'" == "" {
|
141 |
+
tempvar placebo
|
142 |
+
gen byte `placebo' = 1
|
143 |
+
local by "`placebo'"
|
144 |
+
}
|
145 |
+
|
146 |
+
if "`sortvar'" == "" local sortvar `inc'
|
147 |
+
sort `by' `sortvar' `inc' , stable /* `inc' included in v3.2.0 to stabilize concentration curves */
|
148 |
+
by `by' : gen double `cumwy' = sum(`wi' * `inc') if `touse'
|
149 |
+
by `by' : gen double `cumw' = sum(`wi') if `touse'
|
150 |
+
* by `by': gen double `cumw' = sum(`wi') if `touse'
|
151 |
+
egen `maxw' = max(`cumw'), by(`by')
|
152 |
+
gen double `pvar' = `cumw'/`maxw' if `touse'
|
153 |
+
label variable `pvar' "Cumulative population proportion"
|
154 |
+
|
155 |
+
/* get the appropriate curve label */
|
156 |
+
if "`lorenz'" != "" loc curvelabel "Lorenz"
|
157 |
+
else if "`atip'" != "" loc curvelabel "Absolute TIP"
|
158 |
+
else if "`rtip'" != "" loc curvelabel "Relative TIP"
|
159 |
+
else loc curvelabel "Gen. Lorenz"
|
160 |
+
|
161 |
+
if "`split'" == "" {
|
162 |
+
gen `glvar' = `cumwy'/`maxw' if `touse'
|
163 |
+
label var `glvar' "`curvelabel' (`varlist')"
|
164 |
+
if "`lorenz'" != ""{
|
165 |
+
su `inc' [`weight' `exp'] if `touse', meanonly
|
166 |
+
replace `glvar' = `glvar' / r(mean)
|
167 |
+
}
|
168 |
+
if "`graph'" != "" {
|
169 |
+
twoway scatter `glvar' `pvar' if `touse', ///
|
170 |
+
ms(i i) c(l l) `options' || `plot'
|
171 |
+
}
|
172 |
+
}
|
173 |
+
else {
|
174 |
+
local lname : value label `by'
|
175 |
+
forval i = 1/`nv' {
|
176 |
+
local bylevel = `byname'[`i',1]
|
177 |
+
bysort `by' (`sortvar'): ge `newvar`i'' = `cumwy'/`maxw' ///
|
178 |
+
if `touse' & `by' == `byname'[`i',1]
|
179 |
+
if ("`lname'" != "") {
|
180 |
+
label var `newvar`i'' "`curvelabel' (`varlist') [`by'==`: label `lname' `= `byname'[`i',1]'']"
|
181 |
+
}
|
182 |
+
else label var `newvar`i'' "`curvelabel' (`varlist') [`by'==`= `byname'[`i',1]']"
|
183 |
+
if "`lorenz'" != "" {
|
184 |
+
su `inc' [`weight' `exp'] if `touse' & `by' == `byname'[`i',1], meanonly
|
185 |
+
replace `newvar`i'' = `newvar`i'' / r(mean)
|
186 |
+
}
|
187 |
+
local listvar "`listvar' `newvar`i''"
|
188 |
+
/*local legtext `"`legtext' `i' "`varlist'[`= `byname'[`i',1]']" "' */
|
189 |
+
if ("`lname'" != "") {
|
190 |
+
local legtext `"`legtext' `i' "`: label `lname' `= `byname'[`i',1]''" "'
|
191 |
+
}
|
192 |
+
else local legtext `"`legtext' `i' "`by'==`= `byname'[`i',1]'" "'
|
193 |
+
}
|
194 |
+
if "`graph'" != "" {
|
195 |
+
if `nv' > 1 {
|
196 |
+
local yti `"yti("`curvelabel' `varlist' (by `by')")"'
|
197 |
+
}
|
198 |
+
twoway scatter `listvar' `pvar' if `touse', ///
|
199 |
+
ms(i ..) c(l ..) `yti' legend(order(`legtext')) `options' || `plot'
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
end
|
40/replication_package/EmpiricalAnalysis/library/stata/ado_ext/plus/g/glcurve.hlp
ADDED
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{smcl}
|
2 |
+
{* *! 3.2.0 07feb2007}{...}
|
3 |
+
{hline}
|
4 |
+
help for {hi:glcurve}{right:(SJ7-2: gr0001_3; SJ6-4: gr0001_2; SJ4-4: gr0001_1;}
|
5 |
+
{right:SJ1-1: gr0001; STB-49: sg107_1; STB-48: sg107)}
|
6 |
+
{hline}
|
7 |
+
|
8 |
+
{title:Deriving generalized Lorenz curve ordinates with unit record data}
|
9 |
+
|
10 |
+
{p 8 17 2}{cmd:glcurve}
|
11 |
+
{it:varname}
|
12 |
+
{weight}
|
13 |
+
{ifin}
|
14 |
+
[{cmd:,}
|
15 |
+
{cmdab:p:var}{cmd:(}{it:newvarname}{cmd:)}
|
16 |
+
{cmdab:gl:var}{cmd:(}{it:newvarname}{cmd:)}
|
17 |
+
{cmdab:so:rtvar}{cmd:(}{it:varname}{cmd:)}
|
18 |
+
{cmd:by}{cmd:(}{it:varname}{cmd:)}
|
19 |
+
{cmdab:sp:lit}
|
20 |
+
{cmdab:nogr:aph}
|
21 |
+
{cmd:replace}
|
22 |
+
{cmdab:l:orenz}
|
23 |
+
{cmd:atip}{cmd:(}{it:string}{cmd:)}
|
24 |
+
{cmd:rtip}{cmd:(}{it:string}{cmd:)}
|
25 |
+
{cmd:plot}{cmd:(}{it:plot}{cmd:)}
|
26 |
+
{it:graph_options}]
|
27 |
+
|
28 |
+
{p 4 4 2}{cmd:aweight}s and {cmd:fweight}s are allowed; see {help weight}.
|
29 |
+
|
30 |
+
|
31 |
+
{title:Description}
|
32 |
+
|
33 |
+
{p 4 4 2}Given a variable {it:varname}, call it x with c.d.f. F(x),
|
34 |
+
{cmd:glcurve} draws its generalized Lorenz curve and/or generates two new
|
35 |
+
variables containing the generalized Lorenz ordinates for x; i.e., GL(p) at
|
36 |
+
each p = F(x). For a population ordered in ascending order of x, a graph of
|
37 |
+
GL(p) against p plots the cumulative total of x divided by population size
|
38 |
+
against cumulative population share GL(1) = mean(x). {cmd:glcurve} can also be
|
39 |
+
used to derive many other related concepts such as Lorenz curves, concentration
|
40 |
+
curves, and "three is of poverty" (TIP) curves, with appropriate definition of
|
41 |
+
{it:varname}, order of cumulation (set with the {cmd:sortvar} option), and
|
42 |
+
normalization (e.g., by means of {it:varname}). {cmd:glcurve}
|
43 |
+
with the {cmd:lorenz}, {cmd:atip}, or {cmd:rtip} option can also be used
|
44 |
+
directly to draw the related Lorenz, concentration, and TIP curves.
|
45 |
+
|
46 |
+
{p 4 4 2}Comparisons of pairs of distributions (and dominance checks) can be
|
47 |
+
undertaken by using the {cmd:by()} (with or without the {cmd:split}) option.
|
48 |
+
It can also be made manually by "stacking" the data (see {helpb stack}).
|
49 |
+
|
50 |
+
{p 4 4 2}The graphs drawn by {cmd:glcurve} are relatively basic. For graphs
|
51 |
+
with full user control over formatting and labeling, users should
|
52 |
+
use {cmd:glcurve} to generate the ordinates of the graph required using the
|
53 |
+
{cmd:pvar(}{it:newvarname}{cmd:)} and {cmd:glvar(}{it:newvarname}{cmd:)}
|
54 |
+
options and then should draw the graph by using {helpb graph twoway}.
|
55 |
+
|
56 |
+
|
57 |
+
{title:Options}
|
58 |
+
|
59 |
+
{p 4 8 2}{cmd:pvar(}{it:pvarname}{cmd:)} generates the variable {it:pvarname}
|
60 |
+
containing the x coordinates of the created curve.
|
61 |
+
|
62 |
+
{p 4 8 2}{cmd:glvar(}{it:glvarname}{cmd:)} generates the variable
|
63 |
+
{it:glvarname} containing the y coordinates of the created curve.
|
64 |
+
|
65 |
+
{p 4 8 2}{cmd:sortvar(}{it:sname}{cmd:)} specifies the sort variable. By
|
66 |
+
default, the data are sorted (and cumulated) in ascending order of
|
67 |
+
{it:varname}. If the {cmd:sortvar} option is specified, sorting and cumulation
|
68 |
+
is in ascending order of variable {it:sname}. Within tied values of {it:sname},
|
69 |
+
data are sorted in ascending order of {it:varname}.
|
70 |
+
|
71 |
+
{p 4 8 2}{cmd:by(}{it:groupvar}{cmd:)} specifies that the coordinates are to be
|
72 |
+
computed separately for each subgroup defined by {it:groupvar}. {it:groupvar}
|
73 |
+
must be an integer variable.
|
74 |
+
|
75 |
+
{p 4 8 2}{cmd:split} specifies that a series of new variables be created,
|
76 |
+
containing the coordinates for each subgroup specified by
|
77 |
+
{cmd:by(}{it:groupvar}{cmd:)}. {cmd:split} cannot be used without {cmd:by()}.
|
78 |
+
If {cmd:split} is specified, then the string {it:glname} in
|
79 |
+
{cmd:glvar(}{it:glname}{cmd:)} is used as a prefix to create new variables
|
80 |
+
{it:glname_X1}, {it:glname_X2}, ... (where X1, X2, ... are the values taken by
|
81 |
+
{it:groupvar}).
|
82 |
+
|
83 |
+
{p 4 8 2}{cmd:nograph} avoids the automatic display of a crude graph made from
|
84 |
+
the created variables. {cmd:nograph} is assumed if {cmd:by()} is specified
|
85 |
+
without {cmd:split}.
|
86 |
+
|
87 |
+
{p 4 8 2}{cmd:replace} allows the variables specified in
|
88 |
+
{cmd:glvar(}{it:glvarname}{cmd:)} and {cmd:pvar(}{it:pvarname}{cmd:)} to be
|
89 |
+
overwritten if they already exist. Otherwise {it:glvarname} and
|
90 |
+
{it:pvarname} must be new variable names.
|
91 |
+
|
92 |
+
{p 4 8 2}{cmd:lorenz} requires that the ordinates of the Lorenz curve be
|
93 |
+
computed instead of generalized Lorenz ordinates. The Lorenz ordinates of
|
94 |
+
variable x, L(p), are GL(p)/mean(x).
|
95 |
+
|
96 |
+
{p 4 8 2}{cmd:rtip(}{it:povline}{cmd:)} and {cmd:atip(}{it:povline}{cmd:)}
|
97 |
+
require that the ordinates of TIP curves be computed instead of generalized
|
98 |
+
Lorenz ordinates. {it:povline} specifies the value of the poverty line: it can
|
99 |
+
be either a numeric value taken as the poverty line for all observations or a
|
100 |
+
variable name containing the value of the poverty line for each observation.
|
101 |
+
{cmd:atip()} draws absolute TIP curves (by cumulating max(z-x,0)) and
|
102 |
+
{cmd:rtip()} draws relative TIP curves (by cumulating max(1-(x/z),0)).
|
103 |
+
|
104 |
+
{p 4 8 2}{cmd:plot(}{it:plot}{cmd:)} provides a way to add other plots to the
|
105 |
+
generated graph; see {it:{help addplot_option}}.
|
106 |
+
|
107 |
+
{p 4 8 2}{it:graph_options} are standard {helpb twoway scatter} options.
|
108 |
+
Modifications to the legend labels should be made with the
|
109 |
+
{cmd:legend(order(}...{cmd:)} options instead of
|
110 |
+
{cmd:legend(label(}...{cmd:)} (see {it:{help legend_option}}).
|
111 |
+
|
112 |
+
|
113 |
+
{title:Examples}
|
114 |
+
|
115 |
+
{p 4 4 2}Many {cmd:glcurve} examples are provided in the downloadable
|
116 |
+
materials provided by
|
117 |
+
{browse "http://econpapers.repec.org/paper/bocasug06/16.htm":Jenkins (2006)}.
|
118 |
+
|
119 |
+
{p 4 8 2}{cmd:. * Generalized Lorenz curve ordinates; plot using -graph twoway- }
|
120 |
+
|
121 |
+
{p 4 8 2}{cmd:. glcurve x, gl(gl1) p(p1) nograph}{p_end}
|
122 |
+
|
123 |
+
{p 4 8 2}{cmd:. twoway line gl1 p1}
|
124 |
+
|
125 |
+
{p 4 8 2}{cmd:. * Lorenz curve ordinates; plot using -glcurve- }
|
126 |
+
|
127 |
+
{p 4 8 2}{cmd:. glcurve x, lorenz plot(function equality = x)}
|
128 |
+
|
129 |
+
{p 4 8 2}{cmd:. * Lorenz curve ordinates; plot using -glcurve-; options }
|
130 |
+
|
131 |
+
{p 4 8 2}{cmd:. glcurve x [fw=wgt] if x > 0, gl(gl2) p(p2) lorenz}
|
132 |
+
|
133 |
+
{p 4 8 2}{cmd:. * Generalized Lorenz curve ordinates and graphs, by state }
|
134 |
+
|
135 |
+
{p 4 8 2}{cmd:. glcurve x, gl(gl2) p(p2) replace sort(y) by(state) split}
|
136 |
+
|
137 |
+
{p 4 8 2}{cmd:. * TIP curve ordinates with graph }
|
138 |
+
|
139 |
+
{p 4 8 2}{cmd:. glcurve x, gl(gl3) p(p3) atip(10000)}
|
140 |
+
|
141 |
+
{p 4 8 2}{cmd:. glcurve x, gl(gl3) p(p3) atip(plinevar)}
|
142 |
+
|
143 |
+
{p 4 8 2}{cmd:. * Lorenz curve ordinates; plot using -graph twoway- }
|
144 |
+
|
145 |
+
{p 4 8 2}{cmd:. glcurve x, gl(gl) p(p) lorenz nograph}{p_end}
|
146 |
+
|
147 |
+
{p 4 8 2}{cmd:. twoway line gl p , sort || line p p ,{space 1}/// }{p_end}
|
148 |
+
{p}{space 8}{cmd:xlabel(0(.1)1) ylabel(0(.1)1){space 6}///}{p_end}
|
149 |
+
{p}{space 8}{cmd:xline(0(.2)1) yline(0(.2)1){space 8}/// }{p_end}
|
150 |
+
{p}{space 8}{cmd:title("Lorenz curve") subtitle("Example with custom formatting"){space 4}/// }{p_end}
|
151 |
+
{p}{space 8}{cmd:legend(label(1 "Lorenz curve") label(2 "Line of perfect equality")) /// }{p_end}
|
152 |
+
{p}{space 8}{cmd:plotregion(margin(zero)) aspectratio(1) scheme(economist)}{p_end}
|
153 |
+
|
154 |
+
|
155 |
+
{title:Notes}
|
156 |
+
|
157 |
+
{p 4 4 2}{cmd:glcurve} is designed to be used with individual-level,
|
158 |
+
unit-record data. Although {cmd:glcurve} can also be applied mechanically to
|
159 |
+
grouped (banded) income data by using {cmd:fweight}s, the
|
160 |
+
resulting curve is a potentially poor estimate, because within-income-band
|
161 |
+
inequality is not taken into account. On the estimation of Lorenz curves and
|
162 |
+
inequality indices with grouped data, see, e.g., Gastwirth and Glaubermann
|
163 |
+
(1976) or Cowell and Mehta (1982).
|
164 |
+
|
165 |
+
{p 4 4 2}One must also be careful in using the ordinates returned from the
|
166 |
+
option {it:pvar} for subsequent computation of the Gini or concentration
|
167 |
+
coefficient by using the "convenient covariance" formulas described by, e.g.,
|
168 |
+
Lerman and Yitzhaki (1984, 1989) or Jenkins (1988). The ordinates returned in
|
169 |
+
{it:pvar} are the curve ordinates (and are equal to estimates obtained from
|
170 |
+
{cmd:cumul}), and these are not necessarily the fractional ranks required in
|
171 |
+
the covariance formula. The difference is generally negligible with continuous
|
172 |
+
unit-record data but is larger if there are many ties in the ranking variable
|
173 |
+
(as for the concentration coefficient based on an ordinal
|
174 |
+
categorical variable or when dealing with grouped data).
|
175 |
+
|
176 |
+
|
177 |
+
{title:Acknowledgments}
|
178 |
+
|
179 |
+
{p 4 4 2}Nicholas J. Cox helped with updating the code for our program from
|
180 |
+
Stata 7 ({helpb glcurve7}) to Stata 8. David Demery and Owen O'Donnell made
|
181 |
+
useful bug reports. Comments by Zhuo (Adam) Chen led to introduction of
|
182 |
+
"sort stable" estimation for concentration curves.
|
183 |
+
|
184 |
+
|
185 |
+
{title:Authors}
|
186 |
+
|
187 |
+
{p 4 4 2}Philippe Van Kerm, CEPS/INSTEAD, Differdange, G.-D. Luxembourg{break}
|
188 | |
189 |
+
|
190 |
+
{p 4 4 2}Stephen P. Jenkins, ISER, University of Essex{break}
|
191 | |
192 |
+
|
193 |
+
|
194 |
+
{title:References}
|
195 |
+
|
196 |
+
{p 4 8 2}Cowell, F. A. 1995. {it:Measuring Inequality}. 2nd ed.
|
197 |
+
Hemel Hempstead: Prentice-Hall/Harvester-Wheatsheaf.
|
198 |
+
|
199 |
+
{p 4 8 2}Cowell, F. A., and F. Mehta. 1982.
|
200 |
+
The estimation and interpolation of inequality measures.
|
201 |
+
{it:Review of Economic Studies} 49(2): 273-290.
|
202 |
+
|
203 |
+
{p 4 8 2}Gastwirth, J. L., and M. Glauberman. 1976.
|
204 |
+
The interpolation of the Lorenz curve and Gini index from grouped data.
|
205 |
+
{it:Econometrica} 44(3): 479-483.
|
206 |
+
|
207 |
+
{p 4 8 2}Jenkins, S. P. 1988.
|
208 |
+
Calculating income distribution indices from microdata.
|
209 |
+
{it:National Tax Journal} 61: 139-142.
|
210 |
+
|
211 |
+
{p 4 8 2}Jenkins, S. P. 2006.
|
212 |
+
Estimation and interpretation of measures of inequality,
|
213 |
+
poverty, and social welfare using Stata. Presentation at North American
|
214 |
+
Stata Users Group meeting 2006, Boston.
|
215 |
+
{browse "http://econpapers.repec.org/paper/bocasug06/16.htm"}.
|
216 |
+
|
217 |
+
{p 4 8 2}Jenkins, S. P., and P. J. Lambert. 1997.
|
218 |
+
Three 'I's of poverty curves, with an analysis of UK poverty trends.
|
219 |
+
{it:Oxford Economic Papers} 49: 317-327.
|
220 |
+
|
221 |
+
{p 4 8 2}Lambert, P. J. 2001.
|
222 |
+
{it:The Distribution and Redistribution of Income}. 3rd ed.
|
223 |
+
Manchester: Manchester University Press.
|
224 |
+
|
225 |
+
{p 4 8 2}Lerman, R. I., and S. Yitzhaki. 1984.
|
226 |
+
A note on the calculation and interpretation of the Gini index.
|
227 |
+
{it:Economics Letters} 15: 363-368.
|
228 |
+
|
229 |
+
{p 4 8 2}------. 1989.
|
230 |
+
Improving the accuracy of estimates of Gini coefficients.
|
231 |
+
{it:Journal of Econometrics} 42: 43-47.
|
232 |
+
|
233 |
+
{p 4 8 2}Shorrocks, A. F. 1983. Ranking income distributions.
|
234 |
+
{it:Economica} 197: 3-17.
|
235 |
+
|
236 |
+
|
237 |
+
{title:Also see}
|
238 |
+
|
239 |
+
{psee} Manual: {hi:[R] lorenz}{p_end}
|
240 |
+
|
241 |
+
{psee}Online: {helpb sumdist}, {helpb svylorenz} (if installed)
|
242 |
+
{p_end}
|