-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathologit_yhat.ado
executable file
·82 lines (54 loc) · 1.83 KB
/
ologit_yhat.ado
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
/***
Title
======
__ologit_yhat__ -- Generate predictions and associated confidence intervals from an ordered logistic regression model.
Syntax
------
__ologit_yhat__ [, centiles(numlist) stub(str) drop]
- - -
Options:
> __centiles__ (_numlist_) : A number list between 0 - 100.
> __stub__ (_str_) : A string which will serve as a prefix for the generated variables.
> __drop__ : If specified, the command will write over existing variables.
- - -
Description
-----------
__ologit_yhat__ will generate predictions from an ordered logistic regression model. This command is built on top of the {help predict:{it:predict}} command.
***/
capture program drop ologit_yhat
program ologit_yhat
syntax [if] [in] [, centiles(numlist integer >0 <100) stub(str) drop ]
local cmd = e(cmd)
if "`cmd'" != "ologit" {
display "This function works for postestimation of ologit"
error 301
}
local dv = "`e(depvar)'"
if "`centiles'" == "" {
local centiles = 50
}
if "`drop'" == "drop" {
capture fussydrop `stub'`dv'_mean
foreach j in `centiles' {
capture fussydrop `stub'`dv'_q`j'
}
}
capture drop _tgsdrop_*
gen _tgsdrop_cump = 0
gen `stub'`dv'_mean = 0
mat kmat = e(cat)
predict _tgsdrop_p*, p
foreach j in `centiles' {
quietly gen `stub'`dv'_q`j' = .
quietly gen _tgsdrop_`stub'`dv'_q`j'_ind = 0
}
forvalues i = 1/`e(k_cat)' {
quietly replace _tgsdrop_cump = _tgsdrop_cump + _tgsdrop_p`i'
quietly replace `stub'`dv'_mean = kmat[1,`i']*_tgsdrop_p`i' + `stub'`dv'_mean
foreach j in `centiles' {
quietly replace `stub'`dv'_q`j' = kmat[1,`i'] if _tgsdrop_cump >= `j'/100 & _tgsdrop_`stub'`dv'_q`j'_ind == 0
quietly replace _tgsdrop_`stub'`dv'_q`j'_ind = `i' if _tgsdrop_cump >= `j'/100 & _tgsdrop_`stub'`dv'_q`j'_ind == 0
}
}
quietly drop _tgsdrop*
end