|
1 | | -*! version 5.4 15DEC2017 DIME Analytics lcardosodeandrad@worldbank.org |
2 | | - |
3 | | - capture program drop ieboilsave |
| 1 | +*! version 5.5 26APR2018 DIME Analytics lcardosodeandrad@worldbank.org |
| 2 | + |
| 3 | + capture program drop ieboilsave |
4 | 4 | program ieboilsave , rclass |
5 | | - |
| 5 | + |
6 | 6 | syntax , IDVARname(varlist) [DIOUTput missingok tagnoname tagnohost] |
7 | | - |
| 7 | + |
8 | 8 | qui { |
9 | | - |
| 9 | + |
10 | 10 | preserve |
11 | | - |
| 11 | + |
12 | 12 | local origversion "`c(version)'" |
13 | | - |
| 13 | + |
14 | 14 | version 11.0 |
15 | | - |
| 15 | + |
16 | 16 | //Checking that only one id variable is listed |
17 | 17 | if `:list sizeof idvarname' > 1 { |
18 | | - |
| 18 | + |
19 | 19 | noi di as error "{phang}Multiple ID variables in idvarname(`idvarname') are not allowed. While it is not always incorrect, it is bad practice, see {help ieboilsave##IDnotes:Notes on ID variables} for more details.{p_end}" |
20 | 20 | noi di "" |
21 | 21 | error 103 |
22 | 22 | exit |
23 | 23 | } |
24 | | - |
25 | | - |
| 24 | + |
| 25 | + |
26 | 26 | /********************************* |
27 | | - |
| 27 | +
|
28 | 28 | ID variables |
29 | | - |
| 29 | +
|
30 | 30 | *********************************/ |
31 | | - |
| 31 | + |
32 | 32 | capture isid `idvarname' |
33 | | - |
| 33 | + |
34 | 34 | if _rc { |
35 | | - |
36 | | - |
| 35 | + |
| 36 | + |
37 | 37 | //Test missing |
38 | 38 | capture assert !missing(`idvarname') |
39 | 39 | if _rc { |
40 | | - |
| 40 | + |
41 | 41 | count if missing(`idvarname') |
42 | | - |
| 42 | + |
43 | 43 | noi di as error "{phang}The ID variable `idvarname' is missing in `r(N)' observation(s). The ID variable needs to be fully identifying, meaning that no values can be a missing values (., .a, .b ... .z) or the empty string{p_end}" |
44 | 44 | noi di "" |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | //Test duplicates |
48 | 48 | tempvar iedup |
49 | | - |
| 49 | + |
50 | 50 | duplicates tag `idvarname', gen(`iedup') |
51 | | - |
| 51 | + |
52 | 52 | count if `iedup' != 0 |
53 | | - |
| 53 | + |
54 | 54 | if r(N) > 0 { |
55 | | - |
| 55 | + |
56 | 56 | sort `idvarname' |
57 | | - |
| 57 | + |
58 | 58 | noi di as error "{phang}To be uniquely identifying the ID variable should not have any duplicates. The ID variable `idvarname' has duplicate observations in the following values:{p_end}" |
59 | 59 | noi list `idvarname' if `iedup' != 0 |
60 | 60 | } |
61 | 61 | noi di "" |
62 | 62 | error 148 |
63 | 63 | exit |
64 | | - } |
65 | | - |
66 | | - |
67 | | - |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + |
68 | 68 | /********************************* |
69 | | - |
| 69 | +
|
70 | 70 | Missing values |
71 | | - |
| 71 | +
|
72 | 72 | *********************************/ |
73 | | - |
| 73 | + |
74 | 74 | if "`missingok'" == "" { |
75 | | - |
76 | | - local varsStandMiss |
77 | | - |
| 75 | + |
| 76 | + local varsStandMiss |
| 77 | + |
78 | 78 | ds, has(type numeric) |
79 | | - |
| 79 | + |
80 | 80 | foreach variable in `r(varlist)' { |
81 | | - |
| 81 | + |
82 | 82 | cap assert `variable' != . |
83 | | - |
| 83 | + |
84 | 84 | if _rc { |
85 | | - |
| 85 | + |
86 | 86 | local varsStandMiss `varsStandMiss' `variable' |
87 | 87 | } |
88 | 88 | } |
89 | | - |
| 89 | + |
90 | 90 | if `:list sizeof varsStandMiss' > 0 { |
91 | | - |
| 91 | + |
92 | 92 | noi di as error "{phang}There are `:list sizeof varsStandMiss' numeric variable(s) that contains the standard missing value (.) which is bad practice. A list of the variable(s) are stored in the local {cmd:r(standmissvars)}. Extended missing variables should be used. See {help ieboilsave} for more details.{p_end}" |
93 | | - |
| 93 | + |
94 | 94 | return local standmissvars "`varsStandMiss'" |
95 | | - |
| 95 | + |
96 | 96 | error 416 |
97 | 97 | exit |
98 | 98 | } |
99 | 99 | } |
100 | | - |
101 | | - restore |
102 | | - |
| 100 | + |
| 101 | + restore |
| 102 | + |
103 | 103 | /********************************* |
104 | | - |
| 104 | +
|
105 | 105 | Output success messages |
106 | | - |
107 | | - *********************************/ |
108 | | - |
| 106 | +
|
| 107 | + *********************************/ |
| 108 | + |
109 | 109 | // ID |
110 | | - |
| 110 | + |
111 | 111 | //Store the name of idvar in data set char and in notes |
112 | 112 | char _dta[ie_idvar] "`idvarname'" |
113 | | - |
| 113 | + |
114 | 114 | local idOut "The uniquely and fully identifying ID variable is `idvarname'. " |
115 | | - |
116 | | - |
117 | | - // Version |
| 115 | + |
| 116 | + |
| 117 | + // Version |
118 | 118 | char _dta[ie_version] "`origversion'" |
119 | | - |
| 119 | + |
120 | 120 | local versOut "This data set was created in Stata version `origversion'" |
121 | | - |
| 121 | + |
122 | 122 | // Date |
123 | 123 | char _dta[ie_date] "`c(current_date)'" |
124 | | - |
| 124 | + |
125 | 125 | local dateOut " on `c(current_date)'." |
126 | | - |
127 | | - // Name |
128 | | - |
| 126 | + |
| 127 | + // Name |
| 128 | + |
129 | 129 | local nameOut "" |
130 | 130 | local hostOut "" |
131 | | - |
| 131 | + |
132 | 132 | if "`tagnoname'" == "" { |
133 | | - |
| 133 | + |
134 | 134 | char _dta[ie_name] "`c(username)'" |
135 | | - |
| 135 | + |
136 | 136 | if "`tagnohost'" == "" { |
137 | | - |
| 137 | + |
138 | 138 | char _dta[ie_host] "`c(hostname)'" |
139 | 139 | local hostOut ", by user `c(username)' using computer `c(hostname)'," |
140 | 140 | } |
141 | 141 | else { |
142 | | - |
| 142 | + |
143 | 143 | local nameOut ", by user `c(username)'," |
144 | | - |
| 144 | + |
145 | 145 | } |
146 | 146 | } |
147 | 147 | // Missing vars |
148 | | - |
| 148 | + |
149 | 149 | if "`missingok'" == "" { |
150 | | - |
| 150 | + |
151 | 151 | local missOut "There are no regular missing values in this data set" |
152 | 152 | } |
153 | 153 | else { |
154 | | - |
| 154 | + |
155 | 155 | local missOut "This data set was not tested for missing values" |
156 | 156 | } |
157 | | - |
| 157 | + |
158 | 158 | char _dta[ie_boilsave] "ieboilsave ran successfully. `idOut'`versOut'`nameOut'`hostOut'`dateOut' `missOut'" |
159 | | - |
| 159 | + |
160 | 160 | if "`dioutput'" != "" { |
161 | | - |
| 161 | + |
162 | 162 | local outputSum : char _dta[ie_boilsave] |
163 | 163 | noi di "" |
164 | 164 | noi di "{phang}`outputSum'{p_end}" |
165 | | - |
| 165 | + |
166 | 166 | } |
167 | | - |
| 167 | + |
168 | 168 | } |
169 | | - end |
| 169 | + end |
0 commit comments