forked from huang100/EconMethod2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture4.do
More file actions
137 lines (108 loc) · 3.07 KB
/
lecture4.do
File metadata and controls
137 lines (108 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// 读入数据
use mus14data.dta, clear
// 生成新的变量
global xlist age hstatusg hhincome educyear married hisp
generate line = ln(hhinc)
global extralist line female white chronic adl sretire
// 描述统计
sum ins retire $xlist $extralist
hist hhincome
// 线性概率模型
reg ins retire $xlist, vce(robust)
// 样本内预测
predict pins
sum pins
/*
预测结果有什么问题?
*/
/*
Stata下我们可以选择的模型有
1. Probit regression
logit depvar [indepvars] [if] [m] [weight] [, options]
2. Logit (logistic) regression
probit depvar [indepvars] [if] [in] [weight] [, options]
3. LPM, linear probability model
reg depvar [indepvars] [if] [in] [weight] [, vce(robust) other options]
*/
// logit regression
logit ins retire $xlist
/*
系数大小有没有意义?
是否需要计算边际效果 marginal effect?
系数符号和边际效果符号是否一样?
*/
// probit regression
probit ins retire $xlist
// Estimation of several models
quietly logit ins retire $xlist
estimates store blogit
quietly probit ins retire $xlist
estimates store bprobit
quietly regress ins retire $xlist, vce(robust)
estimates store bols
* Table for comparing models
esttab blogit bprobit bols, se stats(N ll) star(* 0.1 ** 0.05 *** 0.01) mtitle("Logit" "Probit" "OLS") nonumber
// probit regression,odds ratio
logit ins retire $xlist, or
/*
如何解释OR值?
*/
/*
每个人的边际效应是不一样的,怎么解决?
1. Marginal effect at a representative value (MER)
2. Marginal effect at the mean (MEM)
3. Average marginal effect (AME)
*/
// 平均边际效应
// Average marginal effect (AME) after logit
quietly logit ins retire $xlist
*margins, dydx(retire)
margins, dydx(*)
// 对“代表人”取边际
// Marginal effects (MEM) after logit
quietly logit ins retire $xlist
*margins, dydx(retire) atmeans
margins, dydx(*) atmeans
* 注意stata输出信息
// 比较边际效应
quietly logit ins retire $xlist
margins, dydx(*) post
est store logit_AME
quietly logit ins retire $xlist
margins, dydx(*) atmeans post
est store logit_MEM
quietly probit ins retire $xlist
margins, dydx(*) post
est store probit_AME
quietly probit ins retire $xlist
margins, dydx(*) atmeans post
est store probit_MEM
quietly reg ins retire $xlist, vce(robust)
est store ols
esttab logit_AME logit_MEM probit_AME probit_MEM ols, ///
se star(* 0.1 ** 0.05 *** 0.01) ///
mtitle("Logit_AME" "Logit_MEM" "Probit_AME" "Probit_AME" "OLS") nonumber
// Wald test for zero interactions
cap drop age2 agefem agechr agewhi
generate age2 = age*age
generate agefem = age*female
generate agechr = age*chronic
generate agewhi = age*white
global intlist age2 agefem agechr agewhi
logit ins retire $xlist $intlist
test $intlist
// * Likelihood-ratio test
quietly logit ins retire $xlist $intlist
est store A
quietly logit ins retire $xlist
est store B
lrtest A B
/*
“承认”原假设:交叉项没有影响
*/
// 比较 Pseudo-R2 measure
logit ins retire $xlist
logit ins retire $xlist $extralist
// Comparing fitted probability and dichotomoiis outcome.
quietly logit ins retire $xlist
estat classification