-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit tests.do
226 lines (158 loc) · 7.7 KB
/
unit tests.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
cap cd "D:\OneDrive\Documents\Macros"
cap cd "/mnt/d/OneDrive/Documents/Macros"
set more off
set rmsg off
set trace off
set linesize 200
cap set processors 6
timer clear
timer on 1
cap log close
qui log using "cmp\unit tests.log", replace
version 13
set seed 0193284710
cmp setup
use laborsup, clear
cmp (kids = fem_inc male_educ), ind($cmp_cont) quietly
cmp (kids = fem_inc male_educ) (fem_work = male_educ), ind($cmp_cont $cmp_cont) quietly
cmp (fem_educ = kids other_inc fem_inc) (male_educ = kids other_inc fem_inc), ind(1 1) qui
cmp (kids = fem_inc male_educ) (fem_work = kids fem_inc), ind($cmp_cont $cmp_cont) qui
cmp (kids = fem_inc male_educ other_inc) (fem_work = kids), ind($cmp_cont $cmp_cont) qui
cmp (kids = fem_inc male_educ), ind($cmp_probit) qui
predict p2, pr
margins, dydx(*) predict(pr)
cmp (kids = fem_inc male_educ), ind($cmp_oprobit) qui
margins, dydx(*) predict(eq(#1) outcome(#2) pr)
gen byte anykids = kids > 0
cmp (anykids = fem_inc male_educ) (fem_work = male_educ), ind($cmp_probit $cmp_probit)
preserve
replace anykids=1
replace fem_work=1
margins, dydx(fem_inc) expression(exp(predict(lnl))) force // marginal effect on probability of (1,1)
restore
cmp (anykids = ) (fem_work = ), ind($cmp_probit $cmp_probit) nolr qui
cmp (fem_work = other_inc fem_educ kids) (other_inc = fem_educ kids male_educ), ind($cmp_probit $cmp_cont)
margins, predict(pr) dydx(*) force
cmp (other_inc = fem_educ kids fem_work) (fem_work = male_educ), ind($cmp_cont $cmp_probit) qui
cmp (fem_inc = kids male_educ), ind("cond(fem_inc>10, $cmp_cont, $cmp_left)") qui
margins, dydx(*) predict(pr(17 .))
cmp (fem_inc=kids male_educ) (male_educ=kids other_inc fem_work), ind("cond(fem_inc>10,$cmp_cont,$cmp_left)" $cmp_cont)
use intregxmpl, clear
cmp (wage1 wage2 = age age2 nev_mar rural school tenure), ind($cmp_int) qui
use laborsub, clear
cmp (whrs = kl6 k618 wa we, trunc(0 .)), ind($cmp_cont) qui
use 401k, clear
cmp (prate = mrate ltotemp age i.sole), ind($cmp_frac) qui
margins, dydx(mrate) predict(pr)
use sysdsn3, clear
cmp (insure = age male nonwhite site2 site3, iia), nolr ind($cmp_mprobit) qui
margins, dydx(nonwhite) predict(eq(#2) pr)
use fitness, clear
gen byte hours_pos = hours > 0
cmp (hours = age i.smoke distance i.single, trunc(0 .)) (hours_pos = commute whours age), nolr ind("cond(hours_pos, $cmp_cont, $cmp_out)" $cmp_probit) covar(indep) qui
use travel, clear
drop invehiclecost traveltime partysize
reshape wide choice termtime travelcost, i(id) j(mode)
constraint 1 [air]termtime1 = [train]termtime2
constraint 2 [train]termtime2 = [bus]termtime3
constraint 3 [bus]termtime3 = [car]termtime4
constraint 4 [air]travelcost1 = [train]travelcost2
constraint 5 [train]travelcost2 = [bus]travelcost3
constraint 6 [bus]travelcost3 = [car]travelcost4
cmp (air:choice1=t*1) (train: choice2=income t*2) (bus: choice3=income t*3) (car: choice4=income t*4), ind((6 6 6 6)) constr(1/6) nodrop struct tech(dfp) ghkd(200)
predict cmppr1, eq(air) pr
predict cmppr2, eq(train) pr
predict cmppr3, eq(bus) pr
predict cmppr4, eq(car) pr
use wlsrank, clear
reshape wide rank high low, i(id) j(jobchar)
constraint 1 [esteem]high1=[variety]high2
constraint 2 [esteem]high1=[autonomy]high3
constraint 3 [esteem]high1=[security]high4
constraint 4 [esteem]low1=[variety]low2
constraint 5 [esteem]low1=[autonomy]low3
constraint 6 [esteem]low1=[security]low4
cmp (esteem:rank1=high1 low1)(variety:rank2=female score high2 low2)(autonomy:rank3=female score high3 low3)(security:rank4=female score high4 low4), ind((9 9 9 9)) tech(dfp) ghkd(47, type(hammersley) scramble) rev constr(1/6)
predict cmppr1, eq(esteem) pr
predict cmppr2, eq(variety) pr
predict cmppr3, eq(autonomy) pr
predict cmppr4, eq(security) pr
use class10, clear
cmp (graduate = program#(c.income roommate c.hsgpa) program income roommate hsgpa) (program = i.campus i.scholar income) (hsgpa = income i.hscomp), vce(robust) ind(4 4 1) qui nolr
use womenwk, clear
gen selectvar = wage<.
cmp (wage = education age) (selectvar = married children education age), ind(selectvar $cmp_probit) nolr qui
margins, dydx(*) predict(e eq(wage) condition(0 ., eq(selectvar)))
margins, dydx(*) expression(predict(e eq(wage) cond(0 ., eq(selectvar))) * predict(pr eq(selectvar)) )
predict xb, eq(selectvar) xb
predict e, eq(selectvar) e(0 .)
gen cmp_mills = e - xb
gen wage2 = wage > 20 if wage < .
cmp (wage2 = education age) (selectvar = married children education age), ind(selectvar*$cmp_probit $cmp_probit) qui
margins, dydx(*) predict(pr eq(wage2) condition(0 ., eq(selectvar)))
gen wage3 = (wage > 10)+(wage > 30) if wage < .
cmp (wage3 = education age) (selectvar = married children education age), ind(selectvar*$cmp_oprobit $cmp_probit) nolr qui
sysuse auto, clear
cmp (price = foreign#) (foreign = mpg), ind($cmp_cont $cmp_cont) nolr
predict pricehat1
predict pricehat2, reducedform
cmp (price = foreign#) (foreign = mpg), ind($cmp_cont $cmp_probit)
replace foreign = . in 1/20
cmp (price = foreign#) (foreign = mpg), ind($cmp_cont $cmp_probit) // sample does not shrink
use klein, clear
cmp (consump = wagepriv# wagegovt) (wagepriv = consump# govt capital1), ind($cmp_cont $cmp_cont) nolr tech(dfp) qui
use supDem, clear
cmp (price = quantity# pcompete income) (quantity = price# praw), ind($cmp_cont $cmp_cont) nolr tech(dfp) qui
cmp, resultsform(reduced)
margins, dydx(*) predict(eq(quantity))
egen priceO = cut(price), at(25 27 31 33 35 37 39) icodes
egen quantityO = cut(quantity), at(5 7 9 11 13 15 17 19 21) icodes
cmp (price: priceO = quantity# pcompete income) (quantity: quantityO = price# praw), ind($cmp_oprobit $cmp_oprobit) nolr qui tech(dfp)
cmp, resultsform(reduced)
margins, dydx(praw) predict(outcome(3) eq(quantity) pr)
use union, clear
cmp (union = age grade not_smsa south##c.year || idcode:), ind($cmp_probit) qui
use nlswork3, clear
replace ln_wage = 1.9 if ln_wage > 1.9
cmp (ln_wage = union age grade not_smsa south south#c.year || idcode:), ind("cond(ln_wage<1.899999, $cmp_cont, $cmp_right)") nolr qui
use nlswork5, clear
cmp (ln_wage1 ln_wage2 = union age grade south south#c.year occ_code || idcode:), ind($cmp_int) nolr qui
use tvsfpors, clear
cmp (thk = prethk cc#tv || school: || class:), ind($cmp_oprobit) intpoints(7 7) nolr qui
use productivity, clear
cmp (gsp = private emp hwy water other unemp || region: || state:), nolr ind($cmp_cont)
use womenhlthre, clear
gen byte goodhlth = health > 3
cmp (goodhlth = insured#c.(exercise grade) exercise grade insured || personid:) (insured = grade i.workschool || personid:), ind($cmp_probit $cmp_probit) intp(7) nolr
use wagework, clear
cmp (wage = age tenure || personid:) (working = age market || personid:), ind(working*$cmp_cont $cmp_probit) intp(7) nolr
use laborsup, clear
gen byte kids2 = kids + int(uniform()*3)
gen byte kids3 = kids + int(uniform()*3)
cmp (kids=fem_educ) (kids2=fem_educ) (kids3=fem_educ), ind($cmp_oprobit $cmp_oprobit $cmp_oprobit) nolr qui
cmp (other_inc = fem_work) (fem_work = kids), ind($cmp_cont $cmp_probit) qui robust
gen byte ind2 = cond(fem_work, cond(fem_inc, $cmp_cont, $cmp_left), $cmp_out)
cmp (other_inc=fem_inc kids) (fem_inc=fem_educ), ind($cmp_cont ind2)
use gcse, clear
cmp (gcse = lrt || school: lrt), ind($cmp_cont) nolr
use jspmix, clear
cmp (tby = sex, iia || scy3:), ind($cmp_mprobit) nolr
use union, clear
cmp (union = age not_smsa black# || idcode:) (black = south#c.year), ind($cmp_probit $cmp_probit) nolr
use laborsup, clear
gen byte kids2 = kids + int(uniform()*3)
cmp (kids=fem_educ) (kids2=fem_educ), ind($cmp_oprobit $cmp_oprobit) nolr tech(dfp) qui
predict xbA
predict xbB*
predict xbC xbD
predict sc*, score
predict lnl, lnl
predict prA, pr outcome(0)
predict prB, outcome(#1)
predict prC, outcome(4) eq(kids2)
predict prD*, pr
predict prE prF, pr
predict prG, eq(#2) pr
qui log close
timer off 1
timer list