-
Notifications
You must be signed in to change notification settings - Fork 2
/
ivlasso_p.ado
70 lines (60 loc) · 1.53 KB
/
ivlasso_p.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
*! ivlasso_p 1.0.00 26/09/2017
*! pdslasso package 1.3
*! authors aa/cbh/ms
* postestimation predict for ivlasso and pdslasso
program define ivlasso_p, rclass
version 12.1
syntax namelist(min=1 max=2) [if] [in], ///
///
[XB /// [default]
Residuals ///
///
]
* create variable here
tokenize `namelist'
if "`2'"=="" { // only new varname provided
local varlist `1'
qui gen `1' = .
}
else { // datatype also provided
local vtype `1'
local varlist `2'
qui gen `1' `2' = .
}
*
if ("`e(cmd)'"~="ivlasso") & ("`e(cmd)'"~="pdslasso") {
di as err "error: ivlasso_p supports only ivlasso and pdslasso commands"
exit 198
}
*
if "`e(post)'" ~= "pds" {
di as err "error: predict currently supported only for default post(pds) option"
exit 198
}
marksample touse, novarlist
*** warning messages
if ("`xb'`residuals'"=="") {
di as text "No xb or residuals options specified. Assume xb (fitted values)."
local xb xb
}
*** fe currently not supported.
if `e(fe)' {
di as err "predict not currently supported after FE estimation"
exit 198
}
*
*** obtain prediction/residuals
tempname b
tempvar xbvar
mat `b'=e(b)
qui matrix score `typlist' `xbvar'= `b' `if'
if ("`xb'"!="") {
qui replace `varlist' = `xbvar' `if'
label var `varlist' "Predicted values"
}
else if ("`residuals'"!="") {
qui replace `varlist' = `e(depvar)' - `xbvar' `if'
label var `varlist' "Residuals"
}
*
end