-
Notifications
You must be signed in to change notification settings - Fork 2
/
mixdom.ado
112 lines (67 loc) · 2.56 KB
/
mixdom.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
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
*! mixdom version 2.1.1 12/20/2024 Joseph N. Luchman
version 16
program define mixdom, eclass
syntax varlist(min = 2 fv ts) [pw fw] [if], id(varlist max = 1 min = 1) [REopt(string) XTMopt(string) ///
Mopt(string)]
if strlen("`xtmopt'") {
display as err "{cmd:xtmopt()} is defunct. Use {cmd:mopt()}."
exit 198
}
tempname estmat r2w r2b base_e base_u mean_h
tempvar touse
gettoken dv ivs: varlist
foreach temp in base_e base_u mean_h {
capture assert e(`temp')
if !_rc scalar ``temp'' = e(`temp')
}
mixed `dv' `ivs' [`weight'`exp'] `if' , `constant' || `id':, `reopt' `mopt' nostderr
matrix `estmat' = e(b)
scalar `r2w' = (exp(`estmat'[1, `=colsof(`estmat') - 1']))^2 + (exp(`estmat'[1, `=colsof(`estmat')']))^2
if missing(`mean_h') {
preserve
quietly collapse (count) `dv' `if', by(`id') fast
quietly ameans `dv'
scalar `mean_h' = r(mean_h)
di `mean_h'
restore
}
scalar `r2b' = (exp(`estmat'[1, `=colsof(`estmat') - 1']))^2 + ((exp(`estmat'[1, `=colsof(`estmat')']))^2)/`mean_h'
if missing(`base_e') | missing(`base_u') {
mixed `dv' [`weight'`exp'] `if' , `constant' || `id':, `reopt' `mopt' nostderr
matrix `estmat' = e(b)
scalar `base_e' = `estmat'[1, `=colsof(`estmat')']
scalar `base_u' = `estmat'[1, `=colsof(`estmat') - 1']
}
scalar `r2w' = 1 - ((exp(`base_u'))^2 + (exp(`base_e'))^2)^-1*`r2w'
scalar `r2b' = 1 - ((exp(`base_u'))^2 + ((exp(`base_e'))^2)/`mean_h')^-1*`r2b'
generate `touse' = e(sample)
ereturn clear
ereturn post, esample(`touse')
ereturn scalar r2_w = `r2w'
ereturn scalar r2_b = `r2b'
ereturn local title = "Mixed-effects ML regression"
ereturn hidden scalar base_e = `base_e' // note to self - make these hidden not official returned values
ereturn hidden scalar base_u = `base_u'
ereturn hidden scalar mean_h = `mean_h'
// note to self - return esample and title
end
/* programming notes and history
- mixdom version 1.0 - date - Jan 15, 2014
Basic version
-----
- mixdom version 1.1 - date - Mar 11, 2015
- added version statement (12.1)
- time series operators allowed
- removed scalars persisting after estimation
-----
- mixdom version 2.0 - date - Feb 15, 2021
- -xtmopt()- depreciated in favor of -mopt()-
---
mixdom version 2.1.0 - mth day, year
- minimum version 15 consistent with base -domin-
- xtmopt defunct - gives warning
- noconstant option removed
- returns e(smaple) to satisfy -domin- 3.5 requirements
// 2.1.1 - December 20, 2024
- version to 16 consistent with base -domin-
** mi-able?